[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - add.py:1.35.2.1 editview.py:1.41.2.1 metaconfigure.py:1.6.2.1 metadirectives.py:1.7.14.1

Christian Zagrodnick cvs-admin at zope.org
Sat Dec 6 13:29:48 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv16289/src/zope/app/browser/form

Modified Files:
      Tag: gotcha-usage-branch
	add.py editview.py metaconfigure.py metadirectives.py 
Log Message:
finished the support of 'usage' in page templates (or better views)
 - repaired editForm
 - added to addForm
 - added <usage name=.. /> zcml directive
 - directives that rely on usage check for existing usages
 - asserting that a usage can only be defined once
 - tried use of usage in container/add.pt



=== Zope3/src/zope/app/browser/form/add.py 1.35 => 1.35.2.1 ===
--- Zope3/src/zope/app/browser/form/add.py:1.35	Fri Nov 21 12:10:10 2003
+++ Zope3/src/zope/app/browser/form/add.py	Sat Dec  6 13:29:17 2003
@@ -32,6 +32,8 @@
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.schema.interfaces import ValidationError
 from zope.security.checker import defineChecker, NamesChecker
+from zope.app.publisher.browser.globalbrowsermenuservice import \
+    globalBrowserMenuService
 
 class AddView(EditView):
     """Simple edit-view base class.
@@ -137,8 +139,10 @@
 def AddViewFactory(name, schema, label, permission, layer,
                    template, default_template, bases, for_,
                    fields, content_factory, arguments,
-                   keyword_arguments, set_before_add, set_after_add):
+                   keyword_arguments, set_before_add, set_after_add,
+                   menu=u'', usage=u''):
 
+    s = zapi.getService(None, zapi.servicenames.Presentation)
     class_  = SimpleViewClass(
         template,
         used_for = schema, bases = bases
@@ -155,6 +159,14 @@
 
     class_.generated_form = ViewPageTemplateFile(default_template)
 
+    if not usage and menu:
+        usage = globalBrowserMenuService.getMenuUsage(menu)
+    if not usage:
+        # usage could be None
+        usage = u''
+    s.useUsage(usage)
+    class_.usage = usage
+
     defineChecker(class_,
                   NamesChecker(
                     ("__call__", "__getitem__",
@@ -163,5 +175,4 @@
                     )
                   )
 
-    s = zapi.getService(None, zapi.servicenames.Presentation)
     s.provideView(for_, name, IBrowserRequest, class_, layer)


=== Zope3/src/zope/app/browser/form/editview.py 1.41 => 1.41.2.1 ===
--- Zope3/src/zope/app/browser/form/editview.py:1.41	Fri Nov 21 12:10:10 2003
+++ Zope3/src/zope/app/browser/form/editview.py	Sat Dec  6 13:29:17 2003
@@ -32,6 +32,8 @@
 from zope.app.event.objectevent import ObjectModifiedEvent
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
+from zope.app.publisher.browser.globalbrowsermenuservice import \
+    globalBrowserMenuService
 
 class EditView(BrowserView):
     """Simple edit-view base class
@@ -117,6 +119,7 @@
                     template, default_template, bases, for_, fields,
                     fulledit_path=None, fulledit_label=None, menu=u'',
                     usage=u''):
+    s = zapi.getService(None, zapi.servicenames.Presentation)
     # XXX What about the __implements__ of the bases?
     class_ = SimpleViewClass(template, used_for=schema, bases=bases)
     class_.schema = schema
@@ -131,13 +134,17 @@
 
     class_.generated_form = ViewPageTemplateFile(default_template)
 
-    class_.usage = usage or (
-        menu and globalBrowserMenuService.getMenuUsage(menu))
-
+    if not usage and menu:
+        usage = globalBrowserMenuService.getMenuUsage(menu)
+    if not usage:
+        # usage could be None
+        usage = u''
+    s.useUsage(usage)
+    class_.usage = usage
+    
     defineChecker(class_,
                   NamesChecker(("__call__", "__getitem__",
                                 "browserDefault", "publishTraverse"),
                                permission))
 
-    s = zapi.getService(None, zapi.servicenames.Presentation)
     s.provideView(for_, name, IBrowserRequest, class_, layer)


=== Zope3/src/zope/app/browser/form/metaconfigure.py 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/browser/form/metaconfigure.py:1.6	Fri Nov 21 12:12:19 2003
+++ Zope3/src/zope/app/browser/form/metaconfigure.py	Sat Dec  6 13:29:17 2003
@@ -132,6 +132,7 @@
 
     view = AddView
     default_template = 'add.pt'
+    usage = None
     for_ = IAdding
 
     # default add form information
@@ -147,6 +148,7 @@
             if (not self.menu) or (not self.title):
                 raise ValueError("If either menu or title are specified, "
                                  "they must both be specified")
+            # XXX why no self.schema in for as in EditFormDirective
             menuItemDirective(
                 self._context, self.menu, self.for_, '@@' + self.name,
                 self.title, permission=self.permission,
@@ -209,11 +211,12 @@
         self._handle_arguments()
 
         self._context.action(
-            discriminator = self._discriminator(),
-            callable = AddViewFactory,
-            args = self._args()+(self.content_factory, self.arguments,
+            discriminator=self._discriminator(),
+            callable=AddViewFactory,
+            args=self._args()+(self.content_factory, self.arguments,
                                  self.keyword_arguments,
                                  self.set_before_add, self.set_after_add),
+            kw={'menu': self.menu, 'usage': self.usage},
             )
 
 class EditFormDirective(BaseFormDirective):
@@ -232,9 +235,10 @@
     def __call__(self):
         self._handle_menu()
         self._context.action(
-            discriminator = self._discriminator(),
-            callable = EditViewFactory,
-            args = self._args()+(self.menu, self.usage),
+            discriminator=self._discriminator(),
+            callable=EditViewFactory,
+            args=self._args(),
+            kw={'menu': self.menu, 'usage': self.usage},
         )
 
 class SubeditFormDirective(BaseFormDirective):


=== Zope3/src/zope/app/browser/form/metadirectives.py 1.7 => 1.7.14.1 ===
--- Zope3/src/zope/app/browser/form/metadirectives.py:1.7	Tue Aug 12 08:47:55 2003
+++ Zope3/src/zope/app/browser/form/metadirectives.py	Sat Dec  6 13:29:17 2003
@@ -19,8 +19,9 @@
 from zope.configuration.fields import GlobalObject, Tokens, Path, \
      Bool, PythonIdentifier, MessageID
 from zope.schema import Text, TextLine, Id
+from zope.app.interfaces.publisher.browser import IUsage
 
-class ICommonInformation(Interface):
+class ICommonInformation(IUsage):
     """
     Common information for all successive directives
     """
@@ -79,6 +80,7 @@
         subclass any special classes, such as BrowserView.""",
         required=False
         )
+
 
 class ICommonFormInformation(ICommonInformation):
     """




More information about the Zope3-Checkins mailing list