Exemple #1
0
 def send_message_to_abridge(self, user, item):
     message = LawPalAbridgeService.render_reminder_template(**self.message_template_data(item=item))
     abridge_service = self.get_abridge_service(user)
     if not abridge_service:
         logger.critical('Could not instantiate Abridge Service')
     else:
         abridge_service.create_event(content_group='Important', content=message)
Exemple #2
0
def _abridge_send(verb_slug, actor, target, action_object, message=None, comment=None, item=None,
                  reviewdocument=None, send_to_all=False, **kwargs):
    """
    Send activity data to abridge
    """
    if verb_slug in ABRIDGE_WHITELIST:
        abridge_service = False  # assume false

        query_set = target.participants
        #
        # If we are not sending this message to all participants then exclude the originator
        #
        if send_to_all is False:
            query_set = query_set.exclude(id=actor.pk)

        for user in query_set.all():
            #
            # Categorically turn it off by default
            #
            try:
                abridge_service = LawPalAbridgeService(user=user,
                                                       ABRIDGE_ENABLED=getattr(settings, 'ABRIDGE_ENABLED', False))  
                                                       # initialize and pass in the user
            except Exception as e:
                # AbridgeService is not running.
                logger.critical('Abridge Service is not running because: %s' % e)

            if abridge_service:
                from toolkit.api.serializers.user import LiteUserSerializer
                message_data = _serialize_kwargs({'actor': actor,
                                                  'action_object': action_object,
                                                  'target': target,
                                                  'comment': comment,
                                                  'message': message,
                                                  'item': item,
                                                  'reviewdocument': reviewdocument,
                                                  'verb_slug': verb_slug})
                # Because we cant mixn the ApiMixin class ot the django User Object
                message_data['actor'] = LiteUserSerializer(actor, context={'request': None}).data

                message_for_abridge = LawPalAbridgeService.render_message_template(user, **message_data)

                abridge_service.create_event(content_block=kwargs.get('content_block', 'default'),
                                             content_group=target.name,
                                             content=message_for_abridge)
Exemple #3
0
    def test_expired_reminder_template(self):
        # create item
        date_due = datetime.datetime.today() + datetime.timedelta(days=-5)

        item = mommy.make('item.Item',
                          name='Test Item #1',
                          matter=self.matter,
                          date_due=date_due)

        template_data = self.reminder_service.message_template_data(item=item)
        message = LawPalAbridgeService.render_reminder_template(**template_data)

        self.assertEqual(message,
                         u'<p>Action required</p>\n\n<h3>Warning, Item Overdue</h3>\n<p style="">The "Test Item #1" in the "Lawpal (test)" Matter has not been closed, and its due date has past: %s (%s)</p>\n\n<a href="%s" alt="Click here to view it" title="Click here to view it">%s</a>' % (date_due.strftime('%m-%d-%Y'), naturaltime(date_due), template_data.get('action_link'), template_data.get('action_link')))