[CMF-checkins] SVN: CMF/trunk/CMF - getUseSession now returns a
boolean value
Yvo Schubbe
y.2006_ at wcm-solutions.de
Sun Apr 9 13:51:27 EDT 2006
Log message for revision 66745:
- getUseSession now returns a boolean value
- removed unused getNextDayLink and getPreviousDayLink
- replaced eventsForDay by listItemInfos (@decode doesn't work with brains, we have to create info dicts first)
- moved calendarBox methods from CMFDefault into a new calendar_box_view
- backported some changes from browser views to skin methods
- some related cleanup
Changed:
U CMF/trunk/CMFCalendar/CalendarTool.py
U CMF/trunk/CMFCalendar/browser/TODO.txt
U CMF/trunk/CMFCalendar/browser/calendar.py
U CMF/trunk/CMFCalendar/browser/configure.zcml
U CMF/trunk/CMFCalendar/browser/templates/calendar_day.pt
U CMF/trunk/CMFCalendar/browser/templates/calendar_widgets.pt
U CMF/trunk/CMFCalendar/skins/zpt_calendar/calendar_day_view_template.pt
U CMF/trunk/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py
D CMF/trunk/CMFCalendar/skins/zpt_calendar/getNextDayLink.py
D CMF/trunk/CMFCalendar/skins/zpt_calendar/getPreviousDayLink.py
U CMF/trunk/CMFDefault/browser/utils.py
-=-
Modified: CMF/trunk/CMFCalendar/CalendarTool.py
===================================================================
--- CMF/trunk/CMFCalendar/CalendarTool.py 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/CalendarTool.py 2006-04-09 17:51:27 UTC (rev 66745)
@@ -40,7 +40,7 @@
calendar_types = ('Event',)
calendar_states = ('published',)
- use_session = ''
+ use_session = False
firstweekday = 6 # 6 is Sunday
manage_options = ( ({ 'label' : 'Overview', 'action' : 'manage_overview' }
@@ -70,7 +70,7 @@
""" Change the configuration of the calendar tool
"""
self.calendar_types = tuple(show_types)
- self.use_session = use_session
+ self.use_session = bool(use_session)
if show_states is not None:
self.calendar_states = tuple(show_states)
@@ -118,7 +118,7 @@
def getUseSession(self):
""" Returns the Use_Session option
"""
- return self.use_session
+ return bool(self.use_session)
security.declarePublic('getDays')
def getDays(self):
Modified: CMF/trunk/CMFCalendar/browser/TODO.txt
===================================================================
--- CMF/trunk/CMFCalendar/browser/TODO.txt 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/browser/TODO.txt 2006-04-09 17:51:27 UTC (rev 66745)
@@ -8,18 +8,16 @@
CalendarView.previousDayURL
CalendarView.nextDayURL
[x] calendar_day_view_template.pt -> templates/calendar_day.pt
- [x] getEndAsString.py -> CalendarView.getEndAsString
- [x] getStartAsString.py -> CalendarView.getStartAsString
- [x] getNextDayLink.py -> CalendarView.getNextDayLink
- [x] getPreviousDayLink.py -> CalendarView.getPreviousDayLink
+ [x] getEndAsString.py -> CalendarView._getEndAsString
+ [x] getStartAsString.py -> CalendarView._getStartAsString
[x] @@calendar_widget:
[x] calendarBox.pt -> templates/calendar_widgets.pt
- [x] getDaysClass.py -> ViewBase.getDaysClass
- [x] getMonthAndYear.py -> ViewBase.getMonthAndYear
- [x] getNextMonthLink.py -> ViewBase.getNextMonthLink
- [x] getPreviousMonthLink.py -> ViewBase.getPreviousMonthLink
+ [x] getDaysClass.py -> CalendarBoxView.getDaysClass
+ [x] getMonthAndYear.py -> CalendarBoxView.getMonthAndYear
+ [x] getNextMonthLink.py -> CalendarBoxView.getNextMonthLink
+ [x] getPreviousMonthLink.py -> CalendarBoxView.getPreviousMonthLink
[x] IEvent @@view.html:
Modified: CMF/trunk/CMFCalendar/browser/calendar.py
===================================================================
--- CMF/trunk/CMFCalendar/browser/calendar.py 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/browser/calendar.py 2006-04-09 17:51:27 UTC (rev 66745)
@@ -15,13 +15,8 @@
$Id$
"""
-import urlparse
-
from DateTime.DateTime import DateTime
-from Products.CMFDefault.exceptions import ResourceLockedError
-from Products.CMFDefault.utils import Message as _
-
from Products.CMFDefault.browser.utils import decode
from Products.CMFDefault.browser.utils import memoize
from Products.CMFDefault.browser.utils import ViewBase
@@ -32,27 +27,27 @@
""" Helper class for calendar-related templates
"""
- @decode
- def getStartAsString(self, event_brain):
+ # helpers
+
+ def _getStartAsString(self, event_brain):
""" Retrieve formatted start string
"""
day = self.viewDay()
event_start = event_brain.getObject().start()
first_date = DateTime(day.Date()+" 00:00:00")
-
+
if event_start < first_date:
return event_start.aCommon()[:12]
else:
return event_start.TimeMinutes()
- @decode
- def getEndAsString(self, event_brain):
+ def _getEndAsString(self, event_brain):
""" Retrieve formatted end string
"""
day = self.viewDay()
event_end = event_brain.getObject().end()
last_date = DateTime(day.Date()+" 23:59:59")
-
+
if event_end > last_date:
return event_end.aCommon()[:12]
else:
@@ -66,18 +61,14 @@
return DateTime(date)
+ # interface
+
+ @memoize
def formattedDate(self):
""" Return a simple formatted date string
"""
return self.viewDay().aCommon()[:12]
- def eventsForDay(self):
- """ Get all event catalog records for a specific day
- """
- caltool = self._getTool('portal_calendar')
-
- return caltool.getEventsForThisDay(self.viewDay())
-
@memoize
def previousDayURL(self):
""" URL to the previous day's view
@@ -96,21 +87,102 @@
return '%s?date=%s' % (view_url, (day+1).Date())
+ @memoize
@decode
- def getNextDayLink(self, base_url):
- """ Return URL for the next day link
+ def listItemInfos(self):
+ """ List item infos for all event catalog records for a specific day.
"""
- day = self.viewDay()
- day += 1
-
- return '%s?date=%s' % (base_url, day.Date())
+ caltool = self._getTool('portal_calendar')
+ thisDay = self.viewDay()
- @decode
- def getPreviousDayLink(self, base_url):
- """ Return URL for the previous day link
+ items = [ {'title': item.Title,
+ 'url': item.getURL(),
+ 'start': self._getStartAsString(item),
+ 'stop': self._getEndAsString(item)}
+ for item in caltool.getEventsForThisDay(thisDay) ]
+
+ return tuple(items)
+
+
+class CalendarBoxView(ViewBase):
+
+ # calendarBox widget helpers
+
+ @memoize
+ def getMonthAndYear(self):
+ """ Retrieve month/year tuple
"""
- day = self.viewDay()
- day -= 1
-
- return '%s?date=%s' % (base_url, day.Date())
+ caltool = self._getTool('portal_calendar')
+ current = DateTime()
+ session = None
+ # First priority goes to the data in the request
+ year = self.request.get('year', None)
+ month = self.request.get('month', None)
+
+ # Next get the data from the SESSION
+ if caltool.getUseSession():
+ 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)
+
+ def getNextMonthLink(self, base_url, month, year):
+ """ Return URL for the next month link
+ """
+ caltool = self._getTool('portal_calendar')
+ nextMonthTime = caltool.getNextMonth(month, year)
+
+ x = '%s?month:int=%d&year:int=%d' % ( base_url
+ , nextMonthTime.month()
+ , nextMonthTime.year()
+ )
+
+ return x
+
+ def getPreviousMonthLink(self, base_url, month, year):
+ """ Return URL for the previous month link
+ """
+ caltool = self._getTool('portal_calendar')
+ prevMonthTime = caltool.getPreviousMonth(month, year)
+
+ x = '%s?month:int=%d&year:int=%d' % ( base_url
+ , prevMonthTime.month()
+ , prevMonthTime.year()
+ )
+
+ return x
+
+ 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 ''
Modified: CMF/trunk/CMFCalendar/browser/configure.zcml
===================================================================
--- CMF/trunk/CMFCalendar/browser/configure.zcml 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/browser/configure.zcml 2006-04-09 17:51:27 UTC (rev 66745)
@@ -33,10 +33,18 @@
<browser:page
for="*"
name="calendar_widget"
- class=".calendar.CalendarView"
+ class="Products.CMFDefault.browser.utils.MacroView"
template="templates/calendar_widgets.pt"
permission="zope2.View"
layer="cmf"
/>
+ <browser:page
+ for="*"
+ name="calendar_box_view"
+ class=".calendar.CalendarBoxView"
+ permission="zope2.View"
+ layer="cmf"
+ />
+
</configure>
Modified: CMF/trunk/CMFCalendar/browser/templates/calendar_day.pt
===================================================================
--- CMF/trunk/CMFCalendar/browser/templates/calendar_day.pt 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/browser/templates/calendar_day.pt 2006-04-09 17:51:27 UTC (rev 66745)
@@ -9,10 +9,8 @@
<body>
<metal:slot metal:fill-slot="body">
-
<div class="dayViewBox" metal:define-macro="dayViewBox">
-<table class="dayView" cellpadding="0" cellspacing="0" border="0"
- tal:define="events view/eventsForDay">
+<table class="dayView" cellpadding="0" cellspacing="0" border="0">
<tr>
<th>
<a href="#"
@@ -25,26 +23,23 @@
tal:attributes="href view/nextDayURL">»</a>
</th>
</tr>
- <tal:loop tal:repeat="item_info view/eventsForDay">
+ <tal:loop tal:repeat="item_info view/listItemInfos">
<tr>
<td class="heading" colspan="5" nowrap="nowrap">
- <a href="#" tal:attributes="href item_info/getURL"
- tal:content="item_info/Title">event title</a>
+ <a href="#" tal:attributes="href item_info/url"
+ tal:content="item_info/title">event title</a>
</td>
</tr>
<tr>
<td class="startDate" colspan="2" nowrap="nowrap"
- tal:content="python: view.getStartAsString(item_info)"
- >Event Start</td>
+ tal:content="item_info/start">Event Start</td>
<td nowrap="nowrap"> -- </td>
<td class="endDate" colspan="2" nowrap="nowrap"
- tal:content="python: view.getEndAsString(item_info)"
- >Event End</td>
+ tal:content="item_info/stop">Event End</td>
</tr>
</tal:loop>
</table>
</div>
-
</metal:slot>
</body>
Modified: CMF/trunk/CMFCalendar/browser/templates/calendar_widgets.pt
===================================================================
--- CMF/trunk/CMFCalendar/browser/templates/calendar_widgets.pt 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/browser/templates/calendar_widgets.pt 2006-04-09 17:51:27 UTC (rev 66745)
@@ -4,7 +4,8 @@
<metal:slot metal:fill-slot="body" i18n:domain="cmf_calendar">
<div metal:define-macro="calendarBox"
class="CalendarBox"
- tal:define="yearmonth view/getMonthAndYear;
+ tal:define="calendar_box_view context/@@calendar_box_view;
+ yearmonth calendar_box_view/getMonthAndYear;
year python:yearmonth[0];
month python:yearmonth[1];
weeks python:context.portal_calendar.getEventsForCalendar(month=month, year=year);">
@@ -22,7 +23,7 @@
<tr>
<th>
<a href="#" class="CalendarArrow"
- tal:attributes="href python:view.getPreviousMonthLink(request.URL0, month, year)">«</a>
+ tal:attributes="href python: calendar_box_view.getPreviousMonthLink(request.URL0, month, year)">«</a>
</th>
<th colspan="5" tal:define="date python:context.ZopeTime(int(year), int(month), 1)">
<tal:span tal:content="python:date.strftime('%B').capitalize()"
@@ -31,7 +32,7 @@
</th>
<th>
<a href="#" class="CalendarArrow"
- tal:attributes="href python:view.getNextMonthLink(request.URL0, month, year)">»</a>
+ tal:attributes="href python: calendar_box_view.getNextMonthLink(request.URL0, month, year)">»</a>
</th>
</tr>
@@ -49,7 +50,7 @@
><td class="event"
tal:define="daynumber day/day;
datestring python:'%d/%0.2d/%0.2d' % (year, month, daynumber);"
- tal:attributes="class python:view.getDaysClass(daynumber, month, year, day['event'])">
+ tal:attributes="class python: calendar_box_view.getDaysClass(daynumber, month, year, day['event'])">
<a href
tal:omit-tag="not: day/event"
tal:attributes="href string:${portal_url}/@@calendar_day.html?date=${datestring}"
Modified: CMF/trunk/CMFCalendar/skins/zpt_calendar/calendar_day_view_template.pt
===================================================================
--- CMF/trunk/CMFCalendar/skins/zpt_calendar/calendar_day_view_template.pt 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/skins/zpt_calendar/calendar_day_view_template.pt 2006-04-09 17:51:27 UTC (rev 66745)
@@ -1,4 +1,11 @@
<html metal:use-macro="context/main_template/macros/master">
+<head>
+
+<metal:slot fill-slot="base">
+<tal:span tal:replace="structure context/getBaseTag" />
+</metal:slot>
+
+</head>
<body>
<metal:slot metal:fill-slot="header"> </metal:slot>
@@ -29,7 +36,7 @@
<td class="endDate" colspan="2" nowrap="nowrap"
tal:content="item_info/stop">Event End</td>
</tr>
-</tal:loop>
+ </tal:loop>
</table>
</div>
</metal:slot>
Modified: CMF/trunk/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py
===================================================================
--- CMF/trunk/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/skins/zpt_calendar/getMonthAndYear.py 2006-04-09 17:51:27 UTC (rev 66745)
@@ -1,34 +1,35 @@
# Get the year and month that the calendar should display.
-import DateTime
+from Products.CMFCore.utils import getToolByName
-current = DateTime.DateTime()
+caltool = getToolByName(script, 'portal_calendar')
+current = DateTime()
+session = None
-year = None
-month = None
-use_session = container.portal_calendar.getUseSession()
-
# First priority goes to the data in the request
-year = context.REQUEST.get('year', None)
+year = context.REQUEST.get('year', None)
month = context.REQUEST.get('month', None)
-session = None
# Next get the data from the SESSION
-if use_session == "True":
+if caltool.getUseSession():
session = context.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()
+ 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)
-
+ session.set('calendar_year', year)
+ session.set('calendar_month', month)
+
# Finally return the results
return (year, month)
Deleted: CMF/trunk/CMFCalendar/skins/zpt_calendar/getNextDayLink.py
===================================================================
--- CMF/trunk/CMFCalendar/skins/zpt_calendar/getNextDayLink.py 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/skins/zpt_calendar/getNextDayLink.py 2006-04-09 17:51:27 UTC (rev 66745)
@@ -1,12 +0,0 @@
-##parameters=base_url, thisDay
-
-# Takes a base url and returns a link to the previous day
-
-thisDay += 1
-
-x = '%s?date=%s' % (
- base_url,
- thisDay.Date()
- )
-
-return x
\ No newline at end of file
Deleted: CMF/trunk/CMFCalendar/skins/zpt_calendar/getPreviousDayLink.py
===================================================================
--- CMF/trunk/CMFCalendar/skins/zpt_calendar/getPreviousDayLink.py 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFCalendar/skins/zpt_calendar/getPreviousDayLink.py 2006-04-09 17:51:27 UTC (rev 66745)
@@ -1,12 +0,0 @@
-##parameters=base_url, thisDay
-
-# Takes a base url and returns a link to the next day
-
-thisDay -= 1
-
-x = '%s?date=%s' % (
- base_url,
- thisDay.Date()
- )
-
-return x
\ No newline at end of file
Modified: CMF/trunk/CMFDefault/browser/utils.py
===================================================================
--- CMF/trunk/CMFDefault/browser/utils.py 2006-04-09 17:51:17 UTC (rev 66744)
+++ CMF/trunk/CMFDefault/browser/utils.py 2006-04-09 17:51:27 UTC (rev 66745)
@@ -18,12 +18,13 @@
from AccessControl.SecurityInfo import ClassSecurityInfo
from DateTime.DateTime import DateTime
from Globals import InitializeClass
+from Products.Five import BrowserView
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.permissions import View
from Products.CMFDefault.utils import html_marshal
from Products.CMFDefault.utils import Message as _
from Products.CMFDefault.utils import translate
@@ -46,16 +47,26 @@
return memoized_meth
-class ViewBase:
+class MacroView(BrowserView):
+ """Allows to use macros from non-view templates.
+ """
+
# 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)
+InitializeClass(MacroView)
+
+
+class ViewBase(BrowserView):
+
# helpers
@memoize
@@ -94,96 +105,6 @@
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 CMF-checkins
mailing list