Anonymous avatar Anonymous committed fbf327f

[full-history]
* Removed 'signal_name' attribute from signal from django/db/models/
* Added two wrapper functions for save_new_revision(): save_new_revision_save() and save_new_revision_delete()
* Added 'signal_name' variable to save_new_revision()
* Changed 'signal_name' variable handling in save_new_revision()
* Fixed dispatcher.connects to reflect previous three changes

Comments (0)

Files changed (3)

django/contrib/history/models.py

 
     return m
 
-def save_new_revision(sender, instance, signal, *args, **kwargs):
+
+### Signal wrapper functions
+## pre_save
+def save_new_revision_save(sender, instance, signal, *args, **kwargs):
+    """
+    Wrapper function for save_new_revision() - for pre_save signal
+    This way there is no need to modify django/db/models/base.py
+    """
+    save_new_revision(sender, instance, signal, signal_name='pre_save', *args, **kwargs)
+
+## pre_delete
+def save_new_revision_delete(sender, instance, signal, *args, **kwargs):
+    """
+    Wrapper function for save_new_revision() - for pre_delete signal
+    This way there is no need to modify django/db/models/query.py
+    """
+    save_new_revision(sender, instance, signal, signal_name='pre_delete', *args, **kwargs)
+
+
+### Actual save_new_revision
+def save_new_revision(sender, instance, signal, signal_name, *args, **kwargs):
     """ 
     Saves a old copy of the record into the History table.
 
 
     """
     print "Sender: ",sender
-    print "Signal: ",kwargs['signal_name']
+    print "Signal_name: ",signal_name
 
     if instance.__class__.__name__ is 'ChangeLog' or not hasattr(instance, 'History'): 
 	print "Not history-enabled class."
     
     if im:
 	try:
-	    if kwargs['signal_name'] is 'pre_delete':
+	    if signal_name is 'pre_delete':
 		print "Instance was last revision."
 		old = instance
 		log = ChangeLog(parent=instance, change_type='D', comment="Object deleted. Last revision.")
-	    elif ((kwargs['signal_name'] is 'pre_save') and instance.id):
+	    elif ((signal_name is 'pre_save') and instance.id):
 		print "Instance has an ID."
 		old = getattr(im, instance.__class__.__name__).objects.filter(pk=instance.id)[0]
 		log = ChangeLog(parent=instance, change_type='U', comment="Update")
 	print "ChangeLog faild to save changes."
 
 
-dispatcher.connect( save_new_revision, signal=signals.pre_save )
-dispatcher.connect( save_new_revision, signal=signals.pre_delete )
+dispatcher.connect( save_new_revision_save, signal=signals.pre_save )
+dispatcher.connect( save_new_revision_delete, signal=signals.pre_delete )

django/db/models/base.py

     _prepare = classmethod(_prepare)
 
     def save(self):
-        dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self, signal_name="pre_save")
+        dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self)
 
         non_pks = [f for f in self._meta.fields if not f.primary_key]
         cursor = connection.cursor()

django/db/models/query.py

 
         # Pre notify all instances to be deleted
         for pk_val, instance in seen_objs[cls]:
-            dispatcher.send(signal=signals.pre_delete, sender=cls, instance=instance, signal_name="pre_delete")
+            dispatcher.send(signal=signals.pre_delete, sender=cls, instance=instance)
 
         pk_list = [pk for pk,instance in seen_objs[cls]]
         for related in cls._meta.get_all_related_many_to_many_objects():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.