[Mpuls-commits] r3490 - in jmd/trunk: . jmdweb/lib jmdweb/templates/casemanagement

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 30 20:12:41 CEST 2010


Author: bh
Date: 2010-08-30 20:12:39 +0200 (Mon, 30 Aug 2010)
New Revision: 3490

Added:
   jmd/trunk/jmdweb/templates/casemanagement/search_extra.mako
Modified:
   jmd/trunk/ChangeLog
   jmd/trunk/jmd.json
   jmd/trunk/jmdweb/lib/search.py
Log:
* jmd.json: Add type_ending default search parameters

* jmdweb/lib/search.py (CaseSearch.VALID_OPTIONS)
(CaseSearch.MULTI_OPTIONS): Add type_ending
(CaseSearch.validate_form_params): New. Extend base class method
validate type_ending, too.
(CaseSearch.convert_form_parameters): New. Extend base class
method to convert type_ending, too.
(CaseSearch.get_ending_clause): New. Handle type_ending options.
(CaseSearch.get_where_subclauses): New. Extend base class method
to call get_ending_clause, too.

* jmdweb/templates/casemanagement/search_extra.mako: New.  Search
options for type of ending.


Modified: jmd/trunk/ChangeLog
===================================================================
--- jmd/trunk/ChangeLog	2010-08-30 17:47:55 UTC (rev 3489)
+++ jmd/trunk/ChangeLog	2010-08-30 18:12:39 UTC (rev 3490)
@@ -1,5 +1,22 @@
 2010-08-30  Bernhard Herzog  <bh at intevation.de>
 
+	* jmdweb/templates/casemanagement/search_extra.mako: New.  Search
+	options for type of ending.
+
+	* jmdweb/lib/search.py (CaseSearch.VALID_OPTIONS)
+	(CaseSearch.MULTI_OPTIONS): Add type_ending
+	(CaseSearch.validate_form_params): New. Extend base class method
+	validate type_ending, too.
+	(CaseSearch.convert_form_parameters): New. Extend base class
+	method to convert type_ending, too.
+	(CaseSearch.get_ending_clause): New. Handle type_ending options.
+	(CaseSearch.get_where_subclauses): New. Extend base class method
+	to call get_ending_clause, too.
+
+	* jmd.json: Add type_ending default search parameters
+
+2010-08-30  Bernhard Herzog  <bh at intevation.de>
+
 	* jmdweb/lib/search.py (CaseSearch.get_gender_clause): Adapt to
 	base class changes: Remove search parameter.
 

Modified: jmd/trunk/jmd.json
===================================================================
--- jmd/trunk/jmd.json	2010-08-30 17:47:55 UTC (rev 3489)
+++ jmd/trunk/jmd.json	2010-08-30 18:12:39 UTC (rev 3490)
@@ -49,13 +49,17 @@
 		"admin_defaults": [
             		{"search_str": "", 
 			 "state": ["3", "4"], 
-			 "phase": ["-1", "0", "1", "2"]}
+			 "phase": ["-1", "0", "1", "2"],
+			 "type_ending": ["-3", "-1", "0", "1"]
+			}
 		],
 		"cm_defaults": [
             		{"own": "1", 
 			 "search_str": "", 
 			 "state": ["1"], 
-			 "phase": ["-1", "0", "1", "2"]}
+			 "phase": ["-1", "0", "1", "2"],
+			 "type_ending": ["-3", "-1", "0", "1"]
+			}
 		]
 	},
 	"logbook": {

Modified: jmd/trunk/jmdweb/lib/search.py
===================================================================
--- jmd/trunk/jmdweb/lib/search.py	2010-08-30 17:47:55 UTC (rev 3489)
+++ jmd/trunk/jmdweb/lib/search.py	2010-08-30 18:12:39 UTC (rev 3490)
@@ -28,6 +28,10 @@
 # Torsten Irländer <torsten.irlaender at intevation.de>
 
 import logging
+
+from formencode import ForEach
+from formencode.validators import Int
+
 from mpulsweb.lib.search import CaseSearch as CaseBaseSearch
 
 
@@ -37,15 +41,58 @@
 class CaseSearch(CaseBaseSearch):
 
     VALID_OPTIONS = (CaseBaseSearch.VALID_OPTIONS
-                     + ("gender",))
+                     + ("gender", "type_ending"))
+    MULTI_OPTIONS = (CaseBaseSearch.MULTI_OPTIONS
+                     + ("type_ending",))
 
+    def validate_form_params(self, params):
+        # FIXME: We import SearchCaseForm here because importing it
+        # during import doesn't work.  The validators module performs
+        # translations and accesses app_globals during import, so it has
+        # to be imported when a HTTP-request is being handled.  The
+        # search module is imported early on when the application starts
+        # so validators cannot be imported then.
+        from mpulsweb.lib.validators import SearchCaseForm
+        validator = SearchCaseForm(type_ending=ForEach(Int(),
+                                                       convert_to_list=True))
+        return validator.to_python(params)
 
+    def convert_form_parameters(self, options, user):
+        search_options = CaseBaseSearch.convert_form_parameters(self, options,
+                                                                user)
+        if "type_ending" in options:
+            search_options["type_ending"] = options["type_ending"]
+
+        return search_options
+
+
     def get_gender_clause(self, options):
         gender = options.get("gender")
         if gender is not None:
             return "m.geschlecht = %s" % gender
         return "TRUE"
 
+    def get_ending_clause(self, options):
+        """Return the where subclause that selects based on CM ending.
+        If the type_ending option was not specified, any ending will be
+        OK, so this method returns 'TRUE'.  Otherwise only endings
+        contained in the list value of the type_ending option will be
+        selected.  If that list is empty, no ending will be OK, so no
+        case will be found.
+        """
+        if "type_ending" in options:
+            endings = options["type_ending"]
+            if endings:
+                return ('m.art_cm_ende IN (%s)'
+                        % ','.join([str(ending) for ending in endings]))
+            else:
+                return "FALSE"
+        return "TRUE"
 
+    def get_where_subclauses(self, options):
+        return CaseBaseSearch.get_where_subclauses(self, options) + [
+            self.get_ending_clause(options),
+            ]
 
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Added: jmd/trunk/jmdweb/templates/casemanagement/search_extra.mako
===================================================================
--- jmd/trunk/jmdweb/templates/casemanagement/search_extra.mako	2010-08-30 17:47:55 UTC (rev 3489)
+++ jmd/trunk/jmdweb/templates/casemanagement/search_extra.mako	2010-08-30 18:12:39 UTC (rev 3490)
@@ -0,0 +1,15 @@
+## -*- coding: utf-8 -*-
+
+<tr style="${not c.extended_search and 'display:none' or ''}">
+  <td class="label">Art der Beendigung</td>
+  <td>
+    <input type="checkbox" value="-3" id="type_ending_-3" name="type_ending"/>
+    <label for="type_ending_-3">Unbekannt</label><br/>
+    <input type="checkbox" value="-1" id="type_ending_-1" name="type_ending"/>
+    <label for="type_ending_-1">Keine Angabe</label><br/>
+    <input type="checkbox" value="1" id="type_ending_1" name="type_ending"/>
+    <label for="type_ending_1">reguläre Beendigung</label><br/>
+    <input type="checkbox" value="0" id="type_ending_0" name="type_ending"/>
+    <label for="type_ending_0">Abbruch</label><br/>
+  </td>
+</tr>



More information about the Mpuls-commits mailing list