Exemple #1
0
def set_deferred_message(sender, instance, **kwargs):
    """
    Checks if the Node is a deferred Node and if so,
    set the deferred_message foreign key.
    """
    if not kwargs['raw']:
        if (getattr(instance.todo_state, 'abbreviation', None) == 'DFRD' and
            not instance.archived):
            # Node is deferred so create new message or update existing message
            message = instance.get_deferred_msg()
            if message is None:
                message = Message()
                message.source_node = instance
            message.subject = instance.title
            message.handler_path = 'plugins.deferred'
            message.owner = instance.owner
            message.rcvd_date = dt.datetime.combine(
                instance.scheduled_date,
                dt.time(0, tzinfo=get_current_timezone()),
            )
            message.save()
        else:
            # If instance is not deferred, then it can't have a deferred_message
            message = instance.get_deferred_msg()
            if message is not None and message.pk is not None:
                instance.deferred_message.delete()
Exemple #2
0
def set_deferred_message(sender, instance, **kwargs):
    """
    Checks if the Node is a deferred Node and if so,
    set the deferred_message foreign key.
    """
    if not kwargs['raw']:
        if (getattr(instance.todo_state, 'abbreviation', None) == 'DFRD'
                and not instance.archived):
            # Node is deferred so create new message or update existing message
            message = instance.get_deferred_msg()
            if message is None:
                message = Message()
                message.source_node = instance
            message.subject = instance.title
            message.handler_path = 'plugins.deferred'
            message.owner = instance.owner
            message.rcvd_date = dt.datetime.combine(
                instance.scheduled_date,
                dt.time(0, tzinfo=get_current_timezone()),
            )
            message.save()
        else:
            # If instance is not deferred, then it can't have a deferred_message
            message = instance.get_deferred_msg()
            if message is not None and message.pk is not None:
                instance.deferred_message.delete()
Exemple #3
0
 def test_create_node(self):
     message = Message()
     message.owner = User.objects.get(pk=1)
     message.subject = 'ordinary message'
     message.rcvd_date = dt.datetime.now(pytz.utc)
     message.message_text = 'Hi, person. Have a nice day'
     message.save()
     handler = BaseMessageHandler(message)
     node = handler.create_node()
     self.assertEqual(
         Message.objects.filter(pk=message.pk).count(), 1,
         'Message deleted after node created')
     self.assertTrue(isinstance(node, Node),
                     'create_node() returns a Node object')
     self.assertEqual(node.text, message.message_text)
Exemple #4
0
 def test_create_node(self):
     message = Message()
     message.owner = User.objects.get(pk=1)
     message.subject = 'ordinary message'
     message.rcvd_date = dt.datetime.now(pytz.utc)
     message.message_text = 'Hi, person. Have a nice day'
     message.save()
     handler = BaseMessageHandler(message)
     node = handler.create_node()
     self.assertEqual(
         Message.objects.filter(pk=message.pk).count(),
         1,
         'Message deleted after node created'
     )
     self.assertTrue(
         isinstance(node, Node),
         'create_node() returns a Node object'
     )
     self.assertEqual(
         node.text,
         message.message_text
     )