PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/emailer/auth/models2.py

https://gitlab.com/qb1t/mitro
Python | 48 lines | 23 code | 11 blank | 14 comment | 0 complexity | 6bd376dfcb47d56de5ec9c858b974b3c MD5 | raw file
  1. #!/usr/bin/env python
  2. # import datetime
  3. import json
  4. # import logging
  5. # import sqlalchemy
  6. # import sqlalchemy.exc
  7. import sqlalchemy.ext.declarative
  8. # import sqlalchemy.orm
  9. # from sqlalchemy.pool import StaticPool
  10. # from sqlalchemy.pool import NullPool
  11. # import tornado.options
  12. # from auth import email_queue
  13. # from auth import statsd
  14. Base = sqlalchemy.ext.declarative.declarative_base()
  15. class EmailQueue(Base):
  16. '''Queues emails to be sent by another process.'''
  17. # TODO: Use Kombu queuing?
  18. __tablename__ = 'email_queue'
  19. id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True, nullable=False)
  20. type_string = sqlalchemy.Column(sqlalchemy.Text, nullable=False)
  21. arg_string = sqlalchemy.Column(sqlalchemy.Text, nullable=False)
  22. attempted_time = sqlalchemy.Column(sqlalchemy.DateTime)
  23. template_name = sqlalchemy.Column('mandrill_template_name', sqlalchemy.Text, nullable=True)
  24. template_params_string = sqlalchemy.Column(
  25. 'mandrill_template_param_map_json',sqlalchemy.Text, nullable=True)
  26. def __init__(self, type_string, arg_string, template_name,
  27. template_params_string):
  28. self.type_string = type_string
  29. # arg_string must be valid json
  30. self.arg_string = arg_string
  31. assert len(self.get_arguments()) > 0
  32. self.template_name = template_name
  33. self.template_params_string = template_params_string
  34. def get_arguments(self):
  35. return json.loads(self.arg_string)
  36. def get_template_params(self):
  37. return json.loads(self.template_params_string)