[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/ Portal syndication form.

Charlie Clark charlie at begeistert.org
Wed Sep 29 09:06:24 EDT 2010


Log message for revision 117061:
  Portal syndication form.

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/configure.zcml
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/configure.zcml
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/configure.zcml	2010-09-29 12:24:51 UTC (rev 117060)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/configure.zcml	2010-09-29 13:06:24 UTC (rev 117061)
@@ -3,11 +3,19 @@
     xmlns:browser="http://namespaces.zope.org/browser">
 
     <browser:page
-      for="Products.CMFCore.interfaces.ISiteRoot"
-      layer="Products.CMFDefault.interfaces.ICMFDefaultSkin"
-      name="configure.html"
-      class=".config.PortalConfig"
-      permission="cmf.ManagePortal"
+        for="Products.CMFCore.interfaces.ISiteRoot"
+        layer="Products.CMFDefault.interfaces.ICMFDefaultSkin"
+        name="configure.html"
+        class=".config.PortalConfig"
+        permission="cmf.ManagePortal"
       />
+      
+    <browser:page
+        for="Products.CMFCore.interfaces.ISiteRoot"
+        layer="Products.CMFDefault.interfaces.ICMFDefaultSkin"
+        name="syndication.html"
+        class=".syndication.Manage"
+        permission="cmf.ManagePortal"
+    />
 
 </configure>

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py	2010-09-29 13:06:24 UTC (rev 117061)
@@ -0,0 +1,129 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Enable or disable site syndication"""
+
+import logging
+LOG = logging.getLogger("Syndication settings")
+
+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.CMFDefault.formlib.form import EditFormBase
+from Products.CMFDefault.utils import Message as _
+from Products.CMFDefault.browser.utils import memoize
+
+
+frequency_vocab = SimpleVocabulary.fromItems(
+                            [
+                             (_(u'Hourly'), 'hourly'),
+                             (_(u'Daily'), 'daily'),
+                             (_(u'Weekly'), 'weekly'),
+                             (_(u'Monthly'), 'monthly'),
+                             (_(u'Yearly'), 'yearly',)
+                            ]
+                              )
+
+
+class ISyndication(Interface):
+    """Syndication form schema"""
+    
+    period = Choice(
+                    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 update frequency of '3' and an update period of 'Monthly' will mean an update every 3 three months.")
+                )
+
+    base = Datetime(
+                title=_(u"Update base"),
+                description=_(u"")
+                )
+    
+    max_items = Int(
+                title=_(u"Maximum number of items"),
+                description=_(u"")
+                )
+
+class Manage(EditFormBase):
+    
+    form_fields = form.FormFields(ISyndication)
+    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"
+                    )
+                )
+    
+    @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):
+        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)
+    
+    def handle_enable(self, action, data):
+        self.handle_update(action, data)
+        self.syndtool.isAllowed = 1
+        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=str(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.status = _(u"Syndication disabled")
+        self._setRedirect("portal_actions", "global/syndication")
\ No newline at end of file


Property changes on: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/syndication.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py	2010-09-29 13:06:24 UTC (rev 117061)
@@ -0,0 +1,114 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Tests for portal syndication form"""
+
+import unittest
+
+from zope.interface import alsoProvides
+from zope.i18n.interfaces import IUserPreferredCharsets
+from zope.publisher.browser import TestRequest
+
+from Products.CMFCore.tests.base.dummy import DummySite, DummyTool
+
+
+class DummySyndicationTool(object):
+    
+    isAllowed = 0
+    updatePeriod = "daily"
+    updateFrequency = 1
+    updateBase = ""
+    max_items = 15
+    
+    def editProperties(self, **kw):
+        for k, v in kw.items():
+            setattr(self, k, v)
+
+
+class DummyResponse(object):
+
+    def redirect(self, value):
+        self.location = value
+
+
+class DummyRequest(TestRequest):
+    
+    
+    def __init__(self, **kw):
+        super(DummyRequest, self).__init__(kw)
+        self.RESPONSE = DummyResponse()
+    
+    def getPreferredCharsets(self):
+        return ['utf-8']
+
+
+class SyndicationViewTests(unittest.TestCase):
+
+    def setUp(self):
+        """Setup a site"""
+        self.site = site = DummySite('site')
+        site.portal_syndication = DummySyndicationTool()
+        site._setObject('portal_actions', DummyTool())
+        site._setObject('portal_url', DummyTool())
+        site._setObject('portal_membership', DummyTool())
+        
+    def _getTargetClass(self):
+        from Products.CMFDefault.browser.admin.syndication import Manage
+        request = DummyRequest(ACTUAL_URL="http://example.com")
+        alsoProvides(request, IUserPreferredCharsets)
+        return Manage(self.site, request)
+    
+    def test_enabled(self):
+        view = self._getTargetClass()
+        self.assertFalse(view.enabled())
+        
+    def test_disabled(self):
+        view = self._getTargetClass()
+        self.assertTrue(view.disabled())
+        
+    def test_handle_enable(self):
+        view = self._getTargetClass()
+        data = {'frequency':3, 'period':'weekly', 'base':'', 'max_items':10}
+        view.handle_enable("enable", data)
+        self.assertTrue(view.enabled())
+        self.assertTrue(view.status == u"Syndication enabled")
+        self.assertTrue(view.request.RESPONSE.location == "http://www.foobar.com/bar/site?portal_status_message=Syndication%20enabled")
+
+    def test_handle_update(self):
+        view = self._getTargetClass()
+        self.assertTrue(view.syndtool.updatePeriod == 'daily')
+        self.assertTrue(view.syndtool.updateFrequency == 1)
+        self.assertTrue(view.syndtool.updateBase == "")
+        self.assertTrue(view.syndtool.max_items == 15)
+        data = {'frequency':3, 'period':'weekly', 'base':'active',
+                'max_items':10}
+        view.handle_update("update", data)
+        self.assertTrue(view.syndtool.updatePeriod == 'weekly')
+        self.assertTrue(view.syndtool.updateFrequency == 3)
+        self.assertTrue(view.syndtool.updateBase == "active")
+        self.assertTrue(view.syndtool.max_items == 10)
+        self.assertTrue(view.status == u"Syndication updated")
+        self.assertTrue(view.request.RESPONSE.location == "http://www.foobar.com/bar/site?portal_status_message=Syndication%20updated")
+        
+    def test_handle_disable(self):
+        view = self._getTargetClass()
+        view.syndtool.isAllowed = True
+        self.assertTrue(view.enabled)
+        view.handle_disable("disable", {})
+        self.assertTrue(view.disabled)
+        self.assertTrue(view.status == u"Syndication disabled")
+        self.assertTrue(view.request.RESPONSE.location == "http://www.foobar.com/bar/site?portal_status_message=Syndication%20disabled")
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(SyndicationViewTests))
+    return suite
\ No newline at end of file


Property changes on: Products.CMFDefault/trunk/Products/CMFDefault/browser/admin/tests/test_syndication.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the checkins mailing list