changeset 250:2e507e256726

added filtering by category (including substring) to project calendar display.
author casties
date Fri, 25 Apr 2014 15:30:43 +0200
parents f07dc0d2c60c
children 4742e71606e4
files MPIWGProjects.py zpt/project/edit_calendar.zpt zpt/project/project_index_html.zpt
diffstat 3 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGProjects.py	Wed Apr 23 16:53:10 2014 +0200
+++ b/MPIWGProjects.py	Fri Apr 25 15:30:43 2014 +0200
@@ -662,7 +662,7 @@
         return self.get('calendar', None)    
 
 
-    def editProjectCalendar(self, url=None, only_upcoming=None, show_num=None, RESPONSE=None):
+    def editProjectCalendar(self, url=None, only_upcoming=None, show_num=None, cat_match=None, RESPONSE=None):
         """Change the project calendar."""
         cal = self.get('calendar', None)
         if url:
@@ -683,6 +683,11 @@
             cal.setFlag('only_upcoming', (only_upcoming == 'yes'))
             # number of events
             cal.setFlag('show_num', getInt(show_num, 5))
+            # match (project number) in event category
+            if cat_match:
+                cal.setFlag('cat_match', unicode(cat_match))
+            else:
+                cal.setFlag('cat_match', None)
             
         elif cal is not None:
             # no url - remove calendar
@@ -694,20 +699,26 @@
             
 
 
-    def getProjectNumberMatcher(self, s):
-        """Return a function that matches a project number.
+    def getProjectNumberMatcher(self, num, getter=None):
+        """Return a function that matches a project number pattern.
         
-        Matches exactly except when s ends with '*'.
+        Matches exactly except when num ends with '*'. Uses function getter on arguments.
         """
-        if s is None:
+        if num is None:
             return None
         
-        if s.endswith('*'):
-            rs = re.sub(r'\.', r'\.', s[:-1]) + r'\b'
-            return lambda x : re.match(rs, x)
+        if num.endswith('*'):
+            rs = re.sub(r'\.', r'\.', num[:-1]) + r'\b'
+            if getter is None:
+                return lambda x : re.match(rs, x)            
+            else:
+                return lambda x : re.match(rs, getter(x))
         
         else:
-            return lambda x : s == x
+            if getter is None:
+                return lambda x : num == x
+            else:
+                return lambda x : num == getter(x)
 
               
     def _moveObjectPlace(self, objectList, objectId, direction):
--- a/zpt/project/edit_calendar.zpt	Wed Apr 23 16:53:10 2014 +0200
+++ b/zpt/project/edit_calendar.zpt	Fri Apr 25 15:30:43 2014 +0200
@@ -25,6 +25,12 @@
       <p tal:condition="cal">
         Number of events to show: <input name="show_num" size="2" tal:attributes="value python:cal.getFlag('show_num', 5)" />
       </p>
+      <p tal:condition="cal">
+        Show only events matching category: <input name="cat_match" size="5" tal:attributes="value python:cal.getFlag('cat_match')" /><br/>
+        If all events have the project number as their category "3.1" would show only events of project 3.1 while "3*" would
+        show all events of project 3 and all of its subprojects.<br/>
+        Leave empty to show all events in the calendar.
+      </p>
       <p>
         <input type="submit" value="submit" />
       </p>
--- a/zpt/project/project_index_html.zpt	Wed Apr 23 16:53:10 2014 +0200
+++ b/zpt/project/project_index_html.zpt	Fri Apr 25 15:30:43 2014 +0200
@@ -180,8 +180,9 @@
     <!-- project calendar -->
     <div class="sideblock" tal:define="calendar here/getProjectCalendar" tal:condition="calendar">
       <tal:block tal:define="upcoming python:calendar.getFlag('only_upcoming', False);
-        show_num python:calendar.getFlag('show_num', 2);
-        events python:test(upcoming, calendar.getAllItemsFromTodayOn()[:show_num], calendar.getNext(show_num, reverse=False))" 
+        show_num python:calendar.getFlag('show_num', 2); cat_match python:calendar.getFlag('cat_match');
+        filter python:here.getProjectNumberMatcher(cat_match, lambda x:unicode(x.getValue('categories')));
+        events python:test(upcoming, calendar.getAllItemsFromTodayOn(filter=filter)[:show_num], calendar.getNext(show_num, reverse=False, filter=filter))" 
         tal:condition="events">
         <h2 class="line" tal:condition="upcoming">Upcoming events</h2>
         <h2 class="line" tal:condition="not:upcoming">Events</h2>