Changeset 3596
- Timestamp:
- 08/16/06 07:57:20 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/full-history/django/contrib/history/models.py
r3588 r3596 111 111 """ Saves a old copy of the record into the History table.""" 112 112 print "Sender: ",sender 113 print "Signal: ",kwargs['signal_name'] 113 114 114 115 if instance.__class__.__name__ is 'ChangeLog' or not hasattr(instance, 'History'): … … 124 125 if _import_models(instance): 125 126 try: 126 if instance.id: 127 if kwargs['signal_name'] is 'pre_delete': 128 old = instance 129 log = ChangeLog(parent=instance, comment="Object deleted. Last revision.") 130 print "Log created." 131 elif kwargs['signal_name'] is 'pre_save' and instance.id: 127 132 old = getattr(m, model['name']).objects.filter(pk=instance.id)[0] 128 133 log = ChangeLog(parent=instance, comment="Update") … … 143 148 print "Instance: ",instance.id 144 149 #print "Test: ",getattr(instance, 'Admin').date_hierarchy 145 print "Log: ",log 150 print "Log: ",log.change_time 146 151 147 152 log.object = Pickle.dumps(old, protocol=0) … … 151 156 152 157 dispatcher.connect( save_new_revision, signal=signals.pre_save ) 153 154 ########################### 155 # Pre-delete signal catch # 156 ########################### 157 158 def save_last_revision(sender, instance, signal, *args, **kwargs): 159 """ Saves the last copy of the record when the record is deleted.""" 160 print "Sender: ",sender 161 162 if instance.__class__.__name__ is 'ChangeLog' or not hasattr(instance, 'History'): 163 print "Not history-enabled class." 164 return 0 165 166 #instance_name = instance.__class__.__name__ 167 #print instance_name 168 m = None 169 old = None 170 log = None 171 172 if _import_models(instance): 173 try: 174 old = instance 175 log = ChangeLog(parent=instance, comment="Object deleted. Last revision.") 176 print "Log created." 177 except: 178 return 1 179 180 try: 181 log.object = Pickle.dumps(old, protocol=0) 182 log.save() 183 print "Last change saved." 184 except: 185 print "Failed!" 186 187 dispatcher.connect( save_last_revision, signal=signals.pre_delete ) 158 dispatcher.connect( save_new_revision, signal=signals.pre_delete )
