def action_handler(sender, **kwargs): """ Handler function to create Action instance upon action signal call. """ kwargs.pop('signal', None) verb = kwargs.pop('verb') timestamp = kwargs.pop('timestamp', None) public = kwargs.pop('public', True) msg = kwargs.pop('change_message', None) content_type = kwargs.pop('content_type', None) object_id = kwargs.pop('object_id', None) object_repr = kwargs.pop('object_repr', None) act = Action( actor=sender, target_content_type=content_type, target_object_id=object_id, target_object_repr=object_repr[:200], verb=verb, change_message=msg, public=bool(public), ) if timestamp: act.timestamp = timestamp act.save()
def action_handler(sender, **kwargs): """ Handler function to create Action instance upon action signal call. """ kwargs.pop('signal', None) verb = kwargs.pop('verb') timestamp = kwargs.pop('timestamp', None) public = kwargs.pop('public', True) msg = kwargs.pop('change_message', None) content_type = kwargs.pop('content_type', None) object_id = kwargs.pop('object_id', None) object_repr = kwargs.pop('object_repr', None) act = Action( actor = sender, target_content_type = content_type, target_object_id = object_id, target_object_repr = object_repr[:200], verb = verb, change_message = msg, public = bool(public), ) if timestamp: act.timestamp = timestamp act.save()
def update_action_from_repository(code): ''' @summary: Collect the records of the actions happened on items of ``repository``. Basically, we can know only the details of first action (addition)and last action (last update) on an item. Items having date_published is ignored. @NOTE: Call only one time i.e. after running migrations for ``activity`` app. ''' # Just to avoid the calling of this function accidently if code != ACCESS_CODE: print 'WARNING: wrong access code!' print 'WARNING: Call only one time i.e. after running migrations for ``activity`` app' print 'If you understand the risk, use', ACCESS_CODE, 'as access code.' return False item_classes = [Person, Poetry, Book] # Do for all item types for item_cls in item_classes: print 'Updating actions for', item_cls.item_type() obj_list = item_cls.objects.order_by('-date_added', '-date_modified') for obj in obj_list: # Create action for date_added act = Action() act.timestamp = obj.date_added act.actor = obj.added_by act.target_content_type = ContentType.objects.get_for_model(obj) act.target_object_id = obj.id act.target_object_repr = obj.name[:200] act.verb = VERBS['ADDITION'] act.change_message = None act.public = True act.save() print obj.date_added, 'added' # Create action for date_modified, if it is different if obj.date_modified != obj.date_added: act = Action() act.timestamp = obj.date_modified act.actor = obj.modified_by act.target_content_type = ContentType.objects.get_for_model(obj) act.target_object_id = obj.id act.target_object_repr = obj.name[:200] act.verb = VERBS['CHANGE'] act.change_message = None act.public = True act.save() print obj.date_modified, 'updated'
def add(actor, type_desc, **kwargs): type, subtype = type_desc action = Action(actor=actor, type=type, subtype=subtype, **kwargs) # can this be DRY-ed somehow? # ----- global ----- if action.action_object: if hasattr(action.action_object, "name"): action.action_object_cache = action.action_object.name elif hasattr(action.action_object, "username"): action.action_object_cache = action.action_object.username elif hasattr(action.action_object, "value"): # rating action.action_object_cache = str(action.action_object.value) if action.target: if hasattr(action.target, "name"): action.target_cache = action.target.name elif hasattr(action.target, "username"): action.target_cache = action.target.username elif action.target._meta.app_label == 'solution' and action.target._meta.module_name == 'solution': data = [ action.target.author_id, action.target.author.username, action.target.task_id, action.target.task.name, action.target.task.author_id, ] # 250 chars should be enough for this action.target_cache = POST_SEND_CACHE_SEPARATOR.join([xss.escape(unicode(x)) for x in data]) # ----- type specific ----- if type == POST_SEND: T = action.action_object.content.text action.action_object_cache = T[:78] + '...' if len(T) > 80 else T action.save()