Olemis Lang avatar Olemis Lang committed e98ea8f

BH Multiproduct #492 : Null neighborhood

Comments (0)

Files changed (2)

 t492/t492_r1462792_resource_neighborhood_core.diff
 t492/t492_r1464573_product_neighborhoods.diff
 t492/t492_r1462792_neighborhood_web_chrome.diff
+t492/t492_r1465566_null_neighborhood.diff

t492/t492_r1465566_null_neighborhood.diff

+# HG changeset patch
+# Parent 6f0ece1790931b05a065726b560c9a5bc65dbcfa
+BH Multiproduct #492 : Null neighborhood for local resources
+
+diff -r 6f0ece179093 trac/trac/resource.py
+--- a/trac/trac/resource.py	Mon Apr 08 15:28:11 2013 -0500
++++ b/trac/trac/resource.py	Mon Apr 08 21:21:41 2013 -0500
+@@ -119,8 +119,15 @@
+ 
+     __slots__ = ('_realm', '_id')
+ 
++    @property
++    def is_null(self):
++        return (self._realm, self._id) == (None, None)
++
+     def __repr__(self):
+-        return '<Neighborhood %s:%s>' % (self._realm, self._id)
++        if self.is_null:
++            return '<Neighborhood (null)>'
++        else:
++            return '<Neighborhood %s:%s>' % (self._realm, self._id)
+ 
+     def __eq__(self, other):
+         return isinstance(other, Neighborhood) and \
+@@ -160,7 +167,7 @@
+         True
+ 
+         >>> repr(Neighborhood(None))
+-        'None'
++        '<Neighborhood (null)>'
+         """
+         realm = neighborhood_or_realm
+         if isinstance(neighborhood_or_realm, Neighborhood):
+@@ -170,13 +177,10 @@
+                 realm = neighborhood_or_realm._realm
+         elif id is False:
+             id = None
+-        if (realm, id) == (None, None):
+-            return None
+-        else:
+-            neighborhood = super(Neighborhood, cls).__new__(cls)
+-            neighborhood._realm = realm
+-            neighborhood._id = id
+-            return neighborhood
++        neighborhood = super(Neighborhood, cls).__new__(cls)
++        neighborhood._realm = realm
++        neighborhood._id = id
++        return neighborhood
+ 
+     def __call__(self, realm=False, id=False, version=False, parent=False):
+         """Create a new Resource using the current resource as a template.
+@@ -211,6 +215,20 @@
+ 
+         >>> repr(nbh(None))
+         '<Neighborhood nbh:id>'
++
++        Null neighborhood will be used to put absolute resource
++        references ban into relative form (i.e. `resource.neiighborhood = None`)
++
++        >>> nullnbh = Neighborhood(None, None)
++        >>> repr(nullnbh)
++        '<Neighborhood (null)>'
++
++        >>> repr(nullnbh(main))
++        "<Resource u'wiki:WikiStart'>"
++        >>> repr(nullnbh(main3))
++        "<Resource u'wiki:WikiStart@3'>"
++        >>> repr(nullnbh(main0))
++        "<Resource u'wiki:WikiStart@0'>"
+         """
+         if (realm, id, version, parent) in ((False, False, False, False),
+                                             (None, False, False, False)):
+@@ -222,6 +240,8 @@
+             return resource
+ 
+     def _update_parents(self, resource):
++        if self.is_null and resource.neighborhood is None:
++            return resource
+         newresource = Resource(resource.realm, resource.id, resource.version, self)
+         current = newresource
+         parent = resource.parent
+@@ -378,6 +398,8 @@
+         resource.id = id
+         resource.version = version
+         resource.parent = parent
++        if neighborhood and neighborhood.is_null:
++            neighborhood = None
+         resource.neighborhood = neighborhood
+         return resource
+ 
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.