[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/ Added check for site syndication

Charlie Clark charlie at begeistert.org
Wed Oct 6 08:33:41 EDT 2010


Log message for revision 117289:
  Added check for site syndication

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/TODO.txt
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.pt
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/TODO.txt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/TODO.txt	2010-10-06 12:33:26 UTC (rev 117288)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/TODO.txt	2010-10-06 12:33:41 UTC (rev 117289)
@@ -4,5 +4,22 @@
 Portal configuration
 ====================
 
-reconfig_form.py ->
-reconfig_template.pt
\ No newline at end of file
+ [X] ISiteRoot @@configure.html
+ 
+     reconfig_form.py
+     reconfig_template-> config.Site
+     
+Portal syndication
+==================
+     
+ [X] ISiteRoot @@syndication.html
+ 
+     SyndicationTool properties form -> syndication.Site
+     
+ [X] IFolderish @@syndicate.html
+ 
+     synPropertiesForm.py
+     disableSyndication.py
+     enableSyndication.py
+     synPropertiesForm_template.pt -> syndication.Syndicate    
+      
\ No newline at end of file

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.pt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.pt	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.pt	2010-10-06 12:33:41 UTC (rev 117289)
@@ -0,0 +1,39 @@
+<html metal:use-macro="context/@@standard_macros/page">
+
+<body>
+
+<metal:slot metal:fill-slot="body" i18n:domain="cmf_default">
+
+<ul class="errors" tal:condition="view/errors">
+ <li tal:repeat="error view/error_views"
+     tal:content="structure error">Error Message</li>
+</ul>
+
+<h1 i18n:translate="">Folder Syndication</h1>
+
+<p class="errors" tal:condition="not: view/allowed"
+                  i18n:translate="">Portal syndication is currently disabled</p>
+
+<form action="." method="post"
+      tal:condition="view/allowed"
+      tal:attributes="action request/ACTUAL_URL">
+
+    <fieldset tal:repeat="widget view/widgets">
+      <label tal:attributes="for widget/name" tal:content="widget/label"></label>
+      <tal:block replace="structure widget" />
+      <legend tal:content="widget/hint"></legend>
+      <tal:block condition="widget/error"
+          replace="structure widget/error" />
+    </fieldset>
+
+  <div class="buttons">
+    <tal:loop tal:repeat="action view/actions"
+     tal:replace="structure action/render" />
+  </div>
+
+</form>
+
+</metal:slot>
+
+</body>
+</html>

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py	2010-10-06 12:33:26 UTC (rev 117288)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py	2010-10-06 12:33:41 UTC (rev 117289)
@@ -10,15 +10,16 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Syndication configuration views"""
 
-"""Enable or disable site syndication"""
-
 from zope.component import getAdapter
 from zope.interface import Interface
 from zope.formlib import form
 from zope.schema import Choice, Int, Datetime
 from zope.schema.vocabulary import SimpleVocabulary
 
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+
 from Products.CMFCore.interfaces import ISyndicationInfo
 from Products.CMFDefault.formlib.form import EditFormBase
 from Products.CMFDefault.utils import Message as _
@@ -26,106 +27,108 @@
 
 
 frequency_vocab = SimpleVocabulary.fromItems(
-                            [(_(u'Hourly'), 'hourly'),
-                             (_(u'Daily'), 'daily'),
-                             (_(u'Weekly'), 'weekly'),
-                             (_(u'Monthly'), 'monthly'),
-                             (_(u'Yearly'), 'yearly')
-                            ])
+    [(_(u'Hourly'), 'hourly'),
+     (_(u'Daily'), 'daily'),
+     (_(u'Weekly'), 'weekly'),
+     (_(u'Monthly'), 'monthly'),
+     (_(u'Yearly'), 'yearly')
+     ])
 
 
 class ISyndicationSchema(Interface):
     """Syndication form schema"""
-    
+
     period = Choice(
-                    title=_(u"Update period"),
-                    vocabulary=frequency_vocab,
-                    default="daily"
-                    )
-    
+        title=_(u"Update period"),
+        vocabulary=frequency_vocab,
+        default="daily"
+    )
+
     frequency = Int(
-                title=_(u"Update frequency"),
-                description=_(u"This is a multiple of the update period. An"
-                    u" update frequency of '3' and an update period"
-                    u" of 'Monthly' will mean an update every three months.")
-                    )
-    
+        title=_(u"Update frequency"),
+        description=_(u"This is a multiple of the update period. An"
+                      u" update frequency of '3' and an update period"
+                      u" of 'Monthly' will mean an update every three months.")
+    )
+
     base = Datetime(
-                title=_(u"Update base"),
-                description=_(u"")
-                )
-    
+        title=_(u"Update base"),
+        description=_(u"")
+    )
+
     max_items = Int(
-                title=_(u"Maximum number of items"),
-                description=_(u"")
-                )
+        title=_(u"Maximum number of items"),
+        description=_(u"")
+    )
 
 class Site(EditFormBase):
     """Enable or disable syndication for a site."""
-    
-    
+
+
     form_fields = form.FormFields(ISyndicationSchema)
     actions = form.Actions(
-                form.Action(
-                    name="enable",
-                    label=_(u"Enable syndication"),
-                    condition="disabled",
-                    success="handle_enable",
-                    ),
-                form.Action(
-                    name="update",
-                    label=_(u"Update syndication"),
-                    condition="enabled",
-                    success="handle_update",
-                    ),
-                form.Action(
-                    name="disable",
-                    label=_(u"Disable syndication"),
-                    condition="enabled",
-                    success="handle_disable"
-                    )
-                )
-    
+        form.Action(
+            name="enable",
+            label=_(u"Enable syndication"),
+            condition="disabled",
+            success="handle_enable",
+            ),
+        form.Action(
+            name="update",
+            label=_(u"Update syndication"),
+            condition="enabled",
+            success="handle_update",
+            ),
+        form.Action(
+            name="disable",
+            label=_(u"Disable syndication"),
+            condition="enabled",
+            success="handle_disable"
+        )
+    )
+
     @property
     @memoize
     def syndtool(self):
         return self._getTool("portal_syndication")
-    
+
     @memoize
     def enabled(self, action=None):
         return self.syndtool.isAllowed
-    
+
     @memoize
     def disabled(self, action=None):
         return not self.syndtool.isAllowed
-    
+
     def setUpWidgets(self, ignore_request=False):
+        fields = self.form_fields
+        if self.disabled():
+            fields = form.FormFields()
         data = {'frequency':self.syndtool.syUpdateFrequency,
                 'period':self.syndtool.syUpdatePeriod,
                 'base':self.syndtool.syUpdateBase,
                 'max_items':self.syndtool.max_items
-               }
-        self.widgets = form.setUpDataWidgets(self.form_fields, self.prefix,
-                       self.context, self.request,data=data,
-                       ignore_request=ignore_request)
-    
+                }
+        self.widgets = form.setUpDataWidgets(fields, self.prefix,
+                                             self.context, self.request,data=data,
+                                             ignore_request=ignore_request)
+
     def handle_enable(self, action, data):
-        self.handle_update(action, data)
-        self.syndtool.isAllowed = 1
+        self.syndtool.isAllowed = True
         self.status = _(u"Syndication enabled")
         self._setRedirect("portal_actions", "global/syndication")
-    
+
     def handle_update(self, action, data):
         self.syndtool.editProperties(updatePeriod=data['period'],
-                                    updateFrequency=data['frequency'],
-                                    updateBase=data['base'],
-                                    max_items=data['max_items']
-                                    )
+                                     updateFrequency=data['frequency'],
+                                     updateBase=data['base'],
+                                     max_items=data['max_items']
+                                     )
         self.status = _(u"Syndication updated")
         self._setRedirect("portal_actions", "global/syndication")
-    
+
     def handle_disable(self, action, data):
-        self.syndtool.isAllowed = 0
+        self.syndtool.isAllowed = False
         self.status = _(u"Syndication disabled")
         self._setRedirect("portal_actions", "global/syndication")
 
@@ -134,77 +137,80 @@
     """
     Enable, disable and customise syndication settings for a folder
     """
-    
+
     form_fields = form.FormFields(ISyndicationSchema)
-    
+    template = ViewPageTemplateFile("syndication.pt")
+
     actions = form.Actions(
-                form.Action(
-                    name="enable",
-                    label=_(u"Enable syndication"),
-                    condition="disabled",
-                    success="handle_enable",
-                    ),
-                form.Action(
-                    name="update",
-                    label=_(u"Update syndication"),
-                    condition="enabled",
-                    success="handle_update",
-                    ),
-                form.Action(
-                    name="revert",
-                    label=_(u"Revert to site default"),
-                    condition="enabled",
-                    success="handle_revert",
-                    ),
-                form.Action(
-                    name="disable",
-                    label=_(u"Disable syndication"),
-                    condition="enabled",
-                    success="handle_disable",
-                    validator="validation_disabled"
-                    )
-                )
-    
+        form.Action(
+            name="enable",
+            label=_(u"Enable syndication"),
+            condition="disabled",
+            success="handle_enable",
+            ),
+        form.Action(
+            name="update",
+            label=_(u"Update syndication"),
+            condition="enabled",
+            success="handle_update",
+            ),
+        form.Action(
+            name="revert",
+            label=_(u"Revert to site default"),
+            condition="enabled",
+            success="handle_revert",
+            ),
+        form.Action(
+            name="disable",
+            label=_(u"Disable syndication"),
+            condition="enabled",
+            success="handle_disable",
+        )
+    )
+
     @property
     @memoize
     def adapter(self):
         return getAdapter(self.context, ISyndicationInfo)
-    
+
     def setUpWidgets(self, ignore_request=False):
         fields = self.form_fields
         if self.disabled():
             fields = form.FormFields()
         self.widgets = form.setUpDataWidgets(fields, self.prefix,
-                       self.context, self.request,
-                       data=self.adapter.get_info(),
-                       ignore_request=ignore_request)
-    
+                            self.context, self.request,
+                            data=self.adapter.get_info(),
+                            ignore_request=ignore_request)
+
+    @memoize
     def enabled(self, action=None):
         return self.adapter.enabled
-    
+
+    @memoize
     def disabled(self, action=None):
         return not self.adapter.enabled
-    
-    def validation_disabled(self, action, data):
-        """Do nothing, data is irrelevant"""
-        pass
-    
+
+    @memoize
+    def allowed(self):
+        syndtool = self._getTool('portal_syndication')
+        return syndtool.isSiteSyndicationAllowed()
+
     def handle_enable(self, action, data):
         self.adapter.enable()
         self.status = _(u"Syndication enabled")
         self._setRedirect("portal_actions", "folder/syndication")
-    
+
     def handle_disable(self, action, data):
         self.adapter.disable()
         self.status = _(u"Syndication disabled")
         self._setRedirect("portal_actions", "folder/syndication")
-    
+
     def handle_update(self, action, data):
         self.adapter.set_info(**data)
         self.status = _(u"Syndication updated")
         self._setRedirect("portal_actions", "folder/syndication")
-    
+
     def handle_revert(self, action, data):
         self.adapter.revert()
         self.status = _(u"Syndication reset to site default")
-        self._setRedirect("portal_actions", "folder/syndication")
\ No newline at end of file
+        self._setRedirect("portal_actions", "folder/syndication")

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py	2010-10-06 12:33:26 UTC (rev 117288)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py	2010-10-06 12:33:41 UTC (rev 117289)
@@ -23,7 +23,7 @@
 
 class DummySyndicationTool(object):
 
-    isAllowed = 0
+    isAllowed = False
     syUpdatePeriod = updatePeriod = "daily"
     syUpdateFrequency = updateFrequency = 1
     syUpdateBase = updateBase = ""
@@ -33,7 +33,10 @@
         for k, v in kw.items():
             setattr(self, k, v)
 
+    def isSiteSyndicationAllowed(self):
+        return self.isAllowed
 
+
 class DummyResponse(object):
 
     def redirect(self, value):
@@ -140,6 +143,10 @@
         alsoProvides(request, IUserPreferredCharsets)
         return Syndicate(self.site, request)
 
+    def test_allowed(self):
+        view = self._getTargetClass()
+        self.assertFalse(view.allowed())
+
     def test_adapter(self):
         from Products.CMFCore.interfaces import ISyndicationInfo
         view = self._getTargetClass()



More information about the checkins mailing list