[Mpuls-commits] r5444 - jmd/trunk/jmdweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Oct 10 16:30:33 CEST 2011
Author: bh
Date: 2011-10-10 16:30:32 +0200 (Mon, 10 Oct 2011)
New Revision: 5444
Modified:
jmd/trunk/jmdweb/lib/search.py
Log:
Implement the search AppMixin class properly for jmdweb:
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, so
that we don't need to differentiate here between case search and
evaluation search.
The extra_validators method requires base/trunk r5426.
Fixes the JMD part of mpuls/issue2125.
Modified: jmd/trunk/jmdweb/lib/search.py
===================================================================
--- jmd/trunk/jmdweb/lib/search.py 2011-10-10 14:05:17 UTC (rev 5443)
+++ jmd/trunk/jmdweb/lib/search.py 2011-10-10 14:30:32 UTC (rev 5444)
@@ -34,35 +34,24 @@
from mpulsweb.lib.search import CaseSearch as CaseBaseSearch
from mpulsweb.lib.search import EvaluationSearch as EvaluationBaseSearch
-from mpulsweb.lib.search import AppMixin as AppBaseMixin
log = logging.getLogger(__name__)
-class AppMixin(AppBaseMixin):
- pass
+class AppMixin(object):
-class CaseSearch(CaseBaseSearch, AppMixin):
- VALID_OPTIONS = (CaseBaseSearch.VALID_OPTIONS
- + ("gender", "type_ending"))
- MULTI_OPTIONS = (CaseBaseSearch.MULTI_OPTIONS
- + ("type_ending",))
+ VALID_OPTIONS = ("gender", "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)
+ MULTI_OPTIONS = ("type_ending",)
+ def extra_validators(self):
+ validators = super(AppMixin, self).extra_validators()
+ validators["type_ending"] = ForEach(Int(), convert_to_list=True)
+ return validators
+
def convert_form_parameters(self, options, user, extended=True):
- 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")
@@ -71,7 +60,6 @@
return search
-
def get_gender_clause(self, options):
gender = options.get("gender")
if gender is not None:
@@ -90,12 +78,25 @@
"m.art_cm_ende")
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),
]
-class EvaluationSearch(EvaluationBaseSearch, AppMixin):
- pass
+class CaseSearch(AppMixin, CaseBaseSearch):
+ VALID_OPTIONS = (CaseBaseSearch.VALID_OPTIONS + AppMixin.VALID_OPTIONS)
+
+ MULTI_OPTIONS = (CaseBaseSearch.MULTI_OPTIONS + AppMixin.MULTI_OPTIONS)
+
+
+class EvaluationSearch(AppMixin, EvaluationBaseSearch):
+
+ 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