Commits

Olemis Lang committed 817030f

Trac #11148 : Move all I*ChangeListener interfaces trac.ticket.model => trac.ticket.api

Comments (0)

Files changed (1)

t11148/t11148_r11782_IEntityChangeListener_v2.diff

 
 diff -r 8d0c3223a818 trac/core.py
 --- a/trac/core.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/core.py	Fri Apr 26 00:27:26 2013 -0500
++++ b/trac/core.py	Sat Apr 27 16:41:49 2013 -0500
 @@ -165,7 +165,6 @@
  
          locals_.setdefault('_implements', []).extend(interfaces)
 +                getattr(listener, method_name)(**kwargs)
 diff -r 8d0c3223a818 trac/tests/core.py
 --- a/trac/tests/core.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/tests/core.py	Fri Apr 26 00:27:26 2013 -0500
++++ b/trac/tests/core.py	Sat Apr 27 16:41:49 2013 -0500
 @@ -15,7 +15,7 @@
  # Author: Christopher Lenz <cmlenz@gmx.de>
  
  def suite():
      return unittest.makeSuite(ComponentTestCase, 'test')
  
-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	Fri Apr 26 00:27:26 2013 -0500
-@@ -25,7 +25,8 @@
- from trac.attachment import Attachment
- from trac import core
- from trac.cache import cached
--from trac.core import TracError
-+from trac.core import (Interface, IEntityChangeListener, ListenerNotifier,
-+                       TracError)
- from trac.resource import Resource, ResourceNotFound
- from trac.ticket.api import TicketSystem
- from trac.util import embedded_numbers, partition
-@@ -718,6 +719,7 @@
- class AbstractEnum(object):
-     type = None
-     ticket_col = None
-+    change_listener_interface = None
- 
-     def __init__(self, env, name=None, db=None):
-         if not self.ticket_col:
-@@ -761,6 +763,11 @@
-                 except ValueError:
-                     pass # Ignore cast error for this non-essential operation
-             TicketSystem(self.env).reset_ticket_fields()
-+
-+        interface = self.change_listener_interface
-+        ListenerNotifier(self.env).notify(getattr(interface, 
-+                    interface._entity_listener_prefix + '_deleted'),
-+                    entity=self)
-         self.value = self._old_value = None
-         self.name = self._old_name = None
- 
-@@ -788,6 +795,10 @@
- 
-         self._old_name = self.name
-         self._old_value = self.value
-+        interface = self.change_listener_interface
-+        ListenerNotifier(self.env).notify(getattr(interface, 
-+                    interface._entity_listener_prefix + '_created'),
-+                    entity=self)
- 
-     def update(self, db=None):
-         """Update the enum value.
-@@ -811,8 +822,17 @@
-                    (self.name, self._old_name))
-             TicketSystem(self.env).reset_ticket_fields()
- 
-+        old_values = dict()
-+        if self.name != self._old_name:
-+            old_values["name"] = self._old_name
-+        if self.value != self._old_value:
-+            old_values["value"] = self._old_value
-         self._old_name = self.name
-         self._old_value = self.value
-+        interface = self.change_listener_interface
-+        ListenerNotifier(self.env).notify(getattr(interface, 
-+                    interface._entity_listener_prefix + '_changed'),
-+                    entity=self, old_values=old_values)
- 
-     @classmethod
-     def select(cls, env, db=None):
-@@ -831,9 +851,33 @@
-                 yield obj
+diff -r 8d0c3223a818 trac/ticket/api.py
+--- a/trac/ticket/api.py	Thu Apr 18 14:30:21 2013 +0000
++++ b/trac/ticket/api.py	Sat Apr 27 16:41:49 2013 -0500
+@@ -179,6 +179,146 @@
+         """Called when a milestone is deleted."""
  
  
 +class ITypeChangeListener(Interface):
 +        """Called when a ticket type is deleted."""
 +
 +
- class Type(AbstractEnum):
-     type = 'ticket_type'
-     ticket_col = 'type'
-+    change_listener_interface = ITypeChangeListener
- 
- 
- class Status(object):
-@@ -848,16 +892,112 @@
-             yield status
- 
- 
 +class IResolutionChangeListener(Interface):
 +    """Extension point interface for components that require notification
 +    when ticket resolution are created, modified, or deleted.
 +        """Called when a ticket resolution is deleted."""
 +
 +
