Example #1
0
 def adjust_history(self, obj, action='U'):
     '''
     Adjusts the latest entry to accomidate any changes not picked up
     Likely changes are ManyToManyFields
     '''
     delta = self.get_difference(obj)
     if delta:
         ct = ContentType.objects.get_for_model(obj)
         try:
             history = get_active_histories().filter(content_type=ct, 
                                                     object_id=obj.pk).latest()
         except FullHistory.DoesNotExist:
             history = FullHistory(content_object=obj,
                                   request=get_or_create_request(), 
                                   action=action, 
                                   data=dict())
         if history.action == 'C':
             for key, value in delta.items():
                 delta[key] = (value[1],)
         data = history.data
         data.update(delta)
         history.data = data
         history.info = history.create_info()
         history.save()
         self.prepare_initial(obj)
         post_adjust.send(sender=type(obj), 
                          fullhistory=history, 
                          instance=obj)
         return history
     return None
Example #2
0
 def create_history(self, entry, action):
     '''
     Returns a FullHistory object recording the change of the object provided
     '''
     request = get_or_create_request()
     if action == 'U':
         data = self.get_difference(entry)
         if len(data) == 0:
             data = self.get_all_data_tuple(entry)
     elif action == 'C':
         data = self.get_all_data_tuple(entry)
     else:
         data = None
     fh = FullHistory(data=data, 
                      content_object=entry, 
                      action=action, 
                      request=request)
     fh.save()
     self.apply_parents(entry, lambda x: self.create_history(x, action))
     self.prepare_initial(entry)
     post_create.send(sender=type(entry), fullhistory=fh, instance=entry)
     return fh