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()
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 ''
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()
def action_handler(self): """ Get action handler object """ handlers = activityregistry.get_handlers() return handlers[self.handler]