- class Resolution(AbstractEnum):
-     type = 'resolution'
-+    change_listener_interface = IResolutionChangeListener
-+
-+
 +class IPriorityChangeListener(Interface):
 +    """Extension point interface for components that require notification
 +    when ticket priority are created, modified, or deleted.
 +
 +    def priority_deleted(entity, changeinfo = None):
 +        """Called when a ticket priority is deleted."""
- 
- 
- class Priority(AbstractEnum):
-     type = 'priority'
-+    change_listener_interface = IPriorityChangeListener
 +
 +
 +class ISeverityChangeListener(Interface):
 +
 +    def severity_deleted(entity, changeinfo = None):
 +        """Called when a ticket severity is deleted."""
- 
- 
- class Severity(AbstractEnum):
-     type = 'severity'
-+    change_listener_interface = ISeverityChangeListener
 +
 +
 +class IComponentChangeListener(Interface):
 +
 +    def component_deleted(entity, changeinfo = None):
 +        """Called when a ticket component is deleted."""
- 
- 
- class Component(object):
-@@ -893,9 +1033,13 @@
-         with self.env.db_transaction as db:
-             self.env.log.info("Deleting component %s", self.name)
-             db("DELETE FROM component WHERE name=%s", (self.name,))
--            self.name = self._old_name = None
-             TicketSystem(self.env).reset_ticket_fields()
- 
-+        ListenerNotifier(self.env).notify(
-+                    IComponentChangeListener.component_deleted, entity=self)
 +
-+        self.name = self._old_name = None
 +
-     def insert(self, db=None):
-         """Insert a new component.
- 
-@@ -915,6 +1059,9 @@
-             self._old_name = self.name
-             TicketSystem(self.env).reset_ticket_fields()
- 
-+        ListenerNotifier(self.env).notify(
-+                    IComponentChangeListener.component_created, entity=self)
-+
-     def update(self, db=None):
-         """Update the component.
- 
-@@ -926,6 +1073,7 @@
-         if not self.name:
-             raise TracError(_("Invalid component name."))
- 
-+        old_name = self._old_name
-         with self.env.db_transaction as db:
-             self.env.log.info("Updating component '%s'", self.name)
-             db("""UPDATE component SET name=%s,owner=%s, description=%s
-@@ -939,6 +1087,14 @@
-                 self._old_name = self.name
-             TicketSystem(self.env).reset_ticket_fields()
- 
-+        #todo:add support of old_values for owner and description fields
-+        old_values = dict()
-+        if self.name != old_name:
-+            old_values["name"] = old_name
-+        ListenerNotifier(self.env).notify(
-+                    IComponentChangeListener.component_changed, 
-+                    entity=self, old_values=old_values)
-+
-     @classmethod
-     def select(cls, env, db=None):
-         """
-@@ -1170,6 +1326,30 @@
-     return groups
- 
- 
 +class IVersionChangeListener(Interface):
 +    """Extension point interface for components that require notification
 +    when ticket version are created, modified, or deleted.
 +        """Called when a ticket version is deleted."""
 +
 +
- class Version(object):
+ class TicketSystem(Component):
+     implements(IPermissionRequestor, IWikiSyntaxProvider, IResourceManager)
+ 
+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	Sat Apr 27 16:41:49 2013 -0500
+@@ -25,9 +25,13 @@
+ from trac.attachment import Attachment
+ from trac import core
+ from trac.cache import cached
+-from trac.core import TracError
++from trac.core import (Interface, IEntityChangeListener, ListenerNotifier,
++                       TracError)
+ from trac.resource import Resource, ResourceNotFound
+-from trac.ticket.api import TicketSystem
++from trac.ticket.api import TicketSystem, IMilestoneChangeListener, \
++                            ITypeChangeListener, IResolutionChangeListener, \
++                            IPriorityChangeListener, ISeverityChangeListener,\
++                            IComponentChangeListener, IVersionChangeListener
+ from trac.util import embedded_numbers, partition
+ from trac.util.text import empty
+ from trac.util.datefmt import from_utimestamp, parse_date, to_utimestamp, \
+@@ -718,6 +722,7 @@
+ class AbstractEnum(object):
+     type = None
+     ticket_col = None
++    change_listener_interface = None
+ 
      def __init__(self, env, name=None, db=None):
