[Zope3-checkins] CVS: Products3/NewsSite - sitesetup.py:1.1 browser.py:1.3 configure.zcml:1.13 interfaces.py:1.5

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


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

Modified Files:
	browser.py configure.zcml interfaces.py 
Added Files:
	sitesetup.py 
Log Message:
start setupSite machinery


=== Added File Products3/NewsSite/sitesetup.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""NewsSite setup.

$Id: sitesetup.py,v 1.1 2003/03/27 10:21:59 jack-e Exp $
"""
__metaclass__ = type


def setupSite(site, data):
    print "setup site"


=== Products3/NewsSite/browser.py 1.2 => 1.3 ===
--- Products3/NewsSite/browser.py:1.2	Wed Mar 26 12:18:16 2003
+++ Products3/NewsSite/browser.py	Thu Mar 27 05:21:59 2003
@@ -15,23 +15,94 @@
 
 $Id$
 """
+__metaclass__ = type
 
-from zope.component import getAdapter
+from zope.schema import getFields
+from zope.component import getAdapter, queryAdapter
 from zope.component import getView
 from zope.component import queryUtility
 
 from zope.proxy.context import ContextWrapper
 
+from zope.schema.interfaces import ValidationError
+from zope.app.event import publish
+from zope.app.event.objectevent import ObjectCreatedEvent
 from zope.app.interfaces.dublincore import IZopeDublinCore
 from zope.app.browser.container.adding import Adding
 
 from interfaces import INewsSite
 from interfaces import ISyndicationPolicies
 
+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.
+
+        The data argument is a dictionary with the data entered in the form.
+        """
+
+
+        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])
+
+        if errors:
+            raise WidgetsError(*errors)
+
+        setupSite(content, data)
+
+        return content
+        
+
+
+        
+
 class NewsSiteAdding(Adding):
     """Custom adding view for NewsSite objects.
     """
     menu_id = "add_news"
+
+
 
 class NewsSiteSyndicationPoliciesView:
 


=== Products3/NewsSite/configure.zcml 1.12 => 1.13 ===
--- Products3/NewsSite/configure.zcml:1.12	Wed Mar 26 15:46:29 2003
+++ Products3/NewsSite/configure.zcml	Thu Mar 27 05:21:59 2003
@@ -63,7 +63,6 @@
 </content>
 
 <!-- Register us with the "global" add list.
-  -->
 <browser:menuItem
     menu="add_content"
     for="zope.app.interfaces.container.IAdding"
@@ -72,6 +71,22 @@
     description="A boring news site."
 	permission="zope.View"
     />
+ -->
+
+<browser:addform
+  name="AddNewsSite"
+  menu="add_content" title="News Site"
+  schema=".interfaces.INewsSiteAddForm"
+  permission="zope.ManageContent"
+  content_factory=".newssite.NewsSite"
+  class=".browser.NewsSiteAddForm"
+  arguments="title"
+  fields="title"
+  set_after_add="title"
+  />
+
+
+
 
 <!-- Custom adding view.
   -->


=== Products3/NewsSite/interfaces.py 1.4 => 1.5 ===
--- Products3/NewsSite/interfaces.py:1.4	Wed Mar 26 12:18:16 2003
+++ Products3/NewsSite/interfaces.py	Thu Mar 27 05:21:59 2003
@@ -15,11 +15,13 @@
 
 $Id$
 """
+__metaclass__ = type
 
 from zope.interface import Interface
 from zope.proxy.context import ContextProperty
 from zope.schema import TextLine, Password, Int, Datetime
 
+from zope.app.interfaces.dublincore import IZopeDublinCore
 from zope.app.interfaces.container import IContentContainer
 from zope.app.datetimeutils import parseDatetimetz
 
@@ -28,6 +30,13 @@
 #
 class INewsSite(IContentContainer):
 	"""Provides a marker interface for news site"""
+
+
+
+class INewsSiteAddForm(IZopeDublinCore):
+        """Schema for News Site AddForm."""
+
+
 
 #
 #   Registration interfaces