Permalink
Browse files

Merge branch 'master' of git://github.com/flavour/eden

  • Loading branch information...
2 parents f2434de + 31a7f69 commit 5f3c28e4eeefb3b00ce2b7f9a46318b5738ad8ab @flavour committed Oct 4, 2012
Showing with 1,347 additions and 714 deletions.
  1. +97 −2 controllers/project.py
  2. +5 −6 modules/eden/asset.py
  3. +4 −9 modules/eden/gis.py
  4. +2 −6 modules/eden/hrm.py
  5. +20 −20 modules/eden/inv.py
  6. +3 −7 modules/eden/member.py
  7. +21 −20 modules/eden/org.py
  8. +9 −6 modules/eden/pr.py
  9. +189 −91 modules/eden/project.py
  10. +65 −7 modules/eden/stats.py
  11. +13 −9 modules/eden/vulnerability.py
  12. +27 −40 modules/s3/s3aaa.py
  13. +14 −4 modules/s3/s3crud.py
  14. +30 −6 modules/s3/s3forms.py
  15. +69 −56 modules/s3/s3import.py
  16. +1 −1 modules/s3/s3search.py
  17. +3 −2 modules/s3/s3widgets.py
  18. +2 −2 modules/tests/project/create_project.py
  19. +1 −1 modules/unit_tests/eden/pr.py
  20. +47 −4 modules/unit_tests/s3/s3aaa.py
  21. +127 −31 private/templates/IFRC/project_activity_type.csv
  22. +67 −27 private/templates/IFRC/project_theme.csv
  23. +100 −100 private/templates/IFRC_Demo/project_location.csv
  24. +10 −7 static/formats/s3csv/cr/shelter.xsl
  25. +10 −7 static/formats/s3csv/hrm/person.xsl
  26. +10 −7 static/formats/s3csv/inv/warehouse.xsl
  27. +10 −7 static/formats/s3csv/member/person.xsl
  28. +10 −7 static/formats/s3csv/org/office.xsl
  29. +10 −7 static/formats/s3csv/org/organisation.xsl
  30. +1 −1 static/formats/s3csv/project/activity.xsl
  31. +37 −2 static/formats/s3csv/project/activity_type.xsl
  32. +1 −1 static/formats/s3csv/project/beneficiary_type.csv
  33. +1 −0 static/formats/s3csv/project/beneficiary_type.xsl
  34. +3 −3 static/formats/s3csv/project/location.xsl
  35. +35 −1 static/formats/s3csv/project/theme.xsl
  36. +10 −7 static/formats/s3csv/scenario/scenario.xsl
  37. +203 −118 static/scripts/S3/S3.js
  38. +69 −68 static/scripts/S3/S3.min.js
  39. +11 −14 static/scripts/S3/s3.search.js
