[Checkins] SVN: z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py - Export compatible directives based on PREFER_Z3C_PT setting.

Sidnei da Silva sidnei at enfoldsystems.com
Mon Mar 9 15:00:10 EDT 2009


Log message for revision 97715:
  - Export compatible directives based on PREFER_Z3C_PT setting.
  
  

Changed:
  U   z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py

-=-
Modified: z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py	2009-03-09 18:52:31 UTC (rev 97714)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py	2009-03-09 19:00:10 UTC (rev 97715)
@@ -11,6 +11,7 @@
 from zope.app.form.browser import metaconfigure as formmeta
 
 from z3c.ptcompat import ViewPageTemplateFile
+from z3c.ptcompat import config
 
 def clone_and_replace_globals(func, new_globals):
     func_globals = func.func_globals.copy()
@@ -111,45 +112,56 @@
 
     return viewletmeta.viewletManagerDirective(_context, name, *args, **kwargs)
 
-# Replace globals in *Factory by the ones from our package, cloning
-# the existing functions so we don't have to re-define them.
-new_factory_globals = dict(ViewPageTemplateFile=ViewPageTemplateFile,
-                           SimpleViewClass=SimpleViewClass)
+if config.PREFER_Z3C_PT:
+    # Replace globals in *Factory by the ones from our package, cloning
+    # the existing functions so we don't have to re-define them.
+    new_factory_globals = dict(ViewPageTemplateFile=ViewPageTemplateFile,
+                               SimpleViewClass=SimpleViewClass)
 
-AddViewFactory = clone_and_replace_globals(formmeta.AddViewFactory,
-                                           new_factory_globals)
-EditViewFactory = clone_and_replace_globals(formmeta.EditViewFactory,
-                                            new_factory_globals)
-DisplayViewFactory = clone_and_replace_globals(formmeta.DisplayViewFactory,
+    AddViewFactory = clone_and_replace_globals(formmeta.AddViewFactory,
                                                new_factory_globals)
+    EditViewFactory = clone_and_replace_globals(formmeta.EditViewFactory,
+                                                new_factory_globals)
+    DisplayViewFactory = clone_and_replace_globals(formmeta.DisplayViewFactory,
+                                                   new_factory_globals)
 
-# Now, replace globals in the directive handlers' __call__ by our own
-# factories that were cloned right above.
-new_form_globals = dict(AddViewFactory=AddViewFactory,
-                        EditViewFactory=EditViewFactory,
-                        DisplayViewFactory=DisplayViewFactory)
+    # Now, replace globals in the directive handlers' __call__ by our own
+    # factories that were cloned right above.
+    new_form_globals = dict(AddViewFactory=AddViewFactory,
+                            EditViewFactory=EditViewFactory,
+                            DisplayViewFactory=DisplayViewFactory)
 
-class AddFormDirective(formmeta.AddFormDirective):
-    __call__ = clone_and_replace_globals(
-        formmeta.AddFormDirective.__call__.im_func,
-        new_form_globals)
+    class AddFormDirective(formmeta.AddFormDirective):
+        __call__ = clone_and_replace_globals(
+            formmeta.AddFormDirective.__call__.im_func,
+            new_form_globals)
 
-class EditFormDirective(formmeta.EditFormDirective):
-    __call__ = clone_and_replace_globals(
-        formmeta.EditFormDirective.__call__.im_func,
-        new_form_globals)
+    class EditFormDirective(formmeta.EditFormDirective):
+        __call__ = clone_and_replace_globals(
+            formmeta.EditFormDirective.__call__.im_func,
+            new_form_globals)
 
-class FormDirective(formmeta.FormDirective):
-    __call__ = clone_and_replace_globals(
-        formmeta.FormDirective.__call__.im_func,
-        new_form_globals)
+    class FormDirective(formmeta.FormDirective):
+        __call__ = clone_and_replace_globals(
+            formmeta.FormDirective.__call__.im_func,
+            new_form_globals)
 
-class SubeditFormDirective(formmeta.SubeditFormDirective):
-    __call__ = clone_and_replace_globals(
-        formmeta.SubeditFormDirective.__call__.im_func,
-        new_form_globals)
+    class SubeditFormDirective(formmeta.SubeditFormDirective):
+        __call__ = clone_and_replace_globals(
+            formmeta.SubeditFormDirective.__call__.im_func,
+            new_form_globals)
 
-class SchemaDisplayDirective(formmeta.SchemaDisplayDirective):
-    __call__ = clone_and_replace_globals(
-        formmeta.SchemaDisplayDirective.__call__.im_func,
-        new_form_globals)
+    class SchemaDisplayDirective(formmeta.SchemaDisplayDirective):
+        __call__ = clone_and_replace_globals(
+            formmeta.SchemaDisplayDirective.__call__.im_func,
+            new_form_globals)
+else:
+    AddViewFactory = formmeta.AddViewFactory
+    EditViewFactory = formmeta.EditViewFactory
+    DisplayViewFactory = formmeta.DisplayViewFactory
+
+    AddFormDirective = formmeta.AddFormDirective
+    EditFormDirective = formmeta.EditFormDirective
+    FormDirective = formmeta.FormDirective
+    SubeditFormDirective = formmeta.SubeditFormDirective
+    SchemaDisplayDirective = formmeta.SchemaDisplayDirective



More information about the Checkins mailing list