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 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()