[Mpuls-commits] r5956 - base/trunk/mpulsweb/controllers
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Mon May 7 16:14:48 CEST 2012
Author: bricks
Date: 2012-05-07 16:14:48 +0200 (Mon, 07 May 2012)
New Revision: 5956
Modified:
base/trunk/mpulsweb/controllers/case_bundle.py
Log:
Refactor bundleAction of case_bundle controller to be more flexible
For mpuls_S another special export is requiered. Therefore refactor
the bundleAction method to be better overrideable.
Modified: base/trunk/mpulsweb/controllers/case_bundle.py
===================================================================
--- base/trunk/mpulsweb/controllers/case_bundle.py 2012-05-07 14:12:01 UTC (rev 5955)
+++ base/trunk/mpulsweb/controllers/case_bundle.py 2012-05-07 14:14:48 UTC (rev 5956)
@@ -29,8 +29,11 @@
def index(self):
return "Hello world."
+ def _get_bundle_action_validator(self):
+ return BundleActionForm()
+
def bundleAction(self):
- validator = BundleActionForm()
+ validator = self._get_bundle_action_validator()
log.debug(request.params)
try:
# Check submitted fields
@@ -47,162 +50,164 @@
# Delegate to concrete action
action = form_result.get('action')
- # No action
- if action == 'no_action':
- return self.no_action()
- if action == 'markdelete':
- # Fiter out case which are not open(1) or inactive (2)
- case_bundle = self._filterBundle(case_bundle,
- allowedstates=(1, 2))
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- return self.markDelete(0)
- if action == 'delete':
- # Fiter out case which are not marked for deletion
- case_bundle = self._filterBundle(case_bundle,
- allowedstates=(3, 5))
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- return self.delete(0)
- if action == 'markanonymize':
- # Fiter out case which are not open(1) or inactive (2)
- # or not anonymizable
- case_bundle = self._filterBundle(case_bundle,
- allowedstates=(1, 2),
- filter_notanonymizable=True)
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- return self.markAnonymize(0)
- if action == 'anonymize':
- # Fiter out case which are not open(1) or inactive (2)
- # or not anonymizable
- case_bundle = self._filterBundle(case_bundle,
- allowedstates=(4,),
- filter_notanonymizable=True)
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- return self.anonymize(0)
- if action == 'restore':
- # Filter out cases which aren't marked for anonymization (4),
- # or marked for deletion (3)
- case_bundle = self._filterBundle(case_bundle,
- allowedstates=(3, 4))
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- return self.restore(0)
- if action == 'standin':
- # filter out cases where the user is not the editor and
- # therefor is not allowed to set the standin.
- user = session['USER_AUTHORIZED']
- filtered = []
- for case in case_bundle.getCases():
- if (case.getEditor().id != user.id and not user.isAdmin()):
- filtered.append(case.id)
+ return self.bundle_action(action, case_bundle)
+ except formencode.Invalid, error:
+ log.exception(error)
+ raise
+ except Exception, e:
+ log.exception(e)
+ raise
+ return "bundleAction"
- # Fiter out case which are not open(1) or inavtice (2)
- case_bundle = self._filterBundle(case_bundle, (1, 2), filtered)
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
+ def bundle_action(self, action, case_bundle):
+ # No action
+ if action == 'no_action':
+ return self.no_action()
+ if action == 'markdelete':
+ # Fiter out case which are not open(1) or inactive (2)
+ case_bundle = self._filterBundle(case_bundle,
+ allowedstates=(1, 2))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ return self.markDelete(0)
+ if action == 'delete':
+ # Fiter out case which are not marked for deletion
+ case_bundle = self._filterBundle(case_bundle,
+ allowedstates=(3, 5))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ return self.delete(0)
+ if action == 'markanonymize':
+ # Fiter out case which are not open(1) or inactive (2)
+ # or not anonymizable
+ case_bundle = self._filterBundle(case_bundle,
+ allowedstates=(1, 2),
+ filter_notanonymizable=True)
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ return self.markAnonymize(0)
+ if action == 'anonymize':
+ # Fiter out case which are not open(1) or inactive (2)
+ # or not anonymizable
+ case_bundle = self._filterBundle(case_bundle,
+ allowedstates=(4,),
+ filter_notanonymizable=True)
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ return self.anonymize(0)
+ if action == 'restore':
+ # Filter out cases which aren't marked for anonymization (4),
+ # or marked for deletion (3)
+ case_bundle = self._filterBundle(case_bundle,
+ allowedstates=(3, 4))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ return self.restore(0)
+ if action == 'standin':
+ # filter out cases where the user is not the editor and
+ # therefor is not allowed to set the standin.
+ user = session['USER_AUTHORIZED']
+ filtered = []
+ for case in case_bundle.getCases():
+ if (case.getEditor().id != user.id and not user.isAdmin()):
+ filtered.append(case.id)
- group_list = UserGroupList()
- user_list = UserListObject()
- group_filter = [u.gid for u in user_list.getAdminList()]
- group_filter.append(user.gid)
- c.group_list = group_list.getGroupList(group_filter)
- c.case_list = case_bundle.getCases()
- c.current_user = user
+ # Fiter out case which are not open(1) or inavtice (2)
+ case_bundle = self._filterBundle(case_bundle, (1, 2), filtered)
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
- return render('/casebundle/standin.mako')
- if action == 'transfer':
- # Fiter out case which are not open(1) or inavtice (2)
- user = session['USER_AUTHORIZED']
- case_bundle = self._filterBundle(case_bundle, (1, 2))
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
+ group_list = UserGroupList()
+ user_list = UserListObject()
+ group_filter = [u.gid for u in user_list.getAdminList()]
+ group_filter.append(user.gid)
+ c.group_list = group_list.getGroupList(group_filter)
+ c.case_list = case_bundle.getCases()
+ c.current_user = user
- user_list = UserListObject()
- user_filter = [u.id for u in user_list.getAdminList()]
- user_filter.append(user.id)
- c.user_list = user_list.getUserList(user_filter)
- c.case_list = case_bundle.getCases()
+ return render('/casebundle/standin.mako')
+ if action == 'transfer':
+ # Fiter out case which are not open(1) or inavtice (2)
+ user = session['USER_AUTHORIZED']
+ case_bundle = self._filterBundle(case_bundle, (1, 2))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
- return render('/casebundle/editor.mako')
+ user_list = UserListObject()
+ user_filter = [u.id for u in user_list.getAdminList()]
+ user_filter.append(user.id)
+ c.user_list = user_list.getUserList(user_filter)
+ c.case_list = case_bundle.getCases()
- if action.startswith("export"):
- # allow export of cases that are active (1), marked for
- # anonymization (4) or anonymized (5). For historical
- # reasons, there's also the old now unused state 2 in
- # the filter tuple.
- case_bundle = self._filterBundle(case_bundle, (1, 2, 4, 5))
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- export_format = action[6:]
- if export_format in ("XML", "CSV", "XLS"):
- return self.export(export_format)
+ return render('/casebundle/editor.mako')
- if action.startswith("formletter"):
- # allow formletter of cases that are active (1). For historical
- # reasons, there's also the old now unused state 2 in
- # the filter tuple.
- case_bundle = self._filterBundle(case_bundle, (1, 2))
- if case_bundle.isEmpty():
- return self._empty_caselist()
- session['casebundle'] = case_bundle
- session.save()
- letter_id = action.split(':')[1]
- return self.formletter(letter_id)
+ if action.startswith("export"):
+ # allow export of cases that are active (1), marked for
+ # anonymization (4) or anonymized (5). For historical
+ # reasons, there's also the old now unused state 2 in
+ # the filter tuple.
+ case_bundle = self._filterBundle(case_bundle, (1, 2, 4, 5))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ export_format = action[6:]
+ if export_format in ("XML", "CSV", "XLS"):
+ return self.export(export_format)
- if action == 'evaluate':
- case_bundle = self._funcFilterBundle(case_bundle,
- self._filter_for_evaluate)
- case_bundle = self._filterBundle(case_bundle, (1, 4, 5))
- if case_bundle.isEmpty():
- return self._empty_caselist()
+ if action.startswith("formletter"):
+ # allow formletter of cases that are active (1). For historical
+ # reasons, there's also the old now unused state 2 in
+ # the filter tuple.
+ case_bundle = self._filterBundle(case_bundle, (1, 2))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
+ session['casebundle'] = case_bundle
+ session.save()
+ letter_id = action.split(':')[1]
+ return self.formletter(letter_id)
- session['casebundle'] = case_bundle
- session["evaluation_ids"] = case_bundle.listDatasetIds()
- session["id_field"] = session.get('id_field_candidate')
- session["sql_where"] = session.get('sql_where_candidate')
- session.save()
- c.url_ok = url(controller='case_overview', action='index')
- num = len(case_bundle)
- c.dialog_title= ungettext("Case was marked for evaluation",
- "Cases were marked for evaluation",
- num)
- c.dialog_text = \
- ungettext("%d case was marked for evaluation."
- " All following evaluations will be limited"
- " to that case. Click 'OK' to continue.",
- "%d cases were marked for evaluation."
- " All following evalutations will be limited"
- " to those cases. Click 'OK' to continue.",
- num) % num
+ if action == 'evaluate':
+ case_bundle = self._funcFilterBundle(case_bundle,
+ self._filter_for_evaluate)
+ case_bundle = self._filterBundle(case_bundle, (1, 4, 5))
+ if case_bundle.isEmpty():
+ return self._empty_caselist()
- return render('/casebundle/dialogs/success_markevaluate.mako')
+ session['casebundle'] = case_bundle
+ session["evaluation_ids"] = case_bundle.listDatasetIds()
+ session["id_field"] = session.get('id_field_candidate')
+ session["sql_where"] = session.get('sql_where_candidate')
+ session.save()
+ c.url_ok = url(controller='case_overview', action='index')
+ num = len(case_bundle)
+ c.dialog_title= ungettext("Case was marked for evaluation",
+ "Cases were marked for evaluation",
+ num)
+ c.dialog_text = \
+ ungettext("%d case was marked for evaluation."
+ " All following evaluations will be limited"
+ " to that case. Click 'OK' to continue.",
+ "%d cases were marked for evaluation."
+ " All following evalutations will be limited"
+ " to those cases. Click 'OK' to continue.",
+ num) % num
- except formencode.Invalid, error:
- log.exception(error)
- raise
- except Exception, e:
- log.exception(e)
- raise
- return "bundleAction"
+ return render('/casebundle/dialogs/success_markevaluate.mako')
def _filterBundle(self, case_bundle, allowedstates, filtered_cases=None,
filter_notanonymizable=False):
More information about the Mpuls-commits
mailing list