[Mpuls-commits] r5788 - base/branches/2.1.0/mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Jan 24 12:47:16 CET 2012
Author: torsten
Date: 2012-01-24 12:47:15 +0100 (Tue, 24 Jan 2012)
New Revision: 5788
Modified:
base/branches/2.1.0/mpulsweb/lib/base.py
Log:
Moved loadCase function out of the case controller an make it importable for
other parts of the application. Old _loadCase function now calls new
load_case function to ensure that nothing breaks.
Modified: base/branches/2.1.0/mpulsweb/lib/base.py
===================================================================
--- base/branches/2.1.0/mpulsweb/lib/base.py 2012-01-24 11:29:02 UTC (rev 5787)
+++ base/branches/2.1.0/mpulsweb/lib/base.py 2012-01-24 11:47:15 UTC (rev 5788)
@@ -109,63 +109,66 @@
cache_type=cache_type, cache_expire=cache_expire)
render = render_mako
-class BaseController(WSGIController):
+def load_case(id, uncommitted=None, read_only=False):
+ """Load and return the case object for the case with the given id.
- def __init__(self):
- self.db = None
- self.page_cache = None
+ The parameter uncommitted, if given and not None, should be a
+ dictionary usable as the uncommitted parameter of the loadById
+ method of the case factory.
- def _loadCase(self, id, uncommitted=None, read_only=False):
- """Load and return the case object for the case with the given id.
+ If the parameter read_only is false (the default), the case must
+ be editable by the current user as determined by the case's
+ user_may_edit method. If the case is not editable in this sense,
+ the method calls the showError method. Also, showError is called
+ if the case is not readable by the current user as determined by
+ the case's user_may_read method.
- The parameter uncommitted, if given and not None, should be a
- dictionary usable as the uncommitted parameter of the loadById
- method of the case factory.
+ Note that the default value of the read_only parameter means
+ that by default the _loadCase assumes that cases are loaded in
+ order to modify them and will raise an exception if the user is
+ not allowed to do that. The default value was chosen to err on
+ the side of caution. From a security point of view it's better
+ to deny an action that should have been allowed, than to allow
+ an action that ought to have been denied.
+ """
+ case = g.case_factory.loadById(id, uncommitted=uncommitted)
- If the parameter read_only is false (the default), the case must
- be editable by the current user as determined by the case's
- user_may_edit method. If the case is not editable in this sense,
- the method calls the showError method. Also, showError is called
- if the case is not readable by the current user as determined by
- the case's user_may_read method.
+ user = session["USER_AUTHORIZED"]
+ if not case.user_may_read(user):
+ self.showError()
+ if not read_only and not case.user_may_edit(user):
+ self.showError()
- Note that the default value of the read_only parameter means
- that by default the _loadCase assumes that cases are loaded in
- order to modify them and will raise an exception if the user is
- not allowed to do that. The default value was chosen to err on
- the side of caution. From a security point of view it's better
- to deny an action that should have been allowed, than to allow
- an action that ought to have been denied.
- """
- case = g.case_factory.loadById(id, uncommitted=uncommitted)
+ session_case = case.getSessionCase()
+ if session.has_key('case'):
+ old_caseid = session.get('case').id
+ else: old_caseid = None
- user = session["USER_AUTHORIZED"]
- if not case.user_may_read(user):
- self.showError()
- if not read_only and not case.user_may_edit(user):
- self.showError()
+ # New session code
+ session['case'] = session_case
- session_case = case.getSessionCase()
- if session.has_key('case'):
- old_caseid = session.get('case').id
- else: old_caseid = None
+ # Only reset navigation if case is switched
+ if str(old_caseid) != str(id):
+ open_folders = []
+ navigation = get_navigation(id)
+ session['render_mode'] = 'ro'
+ session['navigation.tree'] = navigation
+ session['navigation.openfolders'] = open_folders
+ session['navigation.selectedpage'] = None
+ # Also reset uncommited fields, because a new case is loaded.
+ session['uncommited_fields'] = {}
+ session.save()
+ return case
- # New session code
- session['case'] = session_case
+class BaseController(WSGIController):
- # Only reset navigation if case is switched
- if str(old_caseid) != str(id):
- open_folders = []
- navigation = get_navigation(id)
- session['render_mode'] = 'ro'
- session['navigation.tree'] = navigation
- session['navigation.openfolders'] = open_folders
- session['navigation.selectedpage'] = None
- # Also reset uncommited fields, because a new case is loaded.
- session['uncommited_fields'] = {}
- session.save()
- return case
+ def __init__(self):
+ self.db = None
+ self.page_cache = None
+ def _loadCase(self, id, uncommitted=None, read_only=False):
+ return load_case(id, uncommitted, read_only)
+
def _load_current_case(self, read_only=False):
"""Load and return the case object for the session's current case.
More information about the Mpuls-commits
mailing list