Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
|
|||
2 | |||
3 | from tracim.lib.utils.logger import logger |
||
4 | from tracim.models.auth import User |
||
5 | from tracim.models.data import Content |
||
6 | |||
7 | |||
8 | class INotifier(object): |
||
9 | """ |
||
10 | Interface for Notifier instances |
||
11 | """ |
||
12 | def __init__(self, config, current_user: User=None): |
||
13 | pass |
||
14 | |||
15 | def notify_content_update(self, content: Content): |
||
16 | raise NotImplementedError |
||
17 | |||
18 | |||
19 | class NotifierFactory(object): |
||
20 | |||
21 | @classmethod |
||
22 | def create(cls, config, current_user: User=None) -> INotifier: |
||
23 | if not config.EMAIL_NOTIFICATION_ACTIVATED: |
||
24 | return DummyNotifier(config, current_user) |
||
25 | return EmailNotifier(config, current_user) |
||
26 | |||
27 | |||
28 | class DummyNotifier(INotifier): |
||
29 | send_count = 0 |
||
30 | |||
31 | def __init__(self, config, current_user: User=None): |
||
32 | INotifier.__init__(config, current_user) |
||
33 | logger.info(self, 'Instantiating Dummy Notifier') |
||
34 | |||
35 | def notify_content_update(self, content: Content): |
||
36 | type(self).send_count += 1 |
||
37 | logger.info( |
||
38 | self, |
||
39 | 'Fake notifier, do not send notification for update of content {}'.format(content.content_id) # nopep8 |
||
40 | ) |
||
41 | |||
42 | |||
43 | class EmailNotifier(INotifier): |
||
44 | # TODO - G.M [emailNotif] move and restore Email Notifier in another file. |
||
45 | pass |
||
46 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.