changeset 254:c15138774864

Merge with e5b444dab055a3fb2e07f28da4abaff846a9f300
author dwinter
date Tue, 27 May 2014 11:33:57 +0200
parents 065c4284238f (current diff) e5b444dab055 (diff)
children cc7517f08d9e 761869998ad0
files MPIWGStaff.py
diffstat 6 files changed, 144 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGProjects.py	Tue May 27 11:33:16 2014 +0200
+++ b/MPIWGProjects.py	Tue May 27 11:33:57 2014 +0200
@@ -24,6 +24,7 @@
 
 from SrvTxtUtils import getInt, unicodify, utf8ify, serialize, refreshingImageFileIndexHtml, shortenString, getPlaintext
 from Products.ZDBInterface.ZDBInterfaceFolder import ZDBInterfaceFolder
+from Products.MPIWGManager import MPIWGIcsManager
 
 import xmlhelper  # Methoden zur Verwaltung der projekt xml
 from HashTree import HashTree
@@ -401,6 +402,8 @@
     editAddAdditionalPublications = PageTemplateFile('zpt/project/pubman/add_publications', globals())
     security.declareProtected('View management screens', 'edit')
     edit = editDescription
+    security.declareProtected('View management screens', 'editCalendarForm')
+    editCalendarForm = PageTemplateFile('zpt/project/edit_calendar', globals())
     # management templates
     security.declareProtected('View management screens', 'loadNewFileForm')
     loadNewFileForm = PageTemplateFile('zpt/project/manage_newfile', globals())
@@ -421,9 +424,9 @@
         if argv:
             for arg in definedFields:
                 try:
-                        setattr(self, arg, argv[arg])
+                    setattr(self, arg, argv[arg])
                 except:
-                        setattr(self, arg, "")
+                    setattr(self, arg, "")
         else:
             for arg in definedFields:
                 setattr(self, arg, '')
@@ -653,6 +656,70 @@
         else:
             return t
 
