Back to index

plone3  3.1.7
getMonthAndYear.py
Go to the documentation of this file.
00001 
00002 # Get the year and month that the calendar should display.
00003 
00004 from Products.CMFCore.utils import getToolByName
00005 
00006 caltool = getToolByName(script, 'portal_calendar')
00007 current = DateTime()
00008 session = None
00009 
00010 # First priority goes to the data in the request
00011 year = context.REQUEST.get('year', None)
00012 month = context.REQUEST.get('month', None)
00013 
00014 # Next get the data from the SESSION
00015 if caltool.getUseSession():
00016     session = context.REQUEST.get('SESSION', None)
00017     if session:
00018         if not year:
00019             year = session.get('calendar_year', None)
00020         if not month:
00021             month = session.get('calendar_month', None)
00022 
00023 # Last resort to today
00024 if not year:
00025     year = current.year()
00026 if not month:
00027     month = current.month()
00028 
00029 # Then store the results in the session for next time
00030 if session:
00031     session.set('calendar_year', year)
00032     session.set('calendar_month', month)
00033 
00034 # Finally return the results
00035 return (year, month)