[Mpuls-commits] r3756 - in wasko/trunk: . waskoweb/lib waskoweb/templates/casemanagement

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 21 17:00:38 CEST 2010


Author: bh
Date: 2010-09-21 17:00:37 +0200 (Tue, 21 Sep 2010)
New Revision: 3756

Modified:
   wasko/trunk/ChangeLog
   wasko/trunk/waskoweb/lib/search.py
   wasko/trunk/waskoweb/templates/casemanagement/search_extra.mako
Log:
Implement mpuls/issue1092 (search for migration background)

* waskoweb/lib/search.py (CaseSearch.VALID_OPTIONS): Add migration
(CaseSearch.validate_form_params): Add validator for the migration
parameter
(CaseSearch.convert_form_parameters): Handle the migration
parameter
(CaseSearch.get_migration_clause): Construct migration search
clause
(CaseSearch.get_where_subclauses): Include the migration clause in
the return value

* waskoweb/templates/casemanagement/search_extra.mako: Add search
option for migration background.


Modified: wasko/trunk/ChangeLog
===================================================================
--- wasko/trunk/ChangeLog	2010-09-20 15:47:19 UTC (rev 3755)
+++ wasko/trunk/ChangeLog	2010-09-21 15:00:37 UTC (rev 3756)
@@ -1,3 +1,20 @@
+2010-09-21  Bernhard Herzog  <bh at intevation.de>
+
+	Implement mpuls/issue1092 (search for migration background)
+
+	* waskoweb/lib/search.py (CaseSearch.VALID_OPTIONS): Add migration
+	(CaseSearch.validate_form_params): Add validator for the migration
+	parameter
+	(CaseSearch.convert_form_parameters): Handle the migration
+	parameter
+	(CaseSearch.get_migration_clause): Construct migration search
+	clause
+	(CaseSearch.get_where_subclauses): Include the migration clause in
+	the return value
+
+	* waskoweb/templates/casemanagement/search_extra.mako: Add search
+	option for migration background.
+
 2010-09-20  Roland Geider  <roland.geider at intevation.de>
 
 	* waskoweb/templates/privacy/discretion_statement.html: issue1174

Modified: wasko/trunk/waskoweb/lib/search.py
===================================================================
--- wasko/trunk/waskoweb/lib/search.py	2010-09-20 15:47:19 UTC (rev 3755)
+++ wasko/trunk/waskoweb/lib/search.py	2010-09-21 15:00:37 UTC (rev 3756)
@@ -41,7 +41,7 @@
 class CaseSearch(CaseBaseSearch):
 
     VALID_OPTIONS = (CaseBaseSearch.VALID_OPTIONS
-                     + ("gender", "type_ending"))
+                     + ("gender", "type_ending", "migration"))
     MULTI_OPTIONS = (CaseBaseSearch.MULTI_OPTIONS
                      + ("type_ending",))
 
@@ -57,7 +57,8 @@
         # so validators cannot be imported then.
         from mpulsweb.lib.validators import SearchCaseForm
         validator = SearchCaseForm(type_ending=ForEach(Int(),
-                                                       convert_to_list=True))
+                                                       convert_to_list=True),
+                                   migration=Int(if_missing=-2))
         return validator.to_python(params)
 
     def convert_form_parameters(self, options, user, extended):
@@ -66,6 +67,8 @@
         if extended:
             if "type_ending" in options:
                 search["type_ending"] = options["type_ending"]
+            if "migration" in options:
+                search["migration"] = options["migration"]
 
         return search
 
@@ -87,9 +90,38 @@
                     % self.wasko_gender_mapping.get(gender, gender))
         return "TRUE"
 
+    def get_migration_clause(self, options):
+        """Return search clause selecting cases based on migration background.
+        """
+        migration = options.get('migration')
+        if migration is not None:
+            migration_clause = ("(nat_muspra NOT IN (18, -1, -3)"
+                                " OR nat_staat NOT IN (1, -1, -3)"
+                                " OR vater_land NOT IN (29, -1, -3)"
+                                " OR mutter_land NOT IN (29, -1, -3))")
+            no_migration_clause = ("(nat_muspra = 18 AND nat_staat = 1"
+                                   " AND vater_land = 29 AND mutter_land = 29)")
+            if migration == 1:
+                return migration_clause
+            elif migration == 0:
+                return no_migration_clause
+            elif migration == -1:
+                return ("(NOT %s AND NOT %s)"
+                        % (migration_clause, no_migration_clause))
+            elif migration == 2:
+                return ("(nat_staat = 2"
+                        " and (vater_staat != 2 or mutter_staat != 2))")
+            elif migration == -2:
+                return "TRUE"
+            else:
+                log.warning("unknown value for migration search: %d", migration)
+
+        return "TRUE"
+
     def get_where_subclauses(self, options):
         return CaseBaseSearch.get_where_subclauses(self, options) + [
             self.get_ending_clause(options),
+            self.get_migration_clause(options),
             ]
 
 

Modified: wasko/trunk/waskoweb/templates/casemanagement/search_extra.mako
===================================================================
--- wasko/trunk/waskoweb/templates/casemanagement/search_extra.mako	2010-09-20 15:47:19 UTC (rev 3755)
+++ wasko/trunk/waskoweb/templates/casemanagement/search_extra.mako	2010-09-21 15:00:37 UTC (rev 3756)
@@ -1,6 +1,22 @@
 ## -*- coding: utf-8 -*-
 
 <tr style="${not c.extended_search and 'display:none' or ''}">
+  <td class="label">Migration</td>
+  <td valign="top">
+    <select name="migration" id="migration">
+      <option value="-2">Keine Auswahl</option>
+      <option value="1">Ja</option>
+      <option value="0">Nein</option>
+      <option value="-1">Unbekannt</option>
+      <option value="2">Auffällig</option>
+    </select>
+  </td>
+  <td>
+    <form:error name="migration">
+  </td>
+</tr>
+
+<tr style="${not c.extended_search and 'display:none' or ''}">
   <td class="label">Art der Beendigung</td>
   <td>
     <input type="checkbox" value="-1" id="type_ending_-1" name="type_ending"/>



More information about the Mpuls-commits mailing list