Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[full-history]

* Removed save_last_revision()
* signal.pre_delete now uses save_new_revision()
* Added "signal_name" check and "pre_delete" processingto save_new_revision()
* Fixed BUG from [3588]



git-svn-id: http://code.djangoproject.com/svn/django/branches/full-history@3596 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fd837f02354e730a425e5992309f6230f2be75b5 1 parent a064d08
authored August 16, 2006

Showing 1 changed file with 8 additions and 37 deletions. Show diff stats Hide diff stats

  1. 45  django/contrib/history/models.py
45  django/contrib/history/models.py
@@ -110,6 +110,7 @@ def _import_models(instance):
110 110
 def save_new_revision(sender, instance, signal, *args, **kwargs):
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'): 
115 116
 	print "Not history-enabled class."
@@ -123,7 +124,11 @@ def save_new_revision(sender, instance, signal, *args, **kwargs):
123 124
     
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")
129 134
 		print "Instance has an ID."
@@ -142,7 +147,7 @@ def save_new_revision(sender, instance, signal, *args, **kwargs):
142 147
     print "Old: ",old
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)
148 153
     log.save()
@@ -150,38 +155,4 @@ def save_new_revision(sender, instance, signal, *args, **kwargs):
150 155
     print "New change saved."
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 )

0 notes on commit fd837f0

Please sign in to comment.
Something went wrong with that request. Please try again.