bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r1455913 - in /incubator/bloodhound/trunk/trac/trac: attachment.py tests/attachment.py ticket/model.py ticket/tests/model.py wiki/model.py
Date Wed, 13 Mar 2013 12:48:40 GMT
Author: andrej
Date: Wed Mar 13 12:48:40 2013
New Revision: 1455913

URL: http://svn.apache.org/r1455913
Log:
patching trac. Base on feedback from dev mailing list, return code for calling legacy I*ChangeListener
to its orignal place - towards #411

Modified:
    incubator/bloodhound/trunk/trac/trac/attachment.py
    incubator/bloodhound/trunk/trac/trac/tests/attachment.py
    incubator/bloodhound/trunk/trac/trac/ticket/model.py
    incubator/bloodhound/trunk/trac/trac/ticket/tests/model.py
    incubator/bloodhound/trunk/trac/trac/wiki/model.py

Modified: incubator/bloodhound/trunk/trac/trac/attachment.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/attachment.py?rev=1455913&r1=1455912&r2=1455913&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/attachment.py (original)
+++ incubator/bloodhound/trunk/trac/trac/attachment.py Wed Mar 13 12:48:40 2013
@@ -235,6 +235,8 @@ class Attachment(object):
 
         self.env.log.info("Attachment removed: %s" % self.title)
 
+        for listener in AttachmentModule(self.env).change_listeners:
+            listener.attachment_deleted(self)
         ResourceSystem(self.env).resource_deleted(self)
 
     def reparent(self, new_realm, new_id):
@@ -283,6 +285,9 @@ class Attachment(object):
 
         self.env.log.info("Attachment reparented: %s" % self.title)
 
+        for listener in AttachmentModule(self.env).change_listeners:
+            if hasattr(listener, 'attachment_reparented'):
+                listener.attachment_reparented(self, old_realm, old_id)
         old_values = dict(parent_realm=old_realm, parent_id=old_id)
         ResourceSystem(self.env).resource_changed(self, old_values=old_values)
 
@@ -328,6 +333,8 @@ class Attachment(object):
                 self.env.log.info("New attachment: %s by %s", self.title,
                                   self.author)
 
+        for listener in AttachmentModule(self.env).change_listeners:
+            listener.attachment_added(self)
         ResourceSystem(self.env).resource_created(self)
 
 
@@ -1098,30 +1105,3 @@ class AttachmentAdmin(Component):
                 if destination is not None:
                     output.close()
 
-class ResourceToAttachmentChangeListenerAdapter(Component):
-    """
-    The class provides backward compatibility for components implementing
-    IAttachmentChangeListener interface.
-    """
-    implements(IResourceChangeListener)
-    def match_resource(self, resource):
-        return isinstance(resource, Attachment)
-
-    def resource_created(self, resource, context):
-        for listener in AttachmentModule(self.env).change_listeners:
-            listener.attachment_added(resource)
-
-    def resource_changed(self, resource, old_values, context):
-        for listener in AttachmentModule(self.env).change_listeners:
-            if hasattr(listener, 'attachment_reparented'):
-                listener.attachment_reparented(
-                    resource,
-                    old_values.get("parent_realm"),
-                    old_values.get("parent_id"))
-
-    def resource_deleted(self, resource, context):
-        for listener in AttachmentModule(self.env).change_listeners:
-            listener.attachment_deleted(resource)
-
-    def resource_version_deleted(self, resource, context):
-        pass

Modified: incubator/bloodhound/trunk/trac/trac/tests/attachment.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/tests/attachment.py?rev=1455913&r1=1455912&r2=1455913&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/tests/attachment.py (original)
+++ incubator/bloodhound/trunk/trac/trac/tests/attachment.py Wed Mar 13 12:48:40 2013
@@ -6,8 +6,7 @@ from StringIO import StringIO
 import tempfile
 import unittest
 
-from trac.attachment import (Attachment, AttachmentModule,
-                             IAttachmentChangeListener)
+from trac.attachment import Attachment, AttachmentModule
 from trac.core import Component, implements, TracError
 from trac.perm import IPermissionPolicy, PermissionCache
 from trac.resource import Resource, resource_exists
