1. Olemis Lang
  2. trac-mq

Commits

Olemis Lang  committed e4d8cbb

Trac #11148 : Pass entity as first positional argument in 'ListenerNotifier.notify'

This is aimed at providing backwards compatibility with legacy
listener interfaces using a different name for entity argument

  • Participants
  • Parent commits dffc687
  • Branches trac_t11148

Comments (0)

Files changed (1)

File t11148/t11148_r11782_IEntityChangeListener_v2.diff

View file
 
 diff -r 8d0c3223a818 trac/core.py
 --- a/trac/core.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/core.py	Wed Apr 24 19:29:38 2013 -0500
++++ b/trac/core.py	Thu Apr 25 23:25:56 2013 -0500
 @@ -165,7 +165,6 @@
  
          locals_.setdefault('_implements', []).extend(interfaces)
  implements = Component.implements
  
  
-@@ -236,3 +235,98 @@
+@@ -236,3 +235,99 @@
          with the given class will not be available.
          """
          return True
 +
 +    BUILTIN_EVENTS = set(['created', 'changed', 'deleted', 'reparented'])
 +
-+    def notify(self, method, **kwargs):
++    def notify(self, method, entity, **kwargs):
 +        interface = method.im_class
 +        method_name = method.__name__
 +        if interface is None:
 +        xp = ExtensionPoint(interface)
 +        # FIXME : Sender component rather than self. Change method signature
 +        for listener in xp.extensions(self):
-+            getattr(listener, method_name)(**kwargs)
++            getattr(listener, method_name)(entity, **kwargs)
 +
 +        xp = ExtensionPoint(IEntityChangeListener)
 +        generic_listeners = xp.extensions(self)
 +        if generic_listeners:
++            kwargs['entity'] = entity
 +            #TODO : Include `interface` in kwargs ?
 +            parts = method_name.split('_', 1)
 +            action = parts[-1]
 +                getattr(listener, method_name)(**kwargs)
 diff -r 8d0c3223a818 trac/ticket/model.py
 --- a/trac/ticket/model.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/ticket/model.py	Wed Apr 24 19:29:38 2013 -0500
++++ b/trac/ticket/model.py	Thu Apr 25 23:25:56 2013 -0500
 @@ -25,7 +25,8 @@
  from trac.attachment import Attachment
  from trac import core
          """
 diff -r 8d0c3223a818 trac/ticket/tests/model.py
 --- a/trac/ticket/tests/model.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/ticket/tests/model.py	Wed Apr 24 19:29:38 2013 -0500
++++ b/trac/ticket/tests/model.py	Thu Apr 25 23:25:56 2013 -0500
 @@ -9,11 +9,11 @@
  
  from trac import core
  from trac.ticket.api import (
      IMilestoneChangeListener, ITicketChangeListener, TicketSystem
  )
-@@ -1097,6 +1097,417 @@
+@@ -1097,6 +1097,416 @@
          self.assertEqual([('Test', 0, 'Some text')], self.env.db_query(
              "SELECT name, time, description FROM version WHERE name='Test'"))
  
 +        cls = kwargs['entity'].__class__
 +        self.action.append(cls.__name__.lower() + '_' + kwargs['action'])
 +
-+
 +    def entity_created(self, entity, changeinfo=None):
 +        kwargs = locals()
 +        kwargs.update(action='created')
  
  def suite():
      suite = unittest.TestSuite()
-@@ -1107,6 +1518,17 @@
+@@ -1107,6 +1517,17 @@
      suite.addTest(unittest.makeSuite(MilestoneTestCase, 'test'))
      suite.addTest(unittest.makeSuite(ComponentTestCase, 'test'))
      suite.addTest(unittest.makeSuite(VersionTestCase, 'test'))