25 | | """ |
26 | | Returns 'current-offset' revision of the 'object' |
27 | | """ |
28 | | if not kwargs or not kwargs['offset']: offset=0 |
29 | | |
30 | | ct = ContentType.objects.get_for_model(object) |
31 | | |
32 | | if kwargs and kwargs['revision']: |
33 | | return self.get_query_set().filter( |
34 | | content_type=ct.id).filter( |
35 | | object_id=object.id).filter( |
36 | | pk=revision)[offset] |
37 | | else: |
38 | | return self.get_query_set().filter( |
39 | | content_type=ct.id).filter( |
40 | | object_id=object.id)[offset] |
| 25 | """ |
| 26 | Returns 'current-offset' revision of the 'object' |
| 27 | """ |
| 28 | if not kwargs or not kwargs['offset']: offset=0 |
| 29 | |
| 30 | ct = ContentType.objects.get_for_model(object) |
| 31 | |
| 32 | if kwargs and kwargs['revision']: |
| 33 | return self.get_query_set().filter( |
| 34 | content_type=ct.id).filter( |
| 35 | object_id=object.id).filter( |
| 36 | pk=revision)[offset] |
| 37 | else: |
| 38 | return self.get_query_set().filter( |
| 39 | content_type=ct.id).filter( |
| 40 | object_id=object.id)[offset] |
43 | | """ |
44 | | list_history(object): Returns a list of all revisions for that id. |
45 | | list_history(object, offset=X): Returns a list of last X revisions. |
46 | | """ |
47 | | ct = ContentType.objects.get_for_model(object) |
48 | | if kwargs['offset']: |
49 | | return self.get_query_set().filter( |
50 | | content_type=ct.id).filter( |
51 | | object_id=object.id)[:kwargs['offset']] |
52 | | else: |
53 | | return ChangeLog.objects.filter(object_id=object.id) |
| 43 | """ |
| 44 | list_history(object): Returns a list of all revisions for that id. |
| 45 | list_history(object, offset=X): Returns a list of last X revisions. |
| 46 | """ |
| 47 | ct = ContentType.objects.get_for_model(object) |
| 48 | if kwargs['offset']: |
| 49 | return self.get_query_set().filter( |
| 50 | content_type=ct.id).filter( |
| 51 | object_id=object.id)[:kwargs['offset']] |
| 52 | else: |
| 53 | return ChangeLog.objects.filter(object_id=object.id) |
86 | | date_hierarchy = 'change_time' |
87 | | list_filter = ['change_time', 'change_type', 'content_type'] |
88 | | fields = ( |
89 | | ('Meta info', {'fields': ('change_time', 'content_type', 'object_id', 'user', 'comment'),}), |
90 | | ('Object', {'fields': ('object',),}), |
91 | | ) |
| 86 | date_hierarchy = 'change_time' |
| 87 | list_filter = ['change_time', 'change_type', 'content_type'] |
| 88 | fields = ( |
| 89 | ('Meta info', {'fields': ('change_time', 'content_type', 'object_id', 'user', 'comment'),}), |
| 90 | ('Object', {'fields': ('object',),}), |
| 91 | ) |
129 | | if model['name'] is instance.__class__.__name__: |
130 | | try: |
131 | | m = __import__(model['module'], '', '', [model['name']]) |
132 | | #print model['module'],": ",model['name'],"- ",m |
133 | | print "Model import done: ",m |
134 | | except: |
135 | | print "Model import error." |
136 | | return False |
| 129 | if model['name'] is instance.__class__.__name__: |
| 130 | try: |
| 131 | m = __import__(model['module'], '', '', [model['name']]) |
| 132 | #print model['module'],": ",model['name'],"- ",m |
| 133 | print "Model import done: ",m |
| 134 | except: |
| 135 | print "Model import error." |
| 136 | return False |
165 | | try: |
166 | | if kwargs['signal_name'] is 'pre_delete': |
167 | | print "Instance was last revision." |
168 | | old = instance |
169 | | log = ChangeLog(parent=instance, change_type='D', comment="Object deleted. Last revision.") |
170 | | elif ((kwargs['signal_name'] is 'pre_save') and instance.id): |
171 | | print "Instance has an ID." |
172 | | old = getattr(im, instance.__class__.__name__).objects.filter(pk=instance.id)[0] |
173 | | log = ChangeLog(parent=instance, change_type='U', comment="Update") |
174 | | else: |
175 | | print "Instance without an ID." |
176 | | old = instance |
177 | | instance.id = 0 # FIX: ID cannot be None |
178 | | log = ChangeLog(parent=instance, change_type='A', comment="New") |
179 | | except: |
180 | | return 1 |
| 165 | try: |
| 166 | if kwargs['signal_name'] is 'pre_delete': |
| 167 | print "Instance was last revision." |
| 168 | old = instance |
| 169 | log = ChangeLog(parent=instance, change_type='D', comment="Object deleted. Last revision.") |
| 170 | elif ((kwargs['signal_name'] is 'pre_save') and instance.id): |
| 171 | print "Instance has an ID." |
| 172 | old = getattr(im, instance.__class__.__name__).objects.filter(pk=instance.id)[0] |
| 173 | log = ChangeLog(parent=instance, change_type='U', comment="Update") |
| 174 | else: |
| 175 | print "Instance without an ID." |
| 176 | old = instance |
| 177 | instance.id = 0 # FIX: ID cannot be None |
| 178 | log = ChangeLog(parent=instance, change_type='A', comment="New") |
| 179 | except: |
| 180 | return 1 |