Permalink
Browse files

Move hrm_vars into modules/eden/hrm.py (for reuse by other modules).

  • Loading branch information...
nursix committed Mar 28, 2012
1 parent 46595f4 commit e823997784e1fbc80b05a2a1aaaf1af0e41423ee
Showing with 45 additions and 42 deletions.
  1. +1 −1 VERSION
  2. +1 −41 controllers/hrm.py
  3. +43 −0 modules/eden/hrm.py
View
@@ -1 +1 @@
-vita-0.5.5-devel-635-g1a2d8ee (2012-03-28 10:03:57)
+vita-0.5.5-devel-636-g46595f4 (2012-03-28 11:03:08)
View
@@ -15,47 +15,7 @@
session.s3.hrm = Storage()
session.s3.hrm.mode = request.vars.get("mode", None)
-# =============================================================================
-@auth.requires_login()
-def hrm_vars(session):
- """
- Set session and response variables
-
- @param session: the session, parameter to prevent this function
- from being called by a direct request
- """
- try:
- module_name = deployment_settings.modules[module].name_nice
- except:
- module_name = T("Human Resources Management")
- response.title = module_name
-
- # Automatically choose an organisation
- if "orgs" not in session.s3.hrm:
- # Find all organisations the current user is a staff
- # member of (+all their branches)
- user = auth.user.pe_id
- branches = s3db.pr_get_role_branches(user,
- roles="Staff",
- entity_type="org_organisation")
- otable = s3db.org_organisation
- query = (otable.pe_id.belongs(branches))
- orgs = db(query).select(otable.id)
- orgs = [org.id for org in orgs]
- if orgs:
- session.s3.hrm.orgs = orgs
- else:
- session.s3.hrm.orgs = None
-
- # Set mode
- if session.s3.hrm.mode != "personal":
- if (ADMIN in roles or session.s3.hrm.orgs) or \
- deployment_settings.get_security_policy() in (1, 2):
- session.s3.hrm.mode = None
- else:
- session.s3.hrm.mode = "personal"
-
-hrm_vars(session)
+s3db.hrm_vars()
# =============================================================================
def index():
View
@@ -33,6 +33,7 @@
"hrm_hr_represent",
"hrm_human_resource_represent",
#"hrm_position_represent",
+ "hrm_vars",
"hrm_rheader",
]
@@ -2247,6 +2248,48 @@ def reduction(a, b):
form.vars.id = id
self.hrm_certification_onaccept(form)
+# =============================================================================
+@current.auth.requires_login()
+def hrm_vars():
+ """ Set session and response variables """
+
+ s3db = current.s3db
+ session = current.session
+ hrm_vars = session.s3.hrm
+
+ settings = current.deployment_settings
+ try:
+ module_name = settings.modules[module].name_nice
+ except:
+ module_name = current.T("Human Resources Management")
+ current.response.title = module_name
+
+ # Automatically choose an organisation
+ if "orgs" not in hrm_vars:
+ # Find all organisations the current user is a staff
+ # member of (+all their branches)
+ user = current.auth.user.pe_id
+ branches = s3db.pr_get_role_branches(user,
+ roles="Staff",
+ entity_type="org_organisation")
+ otable = s3db.org_organisation
+ query = (otable.pe_id.belongs(branches))
+ orgs = current.db(query).select(otable.id)
+ orgs = [org.id for org in orgs]
+ if orgs:
+ hrm_vars.orgs = orgs
+ else:
+ hrm_vars.orgs = None
+
+ # Set mode
+ if hrm_vars.mode != "personal":
+ sr = session.s3.system_roles
+ if sr.ADMIN in session.s3.roles or \
+ hrm_vars.orgs or \
+ deployment_settings.get_security_policy() in (1, 2):
+ hrm_vars.mode = None
+ else:
+ hrm_vars.mode = "personal"
# =============================================================================
def hrm_hr_represent(id):

0 comments on commit e823997

Please sign in to comment.