[Checkins] SVN: CMF/trunk/CMF - forward-porting the CMFCalendar
Fiveification pieces to the trunk
Jens Vagelpohl
jens at dataflake.org
Mon Apr 3 16:48:00 EDT 2006
Log message for revision 66357:
- forward-porting the CMFCalendar Fiveification pieces to the trunk
Changed:
U CMF/trunk/CMFCalendar/CalendarTool.py
U CMF/trunk/CMFCalendar/Event.py
U CMF/trunk/CMFCalendar/__init__.py
A CMF/trunk/CMFCalendar/browser/
A CMF/trunk/CMFCalendar/configure.zcml
A CMF/trunk/CMFCalendar/interfaces/
A CMF/trunk/CMFCalendar/profiles/views_support/
U CMF/trunk/CMFCalendar/tests/test_Calendar.py
U CMF/trunk/CMFCalendar/tests/test_Event.py
U CMF/trunk/CMFDefault/browser/utils.py
-=-
Modified: CMF/trunk/CMFCalendar/CalendarTool.py
===================================================================
--- CMF/trunk/CMFCalendar/CalendarTool.py 2006-04-03 20:37:37 UTC (rev 66356)
+++ CMF/trunk/CMFCalendar/CalendarTool.py 2006-04-03 20:47:59 UTC (rev 66357)
@@ -22,10 +22,13 @@
from DateTime import DateTime
from Globals import InitializeClass
from OFS.SimpleItem import SimpleItem
+from zope.interface import implements
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.CMFCore.utils import UniqueObject
+from interfaces import ICalendarTool
+from interfaces.portal_calendar import portal_calendar as z2ICalendarTool
from permissions import ManagePortal
class CalendarTool (UniqueObject, SimpleItem):
@@ -34,6 +37,9 @@
meta_type= 'CMF Calendar Tool'
security = ClassSecurityInfo()
+ implements(ICalendarTool)
+ __implements__ = (z2ICalendarTool,)
+
calendar_types = ('Event',)
calendar_states = ('published',)
use_session = ''
Modified: CMF/trunk/CMFCalendar/Event.py
===================================================================
--- CMF/trunk/CMFCalendar/Event.py 2006-04-03 20:37:37 UTC (rev 66356)
+++ CMF/trunk/CMFCalendar/Event.py 2006-04-03 20:47:59 UTC (rev 66357)
@@ -19,6 +19,7 @@
from DateTime import DateTime
from Globals import InitializeClass
import transaction
+from zope.interface import implements
from Products.CMFCore.PortalContent import PortalContent
from Products.CMFCore.utils import contributorsplitter
@@ -31,40 +32,47 @@
from Products.CMFDefault.utils import parseHeadersBody
from Products.CMFDefault.utils import SimpleHTMLParser
+from Products.GenericSetup.interfaces import IDAVAware
+
from exceptions import ResourceLockedError
+from interfaces import IEvent
+from interfaces import IMutableEvent
+from interfaces.Event import IEvent as z2IEvent
+from interfaces.Event import IMutableEvent as z2IMutableEvent
from permissions import ChangeEvents
from permissions import ModifyPortalContent
from permissions import View
-def addEvent(self
- , id
- , title=''
- , description=''
- , effective_date = None
- , expiration_date = None
- , start_date = None
- , end_date = None
- , location=''
- , contact_name=''
- , contact_email=''
- , contact_phone=''
- , event_url=''
- , REQUEST=None):
+def addEvent( self
+ , id
+ , title=''
+ , description=''
+ , effective_date = None
+ , expiration_date = None
+ , start_date = None
+ , end_date = None
+ , location=''
+ , contact_name=''
+ , contact_email=''
+ , contact_phone=''
+ , event_url=''
+ , REQUEST=None
+ ):
"""Create an empty event.
"""
- event = Event(id
- , title
- , description
- , effective_date
- , expiration_date
- , start_date
- , end_date
- , location
- , contact_name
- , contact_email
- , contact_phone
- , event_url
+ event = Event( id
+ , title
+ , description
+ , effective_date
+ , expiration_date
+ , start_date
+ , end_date
+ , location
+ , contact_name
+ , contact_email
+ , contact_phone
+ , event_url
)
self._setObject(id, event)
@@ -95,23 +103,26 @@
security = ClassSecurityInfo()
security.declareObjectProtected(View)
- __implements__ = ( PortalContent.__implements__
+ implements(IMutableEvent, IEvent, IDAVAware)
+ __implements__ = ( z2IMutableEvent
+ , z2IEvent
+ , PortalContent.__implements__
, DefaultDublinCoreImpl.__implements__
)
- def __init__(self
- , id
- , title=''
- , description=''
- , effective_date = None
- , expiration_date = None
- , start_date = None
- , end_date = None
- , location=''
- , contact_name=''
- , contact_email=''
- , contact_phone=''
- , event_url=''
+ def __init__( self
+ , id
+ , title=''
+ , description=''
+ , effective_date = None
+ , expiration_date = None
+ , start_date = None
+ , end_date = None
+ , location=''
+ , contact_name=''
+ , contact_email=''
+ , contact_phone=''
+ , event_url=''
):
DefaultDublinCoreImpl.__init__(self)
self.id=id
@@ -147,36 +158,40 @@
security.declarePublic('getEndStrings')
def getEndStrings(self):
+ """ Returns a mapping with string representations for the end time
+
+ o keys are 'day', 'month' and 'year'
"""
- """
return _dateStrings(self.end())
security.declarePublic('getStartStrings')
def getStartStrings(self):
+ """ Returns a mapping with string representations for the start time
+
+ o keys are 'day', 'month' and 'year'
"""
- """
return _dateStrings(self.start())
security.declareProtected(ChangeEvents, 'edit')
- def edit(self
- , title=None
- , description=None
- , eventType=None
- , effectiveDay=None
- , effectiveMo=None
- , effectiveYear=None
- , expirationDay=None
- , expirationMo=None
- , expirationYear=None
- , start_time=None
- , startAMPM=None
- , stop_time=None
- , stopAMPM=None
- , location=None
- , contact_name=None
- , contact_email=None
- , contact_phone=None
- , event_url=None
+ def edit( self
+ , title=None
+ , description=None
+ , eventType=None
+ , effectiveDay=None
+ , effectiveMo=None
+ , effectiveYear=None
+ , expirationDay=None
+ , expirationMo=None
+ , expirationYear=None
+ , start_time=None
+ , startAMPM=None
+ , stop_time=None
+ , stopAMPM=None
+ , location=None
+ , contact_name=None
+ , contact_email=None
+ , contact_phone=None
+ , event_url=None
):
"""\
"""
@@ -262,46 +277,40 @@
security.declareProtected(ChangeEvents, 'setStartDate')
def setStartDate(self, start):
+ """ Setting the event start date when the event is scheduled to begin.
"""
- Setting the event start date, when the event is scheduled to begin.
- """
self.start_date = self._datify(start)
security.declareProtected(ChangeEvents, 'setEndDate')
def setEndDate(self, end):
+ """ Setting the event end date, when the event ends.
"""
- Setting the event end date, when the event ends.
- """
self.end_date = self._datify(end)
security.declarePublic('start')
def start(self):
+ """ Return our start time as a DateTime object
"""
- Return our start time as a string.
- """
date = getattr( self, 'start_date', None )
return date is None and self.created() or date
security.declarePublic('end')
def end(self):
+ """ Return our end time as a DateTime object
"""
- Return our stop time as a string.
- """
date = getattr( self, 'end_date', None )
return date is None and self.start() or date
security.declarePublic('getStartTimeString')
def getStartTimeString( self ):
+ """ Return our start time as a string.
"""
- Return our start time as a string.
- """
return self.start().AMPMMinutes()
security.declarePublic('getStopTimeString')
def getStopTimeString( self ):
+ """ Return our stop time as a string.
"""
- Return our stop time as a string.
- """
return self.end().AMPMMinutes()
security.declarePrivate('handleText')
@@ -324,6 +333,13 @@
security.declareProtected(ModifyPortalContent, 'setMetadata')
def setMetadata(self, headers):
+ """ Set an Event's metadata
+
+ o headers is a mapping containing keys corresponding to
+ Dublin Core metadata fields
+ o Only those attributes that are passed in with the mapping are
+ manipulated
+ """
headers['Format'] = self.Format()
new_subject = keywordsplitter(headers)
headers['Subject'] = new_subject or self.Subject()
@@ -346,7 +362,8 @@
security.declarePublic( 'getMetadataHeaders' )
def getMetadataHeaders(self):
- """Return RFC-822-style header spec."""
+ """ Return metadata attributes in RFC-822-style header spec.
+ """
hdrlist = DefaultDublinCoreImpl.getMetadataHeaders(self)
hdrlist.append( ('StartDate', self.start().strftime("%Y-%m-%d %H:%M:%S") ) )
hdrlist.append( ('EndDate', self.end().strftime("%Y-%m-%d %H:%M:%S") ) )
Modified: CMF/trunk/CMFCalendar/__init__.py
===================================================================
--- CMF/trunk/CMFCalendar/__init__.py 2006-04-03 20:37:37 UTC (rev 66356)
+++ CMF/trunk/CMFCalendar/__init__.py 2006-04-03 20:47:59 UTC (rev 66357)
@@ -64,3 +64,12 @@
EXTENSION,
for_=ISiteRoot,
)
+
+ profile_registry.registerProfile('views_support',
+ 'Experimental CMFCalendar Browser Views',
+ 'Hooks up the browser views.',
+ 'profiles/views_support',
+ 'CMFCalendar',
+ EXTENSION,
+ for_=ISiteRoot,
+ )
Copied: CMF/trunk/CMFCalendar/browser (from rev 66356, CMF/branches/2.0/CMFCalendar/browser)
Copied: CMF/trunk/CMFCalendar/configure.zcml (from rev 66356, CMF/branches/2.0/CMFCalendar/configure.zcml)
Copied: CMF/trunk/CMFCalendar/interfaces (from rev 66356, CMF/branches/2.0/CMFCalendar/interfaces)
Copied: CMF/trunk/CMFCalendar/profiles/views_support (from rev 66356, CMF/branches/2.0/CMFCalendar/profiles/views_support)
Modified: CMF/trunk/CMFCalendar/tests/test_Calendar.py
===================================================================
--- CMF/trunk/CMFCalendar/tests/test_Calendar.py 2006-04-03 20:37:37 UTC (rev 66356)
+++ CMF/trunk/CMFCalendar/tests/test_Calendar.py 2006-04-03 20:47:59 UTC (rev 66357)
@@ -40,6 +40,21 @@
return CalendarTool(*args, **kw)
+ def test_z2interfaces(self):
+ from Interface.Verify import verifyClass
+ from Products.CMFCalendar.interfaces.portal_calendar \
+ import portal_calendar as ICalendarTool
+ from Products.CMFCalendar.CalendarTool import CalendarTool
+
+ verifyClass(ICalendarTool, CalendarTool)
+
+ def test_z3interfaces(self):
+ from zope.interface.verify import verifyClass
+ from Products.CMFCalendar.interfaces import ICalendarTool
+ from Products.CMFCalendar.CalendarTool import CalendarTool
+
+ verifyClass(ICalendarTool, CalendarTool)
+
def test_new(self):
ctool = self._makeOne()
self.assertEqual( ctool.getId(), 'portal_calendar' )
@@ -113,20 +128,34 @@
params=(obj, Site.REQUEST)
obj(*params)
- def test_sessions(self):
+ def test_sessions_skinsview(self):
self.Tool.edit_configuration(show_types=['Event'], use_session="True")
self._testURL('/CalendarTest/calendarBox', ())
self.failUnless(self.app.REQUEST.SESSION.get('calendar_year',None))
- def test_noSessions(self):
+ def test_sessions_fiveview(self):
+ self.Tool.edit_configuration(show_types=['Event'], use_session="True")
+
+ self._testURL('/CalendarTest/@@calendar_widget', ())
+
+ self.failUnless(self.app.REQUEST.SESSION.get('calendar_year',None))
+
+ def test_noSessions_skinsview(self):
self.Tool.edit_configuration(show_types=['Event'], use_session="")
self._testURL('/CalendarTest/calendarBox', ())
self.failIf(self.app.REQUEST.SESSION.get('calendar_year',None))
+ def test_noSessions_fiveview(self):
+ self.Tool.edit_configuration(show_types=['Event'], use_session="")
+
+ self._testURL('/CalendarTest/@@calendar_widget', ())
+
+ self.failIf(self.app.REQUEST.SESSION.get('calendar_year',None))
+
def test_simpleCalendarRendering(self):
data = [
[
Modified: CMF/trunk/CMFCalendar/tests/test_Event.py
===================================================================
--- CMF/trunk/CMFCalendar/tests/test_Event.py 2006-04-03 20:37:37 UTC (rev 66356)
+++ CMF/trunk/CMFCalendar/tests/test_Event.py 2006-04-03 20:47:59 UTC (rev 66357)
@@ -43,12 +43,16 @@
from Products.CMFCore.interfaces.Dynamic \
import DynamicType as IDynamicType
from Products.CMFCalendar.Event import Event
+ from Products.CMFCalendar.interfaces.Event import IEvent
+ from Products.CMFCalendar.interfaces.Event import IMutableEvent
verifyClass(ICatalogableDublinCore, Event)
verifyClass(IContentish, Event)
verifyClass(IDublinCore, Event)
verifyClass(IDynamicType, Event)
verifyClass(IMutableDublinCore, Event)
+ verifyClass(IEvent, Event)
+ verifyClass(IMutableEvent, Event)
def test_z3interfaces(self):
from zope.interface.verify import verifyClass
@@ -58,12 +62,16 @@
from Products.CMFCore.interfaces import IDublinCore
from Products.CMFCore.interfaces import IDynamicType
from Products.CMFCore.interfaces import IMutableDublinCore
+ from Products.CMFCalendar.interfaces import IEvent
+ from Products.CMFCalendar.interfaces import IMutableEvent
verifyClass(ICatalogableDublinCore, Event)
verifyClass(IContentish, Event)
verifyClass(IDublinCore, Event)
verifyClass(IDynamicType, Event)
verifyClass(IMutableDublinCore, Event)
+ verifyClass(IEvent, Event)
+ verifyClass(IMutableEvent, Event)
def test_new(self):
event = self._makeOne('test')
Modified: CMF/trunk/CMFDefault/browser/utils.py
===================================================================
--- CMF/trunk/CMFDefault/browser/utils.py 2006-04-03 20:37:37 UTC (rev 66356)
+++ CMF/trunk/CMFDefault/browser/utils.py 2006-04-03 20:47:59 UTC (rev 66357)
@@ -15,10 +15,14 @@
$Id$
"""
+from AccessControl.SecurityInfo import ClassSecurityInfo
+from DateTime.DateTime import DateTime
+from Globals import InitializeClass
from Products.PythonScripts.standard import thousands_commas
from ZTUtils import Batch
from ZTUtils import make_query
+from Products.CMFCore.permissions import View
from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.utils import html_marshal
from Products.CMFDefault.utils import Message as _
@@ -44,6 +48,14 @@
class ViewBase:
+ # The following allows to traverse the view/class and reach
+ # macros defined in page templates, e.g. in a use-macro.
+ security = ClassSecurityInfo()
+ def _macros(self):
+ return self.index.macros
+ security.declareProtected(View, 'macros')
+ macros = property(_macros, None, None)
+
# helpers
@memoize
@@ -82,6 +94,96 @@
return self.context.Description()
+ # Calendar widgets helpers
+ # When CMFCalendar is enabled, the month calendar widget shows up
+ # everywhere - that's why these methods are currently here.
+
+ @memoize
+ @decode
+ def getMonthAndYear(self):
+ """ Retrieve month/year tuple
+ """
+ current = DateTime()
+
+ year = None
+ month = None
+ use_session = self._getTool('portal_calendar').getUseSession()
+
+ # First priority goes to the data in the request
+ year = self.request.get('year', None)
+ month = self.request.get('month', None)
+ session = None
+
+ # Next get the data from the SESSION
+ if use_session == "True":
+ session = self.request.get('SESSION', None)
+ if session:
+ if not year: year = session.get('calendar_year', None)
+ if not month: month = session.get('calendar_month', None)
+
+ # Last resort to Today
+ if not year: year = current.year()
+ if not month: month = current.month()
+
+ # Then store the results in the session for next time
+ if session:
+ session.set('calendar_year', year)
+ session.set('calendar_month', month)
+
+ # Finally return the results
+ return (year, month)
+
+ @memoize
+ @decode
+ def getNextMonthLink(self, base_url, month, year):
+ """ Return URL for the next month link
+ """
+ calendar_tool = self._getTool('portal_calendar')
+ nextMonthTime = calendar_tool.getNextMonth(month, year)
+
+ x = '%s?month:int=%d&year:int=%d' % ( base_url
+ , nextMonthTime.month()
+ , nextMonthTime.year()
+ )
+
+ return x
+
+ @memoize
+ @decode
+ def getPreviousMonthLink(self, base_url, month, year):
+ """ Return URL for the previous month link
+ """
+ calendar_tool = self._getTool('portal_calendar')
+ prevMonthTime = calendar_tool.getPreviousMonth(month, year)
+
+ x = '%s?month:int=%d&year:int=%d' % ( base_url
+ , prevMonthTime.month()
+ , prevMonthTime.year()
+ )
+
+ return x
+
+ @memoize
+ def getDaysClass(self, day, month, year, event=None):
+ """ Determine the CSS class to use for the given day
+ """
+ current = DateTime()
+
+ if ( current.year()==year and
+ current.month()==month and
+ current.day()==int(day) ):
+ if event:
+ return "todayevent"
+ else:
+ return "todaynoevent"
+
+ if event:
+ return "event"
+ else:
+ return ""
+
+InitializeClass(ViewBase)
+
class FormViewBase(ViewBase):
# helpers
More information about the Checkins
mailing list