[Zope3-checkins] CVS: Products3/NewsSite - browser.py:1.4 configure.zcml:1.16 interfaces.py:1.6

Ulrich Eck ueck@net-labs.de
Thu, 27 Mar 2003 09:05:12 -0500


Update of /cvs-repository/Products3/NewsSite
In directory cvs.zope.org:/tmp/cvs-serv16580

Modified Files:
	browser.py configure.zcml interfaces.py 
Log Message:
newssite setup and easy addform support


=== Products3/NewsSite/browser.py 1.3 => 1.4 ===
--- Products3/NewsSite/browser.py:1.3	Thu Mar 27 05:21:59 2003
+++ Products3/NewsSite/browser.py	Thu Mar 27 09:05:11 2003
@@ -30,67 +30,35 @@
 from zope.app.interfaces.dublincore import IZopeDublinCore
 from zope.app.browser.container.adding import Adding
 
-from interfaces import INewsSite
+from interfaces import INewsSite, INewsSiteFormSchema
 from interfaces import ISyndicationPolicies
+from zope.app.dublincore.annotatableadapter \
+     import ZDCAnnotatableAdapter
 
 from sitesetup import setupSite
 
-class NewsSiteAddForm:
-    """News Site AddForm Mixin (includes Site Setup Hook).
-    """
 
-    def createAndAdd(self, data):
-        """Add the desired object using the data in the data argument.
+class NewsSiteAttributesAdapter(ZDCAnnotatableAdapter):
 
-        The data argument is a dictionary with the data entered in the form.
-        """
+    __implements__ = INewsSiteFormSchema
 
+    __used_for__ = INewsSite
+    
+    def __init__(self, context):
+        self.context = context
+        super(NewsSiteAttributesAdapter, self).__init__(context)
 
-        newssite_fields = getFields(INewsSite).keys()
-        dublincore_fields = getFields(IZopeDublinCore).keys()
-        
-        content = self.create()
-
-        siteadapter = queryAdapter(content, INewsSite, content)
-        dcadapter = queryAdapter(content, IZopeDublinCore)
-
-        errors = []
-
-        for name in self._set_before_add:
-            if name in data:
-                try:
-                    if name in newssite_fields:
-                        setattr(siteadapter, name, data[name])
-                    elif name in dublincore_fields:
-                        setattr(dcadapter, name, data[name])
-                except ValidationError:
-                    errors.append(sys.exc_info()[1])
-
-        if errors:
-            raise WidgetsError(*errors)
-
-        publish(self.context, ObjectCreatedEvent(content))
-
-        content = self.add(content)
-
-        siteadapter = queryAdapter(content, INewsSite, content)
-        dcadapter = queryAdapter(content, IZopeDublinCore)
-
-        for name in self._set_after_add:
-            if name in data:
-                try:
-                    if name in newssite_fields:
-                        setattr(siteadapter, name, data[name])
-                    elif name in dublincore_fields:
-                        setattr(dcadapter, name, data[name])
-                except ValidationError:
-                    errors.append(sys.exc_info()[1])
+    # some context properties could be handled here
 
-        if errors:
-            raise WidgetsError(*errors)
 
-        setupSite(content, data)
 
+class NewsSiteAddForm:
+    """News Site AddForm Mixin (includes Site Setup Hook).
+    """
+
+    def createAndAdd(self, data):
+        content = super(NewsSiteAddForm, self).createAndAdd(data)
+        setupSite(content, data)
         return content
         
 


=== Products3/NewsSite/configure.zcml 1.15 => 1.16 ===
--- Products3/NewsSite/configure.zcml:1.15	Thu Mar 27 09:00:59 2003
+++ Products3/NewsSite/configure.zcml	Thu Mar 27 09:05:11 2003
@@ -203,25 +203,23 @@
 
 <!-- Register NewsSite with the "global" add list.
   -->
-<browser:menuItem
-    menu="add_content"
-    title="News site"
-    for="zope.app.interfaces.container.IAdding"
-    action="NewsSite"
-    description="A boring news site."
-	permission="zope.View"
+
+<adapter
+    factory=".browser.NewsSiteAttributesAdapter"
+    provides=".interfaces.INewsSiteFormSchema"
+    for=".interfaces.INewsSite"
     />
 
 <browser:addform
   name="AddNewsSite"
   menu="add_content" title="News Site"
-  schema=".interfaces.INewsSiteAddForm"
+  schema=".interfaces.INewsSiteFormSchema"
   permission="zope.ManageContent"
   content_factory=".newssite.NewsSite"
   class=".browser.NewsSiteAddForm"
-  arguments="title"
-  fields="title"
-  set_after_add="title"
+  arguments=""
+  fields="title description"
+  set_after_add="title description"
   />
 
 


=== Products3/NewsSite/interfaces.py 1.5 => 1.6 ===
--- Products3/NewsSite/interfaces.py:1.5	Thu Mar 27 05:21:59 2003
+++ Products3/NewsSite/interfaces.py	Thu Mar 27 09:05:11 2003
@@ -32,8 +32,10 @@
 	"""Provides a marker interface for news site"""
 
 
-
-class INewsSiteAddForm(IZopeDublinCore):
+#
+#   Helper Interface for Add/Edit Forms
+#
+class INewsSiteFormSchema(IZopeDublinCore):
         """Schema for News Site AddForm."""