Seif Lotfy has proposed merging lp:~zeitgeist/zeitgeist/delete-hooks into 
lp:zeitgeist.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)
Related bugs:
  #595919 delete_event_hook for extensions
  https://bugs.launchpad.net/bugs/595919

-- 
https://code.launchpad.net/~zeitgeist/zeitgeist/delete-hooks/+merge/28754
Your team Zeitgeist Framework Team is requested to review the proposed merge of 
lp:~zeitgeist/zeitgeist/delete-hooks into lp:zeitgeist.
=== modified file '_zeitgeist/engine/extension.py'
--- _zeitgeist/engine/extension.py	2010-04-01 20:10:36 +0000
+++ _zeitgeist/engine/extension.py	2010-06-29 13:45:39 +0000
@@ -86,6 +86,10 @@
 			should see it
 		"""
 		return event
+	
+	def delete_event_hook(self, ids):
+		pass
+
 
 def load_class(path):
 	"""
@@ -179,6 +183,14 @@
 				continue
 		return event
 	
+	def apply_delete_hooks(self, ids):
+		# Apply extension filters if we have an event
+	
+		# FIXME: We need a stable iteration order
+		for ext in self.__extensions.itervalues():
+			event = ext.delete_event_hook(ids, None)
+			
+	
 	def apply_insert_hooks(self, event, sender):
 		# FIXME: We need a stable iteration order
 		for ext in self.__extensions.itervalues():

=== modified file '_zeitgeist/engine/main.py'
--- _zeitgeist/engine/main.py	2010-05-14 17:16:49 +0000
+++ _zeitgeist/engine/main.py	2010-06-29 13:45:39 +0000
@@ -609,6 +609,9 @@
 				% ",".join(["?"] * len(ids)), ids)
 			self._cursor.connection.commit()
 			log.debug("Deleted %s" % map(int, ids))
+			
+			self.extensions.apply_delete_hooks(ids)
+			
 			return timestamps
 		else:
 			log.debug("Tried to delete non-existing event(s): %s" % map(int, ids))

=== modified file 'test/engine-extension-test.py'
--- test/engine-extension-test.py	2010-04-04 18:30:48 +0000
+++ test/engine-extension-test.py	2010-06-29 13:45:39 +0000
@@ -65,6 +65,22 @@
 		ids = import_events("test/data/five_events.js", self.engine)
 		# all inserts where blocked, so each id is 0 to indicate this
 		self.assertEquals(filter(None, ids), [])
+	
+	def testDeleteHook(self):
+		
+		class DeleteAllInsertExtension(Extension):
+			PUBLIC_METHODS = []
+			del_ids = []
+			
+			@classmethod
+			def delete_event_hook(self, del_ids, sender):
+				self.del_ids = del_ids
+				
+		self.engine.extensions.load(DeleteAllInsertExtension)
+		ids = import_events("test/data/five_events.js", self.engine)
+		# all inserts where blocked, so each id is 0 to indicate this
+		self.engine.delete_events([ids[1]])
+		self.assertEquals(DeleteAllInsertExtension.del_ids, [ids[1]])
 
 if __name__ == "__main__":
 	unittest.main()

_______________________________________________
Mailing list: https://launchpad.net/~zeitgeist
Post to     : zeitgeist@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zeitgeist
More help   : https://help.launchpad.net/ListHelp

Reply via email to