コード例 #1
0
def action_handler(sender, **kwargs):
    handlers = activityregistry.get_handlers()
    handler_name = kwargs.get('handler')
    actor = kwargs.get('actor')
    if handler_name in handlers:
        action = Action(
            handler=handler_name,
            actor_content_type=ContentType.objects.get_for_model(actor),
            actor_object_id=actor.pk,
        )
        for opt in ('action_object', 'target'):
            obj = kwargs.get(opt, None)
            if obj is not None:
                setattr(action, '%s_object_id' % opt, obj.pk)
                setattr(action, '%s_content_type' % opt,
                        ContentType.objects.get_for_model(obj))
        action.save()
コード例 #2
0
 def render(self, item):
     """
     Render activities recursively
     """
     if not isinstance(item, Action):
         output = []
         for value in item:
             output.append(self.render(value))
         return output
     else:
         try:
             handlers = activityregistry.get_handlers()
             return handlers[item.handler].render(item)
         except KeyError:
             from django.conf import settings
             if settings.DEBUG:
                 return 'No handler available for %s' % item.handler
             return ''
コード例 #3
0
ファイル: views.py プロジェクト: eofs/django-activity
 def render(self, item):
     """
     Render activities recursively
     """
     if not isinstance(item, Action):
         output = []
         for value in item:
             output.append(self.render(value))
         return output
     else:
         try:
             handlers = activityregistry.get_handlers()
             return handlers[item.handler].render(item)
         except KeyError:
             from django.conf import settings
             if settings.DEBUG:
                 return 'No handler available for %s' % item.handler
             return ''
コード例 #4
0
ファイル: models.py プロジェクト: anobi/django-activity
def action_handler(sender, **kwargs):
    handlers = activityregistry.get_handlers()
    handler_name = kwargs.get('handler')
    actor = kwargs.get('actor')
    is_global = kwargs.get('is_global', False)
    if handler_name in handlers:
        action = Action(
            handler=handler_name,
            actor_content_type=ContentType.objects.get_for_model(actor),
            actor_object_id=actor.pk,
            is_global=is_global,
        )
        for opt in ('action_object', 'target'):
            obj = kwargs.get(opt, None)
            if obj is not None:
                setattr(action, '%s_object_id' % opt, obj.pk)
                setattr(action, '%s_content_type' % opt,
                        ContentType.objects.get_for_model(obj))
        action.save()
コード例 #5
0
ファイル: models.py プロジェクト: eofs/django-activity
 def action_handler(self):
     """
     Get action handler object
     """
     handlers = activityregistry.get_handlers()
     return handlers[self.handler]
コード例 #6
0
ファイル: models.py プロジェクト: anobi/django-activity
 def action_handler(self):
     """
     Get action handler object
     """
     handlers = activityregistry.get_handlers()
     return handlers[self.handler]