[Checkins] SVN: grok/branches/jw-philipp-using-ndir-directives/src/grok/ The order directive (and the corresponding helpers) have moved back to Grok.

Philipp von Weitershausen philikon at philikon.de
Sun May 4 09:09:21 EDT 2008


Log message for revision 86363:
  The order directive (and the corresponding helpers) have moved back to Grok.

Changed:
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/__init__.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/components.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/directive.py
  A   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/arg_orderdirective.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/combined_orderdirective.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/combinednoorder_orderdirective.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/inter1.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/inter2.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/noarg_orderdirective.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/nodirective.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/test_grok.py
  U   grok/branches/jw-philipp-using-ndir-directives/src/grok/util.py

-=-
Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/__init__.py
===================================================================
--- grok/branches/jw-philipp-using-ndir-directives/src/grok/__init__.py	2008-05-04 13:06:40 UTC (rev 86362)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/__init__.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -46,10 +46,10 @@
 
 from martian import baseclass
 from grokcore.component.directive import (
-    context, name, title, description, provides, global_utility, direct, order)
+    context, name, title, description, provides, global_utility, direct)
 from grok.directive import (
     template, templatedir, local_utility, permissions, require, site,
-    layer, viewletmanager, view, traversable)
+    layer, viewletmanager, view, traversable, order)
 from grokcore.component.decorators import subscribe, adapter, implementer
 from martian.error import GrokError, GrokImportError
 

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/components.py
===================================================================
--- grok/branches/jw-philipp-using-ndir-directives/src/grok/components.py	2008-05-04 13:06:40 UTC (rev 86362)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/components.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -53,9 +53,9 @@
 from zope.viewlet.viewlet import ViewletBase
 
 import grok
+import grokcore.component
 import z3c.flashmessage.interfaces
 import martian.util
-import grokcore.component.util
 
 from grok import interfaces, formlib, util
 
@@ -680,7 +680,7 @@
         if self.template:
             return self.template.render(self)
         else:
-            viewlets = grokcore.component.util.sort_components(self.viewlets)
+            viewlets = util.sort_components(self.viewlets)
             return u'\n'.join([viewlet.render() for viewlet in viewlets])
 
     def namespace(self):

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/directive.py
===================================================================
--- grok/branches/jw-philipp-using-ndir-directives/src/grok/directive.py	2008-05-04 13:06:40 UTC (rev 86362)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/directive.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -183,3 +183,14 @@
         if name is None:
             name = attr
         return (name, attr)
+
+class order(martian.Directive):
+    scope = martian.CLASS
+    store = martian.ONCE
+    default = 0, 0
+
+    _order = 0
+
+    def factory(self, value=0):
+        order._order += 1
+        return value, order._order

Copied: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order (from rev 86351, grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order)

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/arg_orderdirective.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/arg_orderdirective.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/arg_orderdirective.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -5,7 +5,7 @@
 
   >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
 
-  >>> from grokcore.component.util import sort_components
+  >>> from grok.util import sort_components
   >>> sort_components(components)
   [<...Fifth object at ...>,
    <...Fourth object at ...>,
@@ -15,7 +15,7 @@
 
 """
 
-import grokcore.component as grok
+import grok
 
 class First(object):
     grok.order(5)

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/combined_orderdirective.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/combined_orderdirective.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/combined_orderdirective.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -6,7 +6,7 @@
 
   >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
 
-  >>> from grokcore.component.util import sort_components
+  >>> from grok.util import sort_components
   >>> sort_components(components)
   [<...Third object at ...>,
    <...Fourth object at ...>,
@@ -16,7 +16,7 @@
 
 """
 
-import grokcore.component as grok
+import grok
 
 class First(object):
     grok.order(2)

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/combinednoorder_orderdirective.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/combinednoorder_orderdirective.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/combinednoorder_orderdirective.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -6,7 +6,7 @@
 
   >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
 
-  >>> from grokcore.component.util import sort_components
+  >>> from grok.util import sort_components
   >>> sort_components(components)
   [<...Fifth object at ...>,
    <...Third object at ...>,
@@ -16,7 +16,7 @@
 
 """
 
-import grokcore.component as grok
+import grok
 
 class First(object):
     grok.order()

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/inter1.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/inter1.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/inter1.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -12,7 +12,7 @@
   >>> from inter2 import Four, Five, Six
   >>> components = [One(), Two(), Three(), Four(), Five(), Six()]
 
-  >>> from grokcore.component.util import sort_components
+  >>> from grok.util import sort_components
   >>> sort_components(components)
   [<...Three object at ...>,
    <...One object at ...>,
@@ -23,7 +23,7 @@
 
 """
 
-import grokcore.component as grok
+import grok
 
 class One(object):
     grok.order()

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/inter2.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/inter2.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/inter2.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -2,7 +2,7 @@
 This module used by inter1 tests
 """
 
-import grokcore.component as grok
+import grok
 
 class Four(object):
     grok.order(1)

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/noarg_orderdirective.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/noarg_orderdirective.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/noarg_orderdirective.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -5,7 +5,7 @@
 
   >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
 
-  >>> from grokcore.component.util import sort_components
+  >>> from grok.util import sort_components
   >>> sort_components(components)
   [<...First object at ...>,
    <...Second object at ...>,
@@ -15,7 +15,7 @@
 
 """
 
-import grokcore.component as grok
+import grok
 
 class First(object):
     grok.order()

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/nodirective.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/tests/order/nodirective.py	2008-05-04 12:37:38 UTC (rev 86351)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/order/nodirective.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -5,7 +5,7 @@
 
   >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
 
-  >>> from grokcore.component.util import sort_components
+  >>> from grok.util import sort_components
   >>> sort_components(components)
   [<...Fifth object at ...>,
    <...First object at ...>,

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/test_grok.py
===================================================================
--- grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/test_grok.py	2008-05-04 13:06:40 UTC (rev 86362)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/tests/test_grok.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -46,7 +46,7 @@
                  'zcml', 'static', 'utility', 'xmlrpc', 'json', 'container',
                  'traversal', 'form', 'grokker', 'directive', 'util',
                  'baseclass', 'annotation', 'application', 'template',
-                 'viewlet', 'testsetup', 'conflict']:
+                 'viewlet', 'testsetup', 'conflict', 'order']:
         suite.addTest(suiteFromPackage(name))
     return suite
 

Modified: grok/branches/jw-philipp-using-ndir-directives/src/grok/util.py
===================================================================
--- grok/branches/jw-philipp-using-ndir-directives/src/grok/util.py	2008-05-04 13:06:40 UTC (rev 86362)
+++ grok/branches/jw-philipp-using-ndir-directives/src/grok/util.py	2008-05-04 13:09:20 UTC (rev 86363)
@@ -101,3 +101,14 @@
     # Add the new skin.
     ifaces.append(skin)
     interface.directlyProvides(request, *ifaces)
+
+def _sort_key(component):
+    explicit_order, implicit_order = grok.order.get(component)
+    return (explicit_order,
+            component.__module__,
+            implicit_order,
+            component.__class__.__name__)
+
+def sort_components(components):
+    # if components have a grok.order directive, sort by that
+    return sorted(components, key=_sort_key)



More information about the Checkins mailing list