+
+    def getProjectCalendar(self):
+        """Return the project calendar object (MPIWGIcsManager)"""
+        return self.get('calendar', 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:
+            if cal is None:
+                # create calendar
+                cal = MPIWGIcsManager.MPIWGIcsManager('calendar', 'Project Calendar', url, defaultProps=MPIWGIcsManager.calendar_props)
+                self['calendar'] = cal
+            
+            else:
+                # calendar exists
+                if cal.url != url:
+                    # remove and re-create
+                    del self['calendar']
+                    cal = MPIWGIcsManager.MPIWGIcsManager('calendar', 'Project Calendar', url, defaultProps=MPIWGIcsManager.calendar_props)
+                    self['calendar'] = cal
+            
+            # show only upcoming
+            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
+            del self['calendar']
+            
+        if RESPONSE is not None:
+            self.redirect(RESPONSE, 'editCalendarForm')
+
+            
+
+
+    def getProjectNumberMatcher(self, num, getter=None):
+        """Return a function that matches a project number pattern.
+        
+        Matches exactly except when num ends with '*'. Uses function getter on arguments.
+        """
+        if num is None:
+            return None
+        
+        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:
+            if getter is None:
+                return lambda x : num == x
+            else:
+                return lambda x : num == getter(x)
+
               
     def _moveObjectPlace(self, objectList, objectId, direction):
         """Move object with objectId from objectList in direction 
--- a/MPIWGStaff.py	Tue May 27 11:33:16 2014 +0200
+++ b/MPIWGStaff.py	Tue May 27 11:33:57 2014 +0200
@@ -19,7 +19,7 @@
 import datetime
 
 from Products.ZDBInterface.ZDBInterfaceFolder import ZDBInterfaceFolder
-from Products.MPIWGManager.MPIWGIcsManager import MPIWGIcsManager
+from Products.MPIWGManager import MPIWGIcsManager
 
 from SrvTxtUtils import getInt, unicodify, utf8ify, sqlName, getPlaintext
 import MPIWGHelper
@@ -38,13 +38,6 @@
 manage_addMPIWGStaffForm = MPIWGStaff_old.manage_addMPIWGStaffForm
 manage_addMPIWGStaff = MPIWGStaff_old.manage_addMPIWGStaff
 
-# MPIWGManager properties for ICS-calendars
-# (ID_EN, ID_DE, VALUE_EN, VALUE_DE, WEIGHT, ID)
-calendar_props = [('Description', 'Beschreibung', None, None, 0, 'description'), 
-             ('Location', 'Ort', None, None, 0, 'location'),
-             ('URL', 'URL', None, None, 0, 'url'),
-             ('Time', 'Zeit', None, None, 0, 'time')]
-
     
 class MPIWGStaffFolder(ZDBInterfaceFolder):
     """Folder of staff objects"""
@@ -613,7 +606,7 @@
                 cal = self.getTalksCal()
                 if cal is None:
                     # create new calendar
-                    cal = MPIWGIcsManager(cal_id, '', url, defaultProps=calendar_props)
+                    cal = MPIWGIcsManager.MPIWGIcsManager(cal_id, '', url, defaultProps=MPIWGIcsManager.calendar_props)
                     self.folder.get('calendars')[cal_id] = cal
                     
                 else:
@@ -621,7 +614,7 @@
                     if cal.url != url:
                         # remove and re-create
                         del self.folder.get('calendars')[cal_id]
-                        cal = MPIWGIcsManager(cal_id, '', url, defaultProps=calendar_props)
+                        cal = MPIWGIcsManager.MPIWGIcsManager(cal_id, '', url, defaultProps=MPIWGIcsManager.calendar_props)
                         self.folder.get('calendars')[cal_id] = cal
 
                 # show only upcoming
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/project/edit_calendar.zpt	Tue May 27 11:33:57 2014 +0200
@@ -0,0 +1,41 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html metal:use-macro="here/edit_template/macros/page">
+<head>
+</head>
+<body>
+  <tal:block metal:fill-slot="navsel" tal:define="global menusel string:calendar" />
+  <tal:block metal:fill-slot="body">
+    <form tal:attributes="action string:$root/editProjectCalendar" method="post" tal:define="cal here/getProjectCalendar">
+      <h3>Project calendar</h3>
+      <p>
+        Calendar URL: <input name="url" tal:attributes="value cal/url | nothing" size="80" />
+      </p>
+      <p>
+        URL has to link to publicly accessible calendar in iCalendar format.<br /> (e.g.
+        https://sogo.mpiwg-berlin.mpg.de/SOGo/dav/public/mpiwg-calendar/Calendar/A5B-52288800-1-2F304600.ics)
+      </p>
+      <p tal:condition="cal">Remove the calendar URL to switch off calendar display.</p>
+      <p tal:condition="not:cal">Calendar display properties can be changed after the calendar has been created.</p>
+      <p tal:condition="cal">
+        <tal:block tal:define="name string:only_upcoming; value python:test(cal.getFlag('only_upcoming'), 'yes', 'no');">
+      Show only upcoming events in the calendar: <span metal:use-macro="here/en/common_template/macros/yesno_input_radio" />
+        </tal:block>
+      </p>
+      <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>
+    </form>
+
+  </tal:block>
+</body>
+</html>
--- a/zpt/project/edit_template.zpt	Tue May 27 11:33:16 2014 +0200
+++ b/zpt/project/edit_template.zpt	Tue May 27 11:33:57 2014 +0200
@@ -24,6 +24,8 @@
       tal:attributes="href string:$root/manageRelatedProjects">Related projects</a></span>
     <span tal:attributes="class python:test('infoblocks'==menusel, 'mainmenusel', 'mainmenu')"><a 
       tal:attributes="href string:$root/manageInfoBlocks">Info blocks</a></span>
+    <span tal:attributes="class python:test('calendar'==menusel, 'mainmenusel', 'mainmenu')"><a 
+      tal:attributes="href string:$root/editCalendarForm">Calendar</a></span>
     <span tal:attributes="class python:test('themes'==menusel, 'mainmenusel', 'mainmenu')"><a 
       tal:attributes="href string:$root/tagTheProject">Tags</a></span>
     <span class="mainmenu"><a target="_blank" 
--- a/zpt/project/project_index_html.zpt	Tue May 27 11:33:16 2014 +0200
+++ b/zpt/project/project_index_html.zpt	Tue May 27 11:33:57 2014 +0200
@@ -177,6 +177,27 @@
       </div>
     </div>
 
+    <!-- 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); 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>
+        <div class="item" tal:repeat="event events">
+          <tal:block tal:define="url python:event.getValue('url'); loc python:event.getValue('location');">
+            <span tal:content="python:event.getDate()" />:
+            <span tal:replace="loc" /> <span tal:condition="loc">&#150;</span> 
+            <a target="_blank" tal:omit-tag="not:url" tal:attributes="href url">
+              <i><span tal:replace="python:event.getValue('title')" /></i>
+            </a>
+          </tal:block>
+        </div>
+      </tal:block>
+    </div>
+
     <!-- related digital sources -->
     <div class="sideblock" tal:define="sources here/getRelatedDigitalSources" tal:condition="sources">
       <h2>OLD! Related digital sources</h2>
@@ -192,6 +213,7 @@
         Funding
       </div>
     </div>
+
     <!-- sideblock -->
 	 <div class="sideblock" tal:define="tags python:here.thesaurus.getTagsAsHash(here.getId())" tal:condition="tags">
       <h2>Keywords</h2>
--- a/zpt/www/main_template.zpt	Tue May 27 11:33:16 2014 +0200
+++ b/zpt/www/main_template.zpt	Tue May 27 11:33:57 2014 +0200
@@ -5,7 +5,7 @@
                   global crumbs template/getBreadcrumbs | nothing;
                   section here/getSection | nothing;
                   sections here/getSections | nothing;
-                  lang here/getLang | nothing;
+                  lang here/getLang | nothing; langroot python:here.getMPIWGRoot().aq_parent.absolute_url();
                   allsecs python:{'en':{
                     'institute':'institute',
                     'staff':'staff',
@@ -60,8 +60,8 @@
       <ul>
         <li tal:repeat="sec sections" tal:attributes="class python:test(sec.getId()==section,'sec on','sec')"><a
           tal:attributes="href sec/absolute_url" tal:content="sec/title">Institute</a></li>
-        <li class="sec lang" tal:condition="python:lang=='en'"><a class="internal" tal:attributes="href string:$root/../de">Deutsch</a></li>
-        <li class="sec lang" tal:condition="python:lang=='de'"><a class="internal" tal:attributes="href string:$root/../en">English</a></li>
+        <li class="sec lang" tal:condition="python:lang=='en'"><a class="internal" tal:attributes="href string:$langroot/de/index.html">Deutsch</a></li>
+        <li class="sec lang" tal:condition="python:lang=='de'"><a class="internal" tal:attributes="href string:$langroot/en/index.html">English</a></li>
       </ul>
     </div>
 
@@ -123,7 +123,8 @@
         | <a href="http://www2.mpiwg-berlin.mpg.de/Library/libindex.html" target="_blank">Bibliothek (intern)</a> 
         | <a tal:attributes="href string:$root/institut/overview.html">&Uuml;berblick</a> 
         | <a tal:attributes="href string:$root/institut/adresse.html">Kontakt</a>
-        | <a tal:attributes="href string:$root/impressum.html">Impressum/Lizenz</a> 
+        | <a tal:attributes="href string:$root/impressum.html">Impressum</a>
+        | <a tal:attributes="href string:$root/institut/lizenzen.html">Lizenzen</a>
       </div>
       <div class="text" tal:condition="python:lang!='de'">
         <a href="http://intranet.mpiwg-berlin.mpg.de" target="_blank">Intranet</a> 
@@ -131,7 +132,8 @@
         | <a href="http://www2.mpiwg-berlin.mpg.de/Library/libindex.html" target="_blank">Library (internal)</a> 
         | <a tal:attributes="href string:$root/institute/overview.html">Overview</a> 
         | <a tal:attributes="href string:$root/institute/address.html">Contact</a>
-        | <a tal:attributes="href string:$root/impressum.html">Imprint/Licenses</a> 
+        | <a tal:attributes="href string:$root/impressum.html">Imprint</a> 
+        | <a tal:attributes="href string:$root/institute/licences.html">Licences</a> 
       </div>
       <div class="logo">
         <a href="http://www.mpg.de/"> <img tal:attributes="src string:$root/images/signet.png" alt="MPG" width="204" height="41" />