@@ -30,24 +29,6 @@ hashes = {
     u'ÜberSicht': 'a16c6837f6d3d2cc3addd68976db1c55deb694c8',
 }
 
-class TestAttachmentChangeListener(Component):
-    implements(IAttachmentChangeListener)
-
-    def attachment_added(self, attachment):
-        self.action = "added"
-        self.attachment = attachment
-
-    def attachment_deleted(self, attachment):
-        self.action = "deleted"
-        self.attachment = attachment
-
-    def attachment_reparented(
-            self, attachment, old_parent_realm, old_parent_id):
-        self.action = "reparented"
-        self.attachment = attachment
-        self.old_parent_realm = old_parent_realm
-        self.old_parent_id = old_parent_id
-
 
 class TicketOnlyViewsTicket(Component):
     implements(IPermissionPolicy)
@@ -241,35 +222,6 @@ class AttachmentTestCase(unittest.TestCa
         att.insert('file.txt', StringIO(''), 1)
         self.assertTrue(resource_exists(self.env, att.resource))
 
-    def test_change_listener_created(self):
-        listener = TestAttachmentChangeListener(self.env)
-        attachment = self._create_attachment()
-        self.assertEqual('added', listener.action)
-        self.assertEqual(attachment, listener.attachment)
-
-    def test_change_listener_deleted(self):
-        listener = TestAttachmentChangeListener(self.env)
-        attachment = self._create_attachment()
-        attachment.delete()
-        self.assertEqual('deleted', listener.action)
-        self.assertEqual(attachment, listener.attachment)
-
-    def test_change_listener_deleted(self):
-        listener = TestAttachmentChangeListener(self.env)
-        attachment = self._create_attachment()
-        old_parent_realm = attachment.parent_realm
-        old_parent_id = attachment.parent_id
-        attachment.reparent("wiki", "SomePage")
-        self.assertEqual('reparented', listener.action)
-        self.assertEqual(attachment, listener.attachment)
-        self.assertEqual(old_parent_realm, listener.old_parent_realm)
-        self.assertEqual(old_parent_id, listener.old_parent_id)
-
-    def _create_attachment(self):
-        attachment = Attachment(self.env, 'wiki', 'WikiStart')
-        attachment.insert('file.txt', StringIO(''), 1)
-        return attachment
-
 
 class AttachmentResourceChangeListenerTestCase(unittest.TestCase):
     DUMMY_PARENT_REALM = "wiki"

Modified: incubator/bloodhound/trunk/trac/trac/ticket/model.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/ticket/model.py?rev=1455913&r1=1455912&r2=1455913&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/ticket/model.py (original)
+++ incubator/bloodhound/trunk/trac/trac/ticket/model.py Wed Mar 13 12:48:40 2013
@@ -25,9 +25,8 @@ from datetime import datetime
 from trac.attachment import Attachment
 from trac import core
 from trac.cache import cached
-from trac.core import TracError, implements
-from trac.resource import (Resource, ResourceNotFound, IResourceChangeListener,
-                           ResourceSystem)
+from trac.core import TracError
+from trac.resource import Resource, ResourceNotFound, ResourceSystem
 from trac.ticket.api import TicketSystem
 from trac.util import embedded_numbers, partition
 from trac.util.text import empty
@@ -253,6 +252,8 @@ class Ticket(object):
         self.resource = self.resource(id=tkt_id)
         self._old = {}
 
+        for listener in TicketSystem(self.env).change_listeners:
+            listener.ticket_created(self)
         ResourceSystem(self.env).resource_created(self)
 
         return self.id
@@ -361,6 +362,8 @@ class Ticket(object):
         self._old = {}
         self.values['changetime'] = when
 
+        for listener in TicketSystem(self.env).change_listeners:
+            listener.ticket_changed(self, comment, author, old_values)
         context = dict(comment=comment, author=author)
         ResourceSystem(self.env).resource_changed(self, old_values, context)
 
@@ -426,6 +429,8 @@ class Ticket(object):
             db("DELETE FROM ticket_change WHERE ticket=%s", (self.id,))
             db("DELETE FROM ticket_custom WHERE ticket=%s", (self.id,))
 
+        for listener in TicketSystem(self.env).change_listeners:
+            listener.ticket_deleted(self)
         ResourceSystem(self.env).resource_deleted(self)
 
     def get_change(self, cnum=None, cdate=None, db=None):
@@ -1037,6 +1042,8 @@ class Milestone(object):
             del self.cache.milestones
             TicketSystem(self.env).reset_ticket_fields()
 
+        for listener in TicketSystem(self.env).milestone_change_listeners:
+            listener.milestone_deleted(self)
         ResourceSystem(self.env).resource_deleted(self)
 
     def insert(self, db=None):
@@ -1058,6 +1065,8 @@ class Milestone(object):
             self.checkin()
             TicketSystem(self.env).reset_ticket_fields()
 
+        for listener in TicketSystem(self.env).milestone_change_listeners:
+            listener.milestone_created(self)
         ResourceSystem(self.env).resource_created(self)
 
     def update(self, db=None):
@@ -1096,6 +1105,8 @@ class Milestone(object):
 
         old_values = dict((k, v) for k, v in old.iteritems()
                           if getattr(self, k) != v)
+        for listener in TicketSystem(self.env).milestone_change_listeners:
+            listener.milestone_changed(self, old_values)
         ResourceSystem(self.env).resource_changed(self, old_values)
 
     @classmethod
@@ -1230,59 +1241,3 @@ class Version(object):
         def version_order(v):
             return (v.time or utcmax, embedded_numbers(v.name))
         return sorted(versions, key=version_order, reverse=True)
-
-class ResourceToMilestoneChangeListenerAdapter(core.Component):
-    """
-    The class provides backward compatibility for components implementing
-    IMilestoneChangeListener interface.
-    """
-    implements(IResourceChangeListener)
-
-    def match_resource(self, resource):
-        return isinstance(resource, Milestone)
-
-    def resource_created(self, resource, context):
-        for listener in TicketSystem(self.env).milestone_change_listeners:
-            listener.milestone_created(resource)
-
-    def resource_changed(self, resource, old_values, context):
-        for listener in TicketSystem(self.env).milestone_change_listeners:
-            listener.milestone_changed(resource, old_values)
-
-    def resource_deleted(self, resource, context):
-        for listener in TicketSystem(self.env).milestone_change_listeners:
-            listener.milestone_deleted(resource)
-
-    def resource_version_deleted(self, resource, context):
-        pass
-
-class ResourceToTicketChangeListenerAdapter(core.Component):
-    """
-    The class provides backward compatibility for components implementing
-    ITicketChangeListener interface.
-    """
-    implements(IResourceChangeListener)
-    def match_resource(self, resource):
-        return isinstance(resource, Ticket)
-
-    def resource_created(self, resource, context):
-        for listener in TicketSystem(self.env).change_listeners:
-            listener.ticket_created(resource)
-
-    def resource_changed(self, resource, old_values, context):
-        author = None
-        comment = None
-        if context:
-            comment = context.get("comment")
-            author = context.get("author")
-
-        for listener in TicketSystem(self.env).change_listeners:
-            listener.ticket_changed(resource, comment, author, old_values)
-
-    def resource_deleted(self, resource, context):
-        for listener in TicketSystem(self.env).change_listeners:
-            listener.ticket_deleted(resource)
-
-    def resource_version_deleted(self, resource, context):
-        pass
-

Modified: incubator/bloodhound/trunk/trac/trac/ticket/tests/model.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/ticket/tests/model.py?rev=1455913&r1=1455912&r2=1455913&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/ticket/tests/model.py (original)
+++ incubator/bloodhound/trunk/trac/trac/ticket/tests/model.py Wed Mar 13 12:48:40 2013
@@ -15,12 +15,13 @@ from trac.ticket.model import (
     Ticket, Component, Milestone, Priority, Type, Version
 )
 from trac.ticket.api import (
-    IMilestoneChangeListener, ITicketChangeListener, TicketSystem,
+    IMilestoneChangeListener, ITicketChangeListener, TicketSystem
 )
 from trac.test import EnvironmentStub
 from trac.tests.resource import TestResourceChangeListener
 from trac.util.datefmt import from_utimestamp, to_utimestamp, utc
 
+
 class TestTicketChangeListener(core.Component):
     implements(ITicketChangeListener)
 
@@ -1005,6 +1006,7 @@ class MilestoneTestCase(unittest.TestCas
         self.assertEqual('deleted', listener.action)
         self.assertEqual(milestone, listener.milestone)
 
+
 class ComponentTestCase(unittest.TestCase):
 
     def setUp(self):

Modified: incubator/bloodhound/trunk/trac/trac/wiki/model.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/wiki/model.py?rev=1455913&r1=1455912&r2=1455913&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/wiki/model.py (original)
+++ incubator/bloodhound/trunk/trac/trac/wiki/model.py Wed Mar 13 12:48:40 2013
@@ -21,7 +21,7 @@ from __future__ import with_statement
 from datetime import datetime
 
 from trac.core import *
-from trac.resource import Resource, ResourceSystem, IResourceChangeListener
+from trac.resource import Resource, ResourceSystem
 from trac.util.datefmt import from_utimestamp, to_utimestamp, utc
 from trac.util.translation import _
 from trac.wiki.api import WikiSystem, validate_page_name
@@ -110,8 +110,13 @@ class WikiPage(object):
 
         # Let change listeners know about the deletion
         if not self.exists:
+            for listener in WikiSystem(self.env).change_listeners:
+                listener.wiki_page_deleted(self)
             ResourceSystem(self.env).resource_deleted(self)
         else:
+            for listener in WikiSystem(self.env).change_listeners:
+                if hasattr(listener, 'wiki_page_version_deleted'):
+                    listener.wiki_page_version_deleted(self)
             ResourceSystem(self.env).resource_version_deleted(self)
 
     def save(self, author, comment, remote_addr, t=None, db=None):
@@ -150,6 +155,12 @@ class WikiPage(object):
         self.comment = comment
         self.time = t
 
+        for listener in WikiSystem(self.env).change_listeners:
+            if self.version == 1:
+                listener.wiki_page_added(self)
+            else:
+                listener.wiki_page_changed(self, self.version, t, comment,
+                                           author, remote_addr)
         context=dict(
             version=self.version,
             time=t,
@@ -200,6 +211,9 @@ class WikiPage(object):
         self.name = new_name
         self.env.log.info('Renamed page %s to %s', old_name, new_name)
 
+        for listener in WikiSystem(self.env).change_listeners:
+            if hasattr(listener, 'wiki_page_renamed'):
+                listener.wiki_page_renamed(self, old_name)
 
         ResourceSystem(self.env).resource_changed(
             self,
@@ -221,42 +235,3 @@ class WikiPage(object):
                 WHERE name=%s AND version<=%s ORDER BY version DESC
                 """, (self.name, self.version)):
             yield version, from_utimestamp(ts), author, comment, ipnr
-
-class ResourceToWikiChangeListenerAdapter(Component):
-    """
-    The class provides backward compatibility for components implementing
-    IWikiChangeListener interface.
-    """
-    implements(IResourceChangeListener)
-    def match_resource(self, resource):
-        return isinstance(resource, WikiPage)
-
-    def resource_created(self, resource, context):
-        for listener in WikiSystem(self.env).change_listeners:
-            listener.wiki_page_added(resource)
-
-    def resource_changed(self, resource, old_values, context):
-        if context is not None and context.get("source_action") == "rename":
-            for listener in WikiSystem(self.env).change_listeners:
-                 if hasattr(listener, 'wiki_page_renamed'):
-                     listener.wiki_page_renamed(
-                         resource, old_values.get("name"))
-        else:
-            for listener in WikiSystem(self.env).change_listeners:
-                    listener.wiki_page_changed(
-                        resource,
-                        context.get("version"),
-                        context.get("time"),
-                        context.get("comment"),
-                        context.get("author"),
-                        context.get("remote_addr"),
-                    )
-
-    def resource_deleted(self, resource, context):
-        for listener in WikiSystem(self.env).change_listeners:
-            listener.wiki_page_deleted(resource)
-
-    def resource_version_deleted(self, resource, context):
-        for listener in WikiSystem(self.env).change_listeners:
-            if hasattr(listener, 'wiki_page_version_deleted'):
-                listener.wiki_page_version_deleted(resource)



Mime
View raw message