View
@@ -101,8 +101,17 @@ def postp(r, output):
# Pre-process
def prep(r):
+ table = s3db.project_project
+
# Location Filter
s3db.gis_location_filter(r)
+
+ # Filter Themes based on Sector
+ if r.record:
+ sector_ids = r.record.sector_id
+ else:
+ sector_ids = []
+ set_project_multi_theme_id_requires(sector_ids)
if r.interactive:
if not r.component:
@@ -138,6 +147,10 @@ def prep(r):
(ttable.tag == "ISO2")
countries = db(query).select(ttable.value)
settings.gis.countries = [c.value for c in countries]
+
+ # Filter Activity Type based on Sector
+ set_project_multi_activity_type_id_requires(sector_ids)
+ #@ToDo: Do this for project_activity too.
elif r.component_name == "task":
r.component.table.milestone_id.requires = IS_NULL_OR(IS_ONE_OF(db,
"project_milestone.id",
@@ -228,6 +241,77 @@ def postp(r, output):
"project", # Need to specify as sometimes we come via index()
rheader=rheader,
csv_template="project")
+# -----------------------------------------------------------------------------
+def set_project_multi_theme_id_requires(sector_ids):
+ """
+ Filters the multi_theme_id based on the sector_id
+ """
+
+ table = s3db.project_project
+ ttable = s3db.project_theme
+ tstable = s3db.project_theme_sector
+
+ # All themes linked to the projects sectors or to no sectors
+ rows = db().select(ttable.id,
+ tstable.sector_id,
+ left=tstable.on(ttable.id == tstable.theme_id))
+ theme_ids = [row.project_theme.id for row in rows
+ if not row.project_theme_sector.sector_id or
+ row.project_theme_sector.sector_id[0] in sector_ids]
+ table.multi_theme_id.requires = IS_NULL_OR(
+ IS_ONE_OF(db,
+ "project_theme.id",
+ s3db.project_theme_represent,
+ filterby="id",
+ filter_opts=theme_ids,
+ sort=True,
+ multiple=True
+ )
+ )
+
+# -----------------------------------------------------------------------------
+def set_project_multi_activity_type_id_requires(sector_ids):
+ """
+ Filters the multi_activity_type_id based on the sector_id
+ """
+
+ # @ToDo: merge with set_project_multi_theme_id_requires?
+ table = s3db.project_location
+ attable = s3db.project_activity_type
+ atstable = s3db.project_activity_type_sector
+
+ # All activity_types linked to the projects sectors or to no sectors
+ rows = db().select(attable.id,
+ atstable.sector_id,
+ left=atstable.on(attable.id == atstable.activity_type_id))
+ activity_type_ids = [row.project_activity_type.id for row in rows
+ if not row.project_activity_type_sector.sector_id or
+ row.project_activity_type_sector.sector_id[0] in sector_ids]
+ table.multi_activity_type_id.requires = IS_NULL_OR(
+ IS_ONE_OF(db,
+ "project_activity_type.id",
+ s3db.project_activity_type_represent,
+ filterby="id",
+ filter_opts=activity_type_ids,
+ sort=True,
+ multiple=True
+ )
+ )
+
+# -----------------------------------------------------------------------------
+def project_multi_theme_id_widget():
+ """
+ Used by the project controller to return dynamically generated
+ multi_theme_id widget based on sector_id
+ """
+ ptable = s3db.project_project
+ sector_ids = [int(id) for id in request.vars.sector_ids.split(",") if id]
+ value = [int(id) for id in request.vars.value.split(",") if id]
+
+ set_project_multi_theme_id_requires(sector_ids)
+ widget = ptable.multi_theme_id.widget(ptable.multi_theme_id,
+ value)
+ return widget
# =============================================================================
def status():
@@ -275,7 +359,7 @@ def organisation():
(T("Basic Details"), None),
(T("Projects"), "project"),
(T("Contacts"), "human_resource"),
- ]
+ ]
rheader = lambda r: s3db.org_rheader(r, tabs)
return s3_rest_controller("org", resourcename,
rheader=rheader)
@@ -373,7 +457,13 @@ def location():
# Pre-process
def prep(r):
if r.interactive:
- if r.component is not None:
+ if r.record and r.record.project_id:
+ sector_ids = ptable[r.record.project_id].sector_id
+ else:
+ sector_ids = []
+ set_project_multi_activity_type_id_requires(sector_ids)
+
+ if r.component:
if r.component_name == "document":
doc_table = s3db.doc_document
doc_table.organisation_id.readable = False
@@ -452,6 +542,11 @@ def represent(record, field):
return s3_rest_controller(interactive_report=True,
rheader=s3db.project_rheader,
csv_template="location")
+# -----------------------------------------------------------------------------
+def demographic_data():
+ """ RESTful CRUD controller """
+
+ return s3db.stats_demographic_data_controller()
# -----------------------------------------------------------------------------
def community_contact():
View
@@ -162,6 +162,7 @@ def model(self):
'Field':'site_id',
'FieldResource':'site',
'FieldPrefix':'org',
+ 'FieldID':'site_id'
})
})'''),),
# This is a component, so needs to be a super_link
@@ -344,7 +345,10 @@ def model(self):
#"L2",
#"L3",
"comments",
- ])
+ ],
+ realm_components = ["log", "presence"],
+ update_realm = True,
+ )
# Log as component of Assets
add_component("asset_log", asset_asset="asset_id")
@@ -576,11 +580,6 @@ def asset_onaccept(form):
vars = form.vars
atable = db.asset_asset
- # Update asset realm_entity and components' realm_entity
- auth.set_realm_entity(atable, vars, force_update=True)
- auth.set_component_realm_entity(atable, vars,
- update_components = ["log", "presence"])
-
site_id = vars.get("site_id", None)
if site_id:
asset_id = vars.id
View
@@ -1369,10 +1369,7 @@ def model(self):
onvalidation=self.gis_config_onvalidation,
onaccept=self.gis_config_onaccept,
create_next=URL(args=["[id]", "layer_entity"]),
- # @ToDo: Not currently allowing delete, but with some
- # restrictions, we could.
- #delete_onaccept=self.gis_config_ondelete,
- update_ondelete=self.gis_config_ondelete,
+ ondelete=self.gis_config_ondelete,
subheadings = {
T("Map Settings"): "zoom",
T("Form Settings"): "default_location_id",
@@ -1683,16 +1680,14 @@ def gis_config_onaccept(form):
# -------------------------------------------------------------------------
@staticmethod
- def gis_config_ondelete(form):
+ def gis_config_ondelete(row):
"""
If the currently-active config was deleted, clear the cache
"""
- record_id = form.record_id
s3 = current.response.s3
- if s3.gis.config:
- gis_config_id = s3.gis.config.id
- if record_id == gis_config_id:
+ if s3.gis.config and \
+ s3.gis.config.id == row.id:
s3.gis.config = None
# -------------------------------------------------------------------------
View
@@ -472,6 +472,8 @@ def model(self):
),
create_next = hrm_url,
update_next = hrm_url,
+ realm_components = ["presence"],
+ update_realm = True,
)
# ---------------------------------------------------------------------
@@ -3262,9 +3264,6 @@ def hrm_human_resource_onaccept(form):
# Affiliation, record ownership and component ownership
s3db.pr_update_affiliations(htable, record)
- auth.set_realm_entity(htable, record, force_update=True)
- auth.set_component_realm_entity(htable, vars,
- update_components = ["presence"])
# Realm_entity for the pr_person record
ptable = s3db.pr_person
@@ -3278,9 +3277,6 @@ def hrm_human_resource_onaccept(form):
auth.set_realm_entity(ptable, person,
entity = entity,
force_update = True)
- auth.set_component_realm_entity(ptable, person,
- entity = entity,
- update_components = ["presence"])
site_id = record.site_id
site_contact = record.site_contact
View
@@ -286,7 +286,26 @@ def model(self):
#"location_id$L4",
"phone1",
"email"
- ])
+ ],
+ realm_components = ["contact_emergency",
+ "physical_description",
+ "config",
+ "image",
+ "req",
+ "send",
+ "human_resource_site",
+ "note",
+ "contact",
+ "role",
+ "asset",
+ "commit",
+ "inv_item",
+ "document",
+ "recv",
+ "address",
+ ],
+ update_realm = True,
+ )
# ---------------------------------------------------------------------
# Pass variables back to global scope (s3db.*)
@@ -341,25 +360,6 @@ def inv_warehouse_onaccept(form):
# Affiliation, record ownership and component ownership
s3db.pr_update_affiliations(wtable, vars)
- auth.set_realm_entity(wtable, vars, force_update=True)
- auth.set_component_realm_entity(wtable, vars,
- update_components = ["contact_emergency",
- "physical_description",
- "config",
- "image",
- "req",
- "send",
- "human_resource_site",
- "note",
- "contact",
- "role",
- "asset",
- "commit",
- "inv_item",
- "document",
- "recv",
- "address",
- ])
# ---------------------------------------------------------------------
@staticmethod
View
@@ -265,7 +265,9 @@ def member_type_opts():
"location_id$L2",
"location_id$L3",
"location_id$L4",
- ])
+ ],
+ update_realm=True,
+ )
# ---------------------------------------------------------------------
# Pass variables back to global scope (s3db.*)
@@ -338,8 +340,6 @@ def member_onaccept(form):
# Affiliation, record ownership and component ownership
s3db.pr_update_affiliations(mtable, record)
- auth.set_realm_entity(mtable, record, force_update=True)
- auth.set_component_realm_entity(mtable, record)
# realm_entity for the pr_person record
person_id = record.person_id
@@ -352,10 +352,6 @@ def member_onaccept(form):
auth.set_realm_entity(ptable, person,
entity = entity,
force_update = True)
- auth.set_component_realm_entity(ptable, person,
- entity = entity,
- update_components = [])
-
# Update the location ID from the Home Address
atable = s3db.pr_address
View
@@ -687,6 +687,7 @@ def model(self):
return Storage(
org_sector_id=sector_id,
org_sector_opts=self.org_sector_opts,
+ org_sector_represent = self.org_sector_represent,
org_organisation_type_id=organisation_type_id,
org_organisation_id=organisation_id,
)
@@ -1024,9 +1025,9 @@ def org_branch_duplicate(item):
def org_branch_onvalidation(form):
"""
Prevent an Organisation from being a Branch of itself
+ - this is for interactive forms, imports are caught in .xsl
"""
- # @ToDo: This ctaches manual creation but need to catch Imports somehow
vars = form.request_vars
if vars and \
vars.branch_id and \
@@ -1915,7 +1916,25 @@ def model(self):
#"location_id$L4",
"phone1",
"email"
- ])
+ ],
+ realm_components=["contact_emergency",
+ "config",
+ "image",
+ "req",
+ "send",
+ "human_resource_site",
+ "note",
+ "contact",
+ "role",
+ "asset",
+ "commit",
+ "inv_item",
+ "document",
+ "recv",
+ "address",
+ ],
+ update_realm=True,
+ )
if current.deployment_settings.get_org_summary():
add_component("org_office_summary",
@@ -1997,24 +2016,6 @@ def org_office_onaccept(form):
# Affiliation, record ownership and component ownership
s3db.pr_update_affiliations(otable, vars)
- auth.set_realm_entity(otable, vars, force_update=True)
- auth.set_component_realm_entity(otable, vars,
- update_components = ["contact_emergency",
- "config",
- "image",
- "req",
- "send",
- "human_resource_site",
- "note",
- "contact",
- "role",
- "asset",
- "commit",
- "inv_item",
- "document",
- "recv",
- "address",
- ])
if current.deployment_settings.get_org_summary():
Oops, something went wrong.

0 comments on commit 5f3c28e

Please sign in to comment.