[Mpuls-commits] r5289 - in base/trunk/mpulsweb: controllers lib model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Aug 31 16:38:39 CEST 2011


Author: roland
Date: 2011-08-31 16:38:38 +0200 (Wed, 31 Aug 2011)
New Revision: 5289

Modified:
   base/trunk/mpulsweb/controllers/mpuls.py
   base/trunk/mpulsweb/lib/config.py
   base/trunk/mpulsweb/model/appointment.py
Log:
Issue2231: add a new option to the JSON configuration file, "overview_tags"
where the IDs of "important" tags can be specified. All cases with these tags
will be shown in the overview as reminders (if the reminder module is active).
For title and description the text from the tags is used. The feature is
currently used only in JMD and there is, at the moment, basically no
configuration.


Modified: base/trunk/mpulsweb/controllers/mpuls.py
===================================================================
--- base/trunk/mpulsweb/controllers/mpuls.py	2011-08-31 09:57:47 UTC (rev 5288)
+++ base/trunk/mpulsweb/controllers/mpuls.py	2011-08-31 14:38:38 UTC (rev 5289)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 import logging
 
 from pylons import tmpl_context as c, app_globals as g
@@ -4,7 +5,8 @@
 
 from mpulsweb.model.news import NewsList
 from mpulsweb.model.appointment import GlobalAppointmentOverview, \
-     CaseAppointmentOverview, MaxSaveTimeReminderOverview, CaseReminderOverview
+     CaseAppointmentOverview, MaxSaveTimeReminderOverview, CaseReminderOverview, \
+     TagsReminderOverview
 from mpulsweb.lib.base import BaseController, render, session
 import mpulsweb.lib.helpers as h
 
@@ -35,7 +37,7 @@
             # Global appointments
             log.debug('Loading global appointment list')
             c.globalappointmentlist = self.get_global_appointments()
-
+        
         return render('/home/home.mako')
 
     def get_newslist(self, user):
@@ -58,11 +60,15 @@
         """Return an AppointmentOverview instance with reminders.
         The overview always contains the max save time reminders.
         """
-        
         remindlist = MaxSaveTimeReminderOverview()
         if h.hasRole(['cm']):
             remindlist.join(CaseReminderOverview())
+        
+        if h.hasRole(['cm']):
+            remindlist.join(TagsReminderOverview())
+        
         remindlist.sort()
+        
         return remindlist
 
 

Modified: base/trunk/mpulsweb/lib/config.py
===================================================================
--- base/trunk/mpulsweb/lib/config.py	2011-08-31 09:57:47 UTC (rev 5288)
+++ base/trunk/mpulsweb/lib/config.py	2011-08-31 14:38:38 UTC (rev 5289)
@@ -289,6 +289,15 @@
         # group instance but not inside a repeat group within the repeat
         # group.
         set("renderer", "rg_digests", unmergeable_dict())
+        
+        # IMPORTANT TAGS
+        # --------------
+        #
+        # Specify here a list of "important" tags. For cases with these tags,
+        # reminders will be shown in the overview, so use sparingly. The
+        # description of the reminder will be the one from the tag, as
+        # specified in the XML file.
+        set('overview_tags', 'tag_ids', '')
 
         # PHASES
         # --------

Modified: base/trunk/mpulsweb/model/appointment.py
===================================================================
--- base/trunk/mpulsweb/model/appointment.py	2011-08-31 09:57:47 UTC (rev 5288)
+++ base/trunk/mpulsweb/model/appointment.py	2011-08-31 14:38:38 UTC (rev 5289)
@@ -435,6 +435,110 @@
         CaseAppointment.__init__(self)
         self.type = 1
 
+# Tags
+
+class TagsReminderOverview(AppointmentOverview):
+    GET_CASES_WITH_TAGS = """
+    SELECT m.id
+    FROM master_tbl_view m
+    JOIN ka_status_tbl_view s ON s.master_id = m.id
+    JOIN nm_tags_cases_view t ON t.case_id = m.id
+    WHERE s.status = 1
+    AND m.bearbeiter_id = %%(editor)s
+    AND t.tag_id = %(tags)s
+    """
+    
+    GET_CASES_WITH_TAGS_ADMIN = """
+    SELECT m.id
+    FROM master_tbl_view m
+    JOIN ka_status_tbl_view s ON s.master_id = m.id
+    JOIN nm_tags_cases_view t ON t.case_id = m.id
+    WHERE s.status = 1
+    AND t.tag_id = %(tags)s
+    """
+    
+    
+    def __init__(self):
+        self.appointment_list = []
+        user = session['USER_AUTHORIZED']
+        reminder_tags = g.mpuls_config.get('overview_tags', 'tag_ids')
+        
+        # Return if there are no "important" tags defined
+        if not reminder_tags:
+            return
+        
+        cases = MpulsCaseOverview()
+        
+        # 1. Load the user's cases so we can check their tags
+        default_search_options = ['own:%s' % user.id, 'standin:%s' % user.id,
+                                  'state:1', 'state:2', 'state:3']
+        
+        # Get phasepart ids for the selected phasepairs. Only if pairs are
+        # defined.
+        for p in default_phases():
+            default_search_options.append('phase:%s' % p)
+        cases.search(";".join(default_search_options))
+
+        conn, cur = None, None
+        
+        h.tag_appointment = True
+        
+        # Make appointments for all cases that have the "important"-tags
+        for tag in reminder_tags:
+            case_list = {}
+            try:
+                conn = db.getConnection()
+                cur = conn.cursor()
+                if user.isAdmin():
+                    sql = (self.GET_CASES_WITH_TAGS_ADMIN % ({'tags': tag}))
+                    cur.execute(sql)
+                    print cur.query
+                else:
+                    sql = (self.GET_CASES_WITH_TAGS % ({'tags': tag}))
+                    cur.execute(sql, {'editor': self.getUserId()})
+                    print cur.query
+                result = cur.fetchall()
+                
+                for r in result:
+                    case_list[r[0]] = {}
+            finally:
+                db.recycleConnection(conn, cur)
+            
+            cases_with_tags_set = set(case_list)
+            cases_with_tags = [case for case in cases.getDatasets()
+                        if case.id in cases_with_tags_set]
+            
+            log.debug('cases with tags: %s' % case_list)
+            for case in cases_with_tags:
+                appointment = self.makeAppointment(case,
+                                        g.taggingConf.get_desc(tag),
+                                        g.taggingConf.get_name(tag))
+                self.appointment_list.append(appointment)
+        
+    def makeAppointment(self, case, description, title):
+        factory = CaseAppointmentFactory()
+        appointment_type = 2
+        
+        appointment = factory.createByData(None,
+                                            title,
+                                            None,
+                                            None,
+                                            description,
+                                            case.id,
+                                            appointment_type)
+        return appointment
+        
+    
+    def getUserId(self):
+        """
+        Return the User-ID. This function can be overwritten by applications
+        that have a "structure" part where the user that owns the cases is not
+        the user logged in.
+        """
+        user = session['USER_AUTHORIZED']
+        return user.id
+
+
 # MAXSAVETIME
 
 class MaxSaveTimeReminderOverview(AppointmentOverview):



More information about the Mpuls-commits mailing list