notifications.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. from tracim.lib.utils.logger import logger
  3. from tracim.models.auth import User
  4. from tracim.models.data import Content
  5. class INotifier(object):
  6. """
  7. Interface for Notifier instances
  8. """
  9. def __init__(self, config, current_user: User=None):
  10. pass
  11. def notify_content_update(self, content: Content):
  12. raise NotImplementedError
  13. class NotifierFactory(object):
  14. @classmethod
  15. def create(cls, config, current_user: User=None) -> INotifier:
  16. if not config.EMAIL_NOTIFICATION_ACTIVATED:
  17. return DummyNotifier(config, current_user)
  18. return EmailNotifier(config, current_user)
  19. class DummyNotifier(INotifier):
  20. send_count = 0
  21. def __init__(self, config, current_user: User=None):
  22. INotifier.__init__(config, current_user)
  23. logger.info(self, 'Instantiating Dummy Notifier')
  24. def notify_content_update(self, content: Content):
  25. type(self).send_count += 1
  26. logger.info(
  27. self,
  28. 'Fake notifier, do not send notification for update of content {}'.format(content.content_id) # nopep8
  29. )
  30. class EmailNotifier(INotifier):
  31. # TODO - G.M [emailNotif] move and restore Email Notifier in another file.
  32. pass