[Mpuls-commits] r5433 - wasko/trunk/waskoweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 7 21:44:39 CEST 2011


Author: bh
Date: 2011-10-07 21:44:38 +0200 (Fri, 07 Oct 2011)
New Revision: 5433

Modified:
   wasko/trunk/waskoweb/lib/search.py
Log:
Make the search AppMixin class work:
AppMixin must be first base class of CaseSearch and EvaluationSearch.
The code in AppMixin has to always use super() to call the inherited
method so that the method from the correct base class is called.
The class variables VALID_OPTIONS and MULTI_OPTIONS have to be handled
correctly.
Use extra_validators instead of validate_form_params in AppMixin.
The extra_validators validators method makes it easier to just add
validation for additional parameters and now the mixin should work for
both the normal case search and the search on the evaluation server
(although WASKO doesn't currently use this code on the evaluation
server).

The extra_validators method requires base/trunk r5426.

Fixes the WASKO part of mpuls/issue2339.


Modified: wasko/trunk/waskoweb/lib/search.py
===================================================================
--- wasko/trunk/waskoweb/lib/search.py	2011-10-07 19:21:03 UTC (rev 5432)
+++ wasko/trunk/waskoweb/lib/search.py	2011-10-07 19:44:38 UTC (rev 5433)
@@ -41,29 +41,20 @@
 
 class AppMixin(object):
 
-    VALID_OPTIONS = (CaseBaseSearch.VALID_OPTIONS
-                     + ("gender", "type_ending", "migration"))
-    MULTI_OPTIONS = (CaseBaseSearch.MULTI_OPTIONS
-                     + ("type_ending",))
+    VALID_OPTIONS = ("gender", "type_ending", "migration")
+    MULTI_OPTIONS = ("type_ending",)
 
     # In wasko, the values for male and female are swapped.
     wasko_gender_mapping = {"1": "0", "0": "1"}
 
-    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),
-                                   migration=Int(if_missing=-2))
-        return validator.to_python(params)
+    def extra_validators(self):
+        validators = super(AppMixin, self).extra_validators()
+        validators["type_ending"] = ForEach(Int(), convert_to_list=True)
+        validators["migration"] = Int(if_missing=-2)
+        return validators
 
     def convert_form_parameters(self, options, user, extended):
-        search = CaseBaseSearch.convert_form_parameters(self, options, user,
+        search = super(AppMixin, self).convert_form_parameters(options, user,
                                                         extended=extended)
         if extended:
             type_ending = options.get("type_ending")
@@ -121,17 +112,26 @@
         return "TRUE"
 
     def get_where_subclauses(self, options):
-        return CaseBaseSearch.get_where_subclauses(self, options) + [
+        return super(AppMixin, self).get_where_subclauses(options) + [
             self.get_ending_clause(options),
             self.get_migration_clause(options),
             ]
 
-class CaseSearch(CaseBaseSearch):
 
-    pass
+class CaseSearch(AppMixin, CaseBaseSearch):
 
+    VALID_OPTIONS = (CaseBaseSearch.VALID_OPTIONS + AppMixin.VALID_OPTIONS)
+
+    MULTI_OPTIONS = (CaseBaseSearch.MULTI_OPTIONS + AppMixin.MULTI_OPTIONS)
+
+
 class EvaluationSearch(EvaluationBaseSearch):
 
-    pass
+    VALID_OPTIONS = (EvaluationBaseSearch.VALID_OPTIONS
+                     + AppMixin.VALID_OPTIONS)
 
+    MULTI_OPTIONS = (EvaluationBaseSearch.MULTI_OPTIONS
+                     + AppMixin.MULTI_OPTIONS)
+
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list