class ReminderAlert(AssistantReminder): id = Reminder.generate_id('assistants', 'alert') model = Alert def _get_delta(self): return timedelta( minutes=getattr(settings, 'DEFAULT_TIME_ALERT_REMIND', 30)) def generate_email_subject(self, object): return _('Reminder concerning a Creme CRM alert related to {entity}' ).format(entity=object.creme_entity) def generate_email_body(self, object): return _( """This mail is automatically sent by Crème CRM to remind you that an alert concerning {entity} will expire. Alert : {title}. which description is : {description}. which is related to the entity : {entity}""").format( entity=object.creme_entity, title=object.title, description=object.description, ) def get_Q_filter(self): return Q(trigger_date__lte=now() + self._get_delta(), is_validated=False) def next_wakeup(self, now_value): alert = Alert.objects.filter(is_validated=False, reminded=False) \ .order_by('trigger_date') \ .first() return alert.trigger_date - self._get_delta( ) if alert is not None else None
class ReminderTodo(AssistantReminder): id = Reminder.generate_id('assistants', 'todo') model = ToDo body = _( """This mail is automatically sent by Crème CRM to remind you that a todo concerning {entity} will expire. Todo : {title}. which description is : {description}. which is related to the entity : {entity}""" # NOQA ) def _get_delta(self): return timedelta(days=TODO_REMINDER_DAYS_BEFORE) def _get_min_hour(self): return SettingValue.objects.get_4_key(key=todo_reminder_key, default=9).value def generate_email_subject(self, object): return _( 'Reminder concerning a Creme CRM todo related to {entity}').format( entity=object.creme_entity, ) def generate_email_body(self, object): return self.body.format( entity=object.creme_entity, title=object.title, description=object.description, ) def get_Q_filter(self): # TODO: exclude Todos related to deleted entities ?? return Q(deadline__lte=now() + self._get_delta(), is_ok=False) def ok_for_continue(self): return localtime(now()).hour >= self._get_min_hour() def next_wakeup(self, now_value): wakeup = None todo = ToDo.objects.filter(is_ok=False, reminded=False, deadline__isnull=False) \ .order_by('deadline') \ .first() if todo is not None: wakeup = localtime(todo.deadline - self._get_delta()) min_hour = self._get_min_hour() if wakeup.hour < min_hour: if wakeup < now_value: wakeup = localtime(now_value) wakeup = wakeup.replace(hour=min_hour) return wakeup
class TestReminder(Reminder): id = Reminder.generate_id('creme_core', 'test_jobmanager_2') def next_wakeup(self, now_value): return rounded_hour + timedelta(minutes=70)
class TestReminder(Reminder): id = Reminder.generate_id('creme_core', 'test_jobmanager_1') def next_wakeup(self, now_value): return wake_up
class TestReminder1(Reminder): id = Reminder.generate_id( 'creme_core', 'ReminderTestCase_test_register_error01')