-         self.env = env
-@@ -1199,9 +1379,12 @@
+         if not self.ticket_col:
+@@ -761,6 +766,11 @@
+                 except ValueError:
+                     pass # Ignore cast error for this non-essential operation
+             TicketSystem(self.env).reset_ticket_fields()
++
++        interface = self.change_listener_interface
++        ListenerNotifier(self.env).notify(getattr(interface, 
++                    interface._entity_listener_prefix + '_deleted'),
++                    entity=self)
+         self.value = self._old_value = None
+         self.name = self._old_name = None
+ 
+@@ -788,6 +798,10 @@
+ 
+         self._old_name = self.name
+         self._old_value = self.value
++        interface = self.change_listener_interface
++        ListenerNotifier(self.env).notify(getattr(interface, 
++                    interface._entity_listener_prefix + '_created'),
++                    entity=self)
+ 
+     def update(self, db=None):
+         """Update the enum value.
+@@ -811,8 +825,17 @@
+                    (self.name, self._old_name))
+             TicketSystem(self.env).reset_ticket_fields()
+ 
++        old_values = dict()
++        if self.name != self._old_name:
++            old_values["name"] = self._old_name
++        if self.value != self._old_value:
++            old_values["value"] = self._old_value
+         self._old_name = self.name
+         self._old_value = self.value
++        interface = self.change_listener_interface
++        ListenerNotifier(self.env).notify(getattr(interface, 
++                    interface._entity_listener_prefix + '_changed'),
++                    entity=self, old_values=old_values)
+ 
+     @classmethod
+     def select(cls, env, db=None):
+@@ -834,6 +857,7 @@
+ class Type(AbstractEnum):
+     type = 'ticket_type'
+     ticket_col = 'type'
++    change_listener_interface = ITypeChangeListener
+ 
+ 
+ class Status(object):
+@@ -850,14 +874,17 @@
+ 
+ class Resolution(AbstractEnum):
+     type = 'resolution'
++    change_listener_interface = IResolutionChangeListener
+ 
+ 
+ class Priority(AbstractEnum):
+     type = 'priority'
++    change_listener_interface = IPriorityChangeListener
+ 
+ 
+ class Severity(AbstractEnum):
+     type = 'severity'
++    change_listener_interface = ISeverityChangeListener
+ 
+ 
+ class Component(object):
+@@ -893,9 +920,13 @@
+         with self.env.db_transaction as db:
+             self.env.log.info("Deleting component %s", self.name)
+             db("DELETE FROM component WHERE name=%s", (self.name,))
+-            self.name = self._old_name = None
+             TicketSystem(self.env).reset_ticket_fields()
+ 
++        ListenerNotifier(self.env).notify(
++                    IComponentChangeListener.component_deleted, entity=self)
++
++        self.name = self._old_name = None
++
+     def insert(self, db=None):
+         """Insert a new component.
+ 
+@@ -915,6 +946,9 @@
+             self._old_name = self.name
+             TicketSystem(self.env).reset_ticket_fields()
+ 
++        ListenerNotifier(self.env).notify(
++                    IComponentChangeListener.component_created, entity=self)
++
+     def update(self, db=None):
+         """Update the component.
+ 
+@@ -926,6 +960,7 @@
+         if not self.name:
+             raise TracError(_("Invalid component name."))
+ 
++        old_name = self._old_name
+         with self.env.db_transaction as db:
+             self.env.log.info("Updating component '%s'", self.name)
+             db("""UPDATE component SET name=%s,owner=%s, description=%s
+@@ -939,6 +974,14 @@
+                 self._old_name = self.name
+             TicketSystem(self.env).reset_ticket_fields()
+ 
++        #todo:add support of old_values for owner and description fields
++        old_values = dict()
++        if self.name != old_name:
++            old_values["name"] = old_name
++        ListenerNotifier(self.env).notify(
++                    IComponentChangeListener.component_changed, 
++                    entity=self, old_values=old_values)
++
+     @classmethod
+     def select(cls, env, db=None):
+         """
+@@ -1199,9 +1242,12 @@
          with self.env.db_transaction as db:
              self.env.log.info("Deleting version %s", self.name)
              db("DELETE FROM version WHERE name=%s", (self.name,))
      def insert(self, db=None):
          """Insert a new version.
  
-@@ -1220,6 +1403,9 @@
+@@ -1220,6 +1266,9 @@
              self._old_name = self.name
              TicketSystem(self.env).reset_ticket_fields()
  
      def update(self, db=None):
          """Update the version.
  
-@@ -1231,6 +1417,7 @@
+@@ -1231,6 +1280,7 @@
          if not self.name:
              raise TracError(_("Invalid version name."))
  
          with self.env.db_transaction as db:
              self.env.log.info("Updating version '%s'", self.name)
              db("""UPDATE version
-@@ -1244,6 +1431,15 @@
+@@ -1244,6 +1294,15 @@
                  self._old_name = self.name
              TicketSystem(self.env).reset_ticket_fields()
  
          """
 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	Fri Apr 26 00:27:26 2013 -0500
++++ b/trac/ticket/tests/model.py	Sat Apr 27 16:41:49 2013 -0500
 @@ -9,15 +9,16 @@
  
  from trac import core