Commits

Ales Zabala Alava committed 976eeb4

new portlet parameter: month_walk. Can be used to display calendar dates in the future or past

Comments (0)

Files changed (1)

collective/portlet/calendar/calendar.py

                      value_type=schema.TextLine()
                      )
 
+    month_walk = schema.Int(title=_(u"Month walk"),
+                     description=_('help_month_walk',
+                                   default=u"How many months in the future will the calendar be set. "
+                                            "Use negative numbers to set months in the past. For example, "
+                                            "Setting this value to 1 displays next months calendar."),
+                     default=0
+                     )
+
 class Assignment(base.Assignment):
     implements(ICalendarExPortlet)
     
     root = None
     review_state = ()
     kw = []
+    month_walk = 0
     
-    def __init__(self, name='' ,root=None, review_state=(), kw=[]):
+    def __init__(self, name='' ,root=None, review_state=(), kw=[], month_walk=0):
         self.title = name or _(u'Calendar Extended')
         self.name = name
         self.root = root
         self.review_state = review_state
         self.kw = kw
+        self.month_walk = month_walk
     
 class Renderer(base.Renderer):
     _template = ViewPageTemplateFile('calendar.pt')
         ''' Show title only if user informed a title in the Assignment form
         '''
         name = self.name
-        name.strip()
+        if name is not None:
+            name.strip()
         return name and True or False
     
     @property
         states = self.data.review_state or self.calendar.getCalendarStates()
         return ''.join(map(lambda x : 'review_state=%s&' % self.url_quote_plus(x), states))
 
+    def getYearAndMonthToDisplay(self):
+        year, month = super(Renderer, self).getYearAndMonthToDisplay()
+        month += self.data.month_walk
+        #Normalize months to stay between 1 and 12
+        while month < 1:
+            year -= 1
+            month += 12
+        while month > 12:
+            year += 1
+            month -= 12
+        self.year = year
+        self.month = month
+        # Store the results in the session for next time
+        session = self.request.get('SESSION', None)
+        if session:
+            session.set('calendar_year', year)
+            session.set('calendar_month', month)
+        return year, month
+
 class AddForm(base_portlet.AddForm):
     form_fields = form.Fields(ICalendarExPortlet)
     form_fields['root'].custom_widget = UberSelectionWidget