Skip to content

Commit

Permalink
CRMT: Add Coalitions to Orgs on import too, Orgs should have default
Browse files Browse the repository at this point in the history
coalition filter
  • Loading branch information
flavour committed Jul 3, 2014
1 parent 5b9541d commit bd800e6
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 38 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nursix-1.1.0-devel-679-gba47c7b (2014-07-03 10:07:02)
5b9541d (2014-07-03 10:47:10)
71 changes: 40 additions & 31 deletions modules/s3db/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2448,35 +2448,37 @@ def model(self):
layer_id = self.super_link("layer_id", "gis_layer_entity",
label = T("Layer"),
represent = gis_layer_represent,
readable=True, writable=True)
readable=True,
writable=True,
)

# Components
add_components(tablename,
# Configs
gis_config={"link": "gis_layer_config",
"pkey": "layer_id",
"joinby": "layer_id",
"key": "config_id",
"actuate": "hide",
"autocomplete": "name",
"autodelete": False,
},
# Symbologies
gis_symbology={"link": "gis_layer_symbology",
"pkey": "layer_id",
"joinby": "layer_id",
"key": "symbology_id",
"actuate": "hide",
"autocomplete": "name",
"autodelete": False,
gis_config = {"link": "gis_layer_config",
"pkey": "layer_id",
"joinby": "layer_id",
"key": "config_id",
"actuate": "hide",
"autocomplete": "name",
"autodelete": False,
},
# Symbologies
gis_symbology = {"link": "gis_layer_symbology",
"pkey": "layer_id",
"joinby": "layer_id",
"key": "symbology_id",
"actuate": "hide",
"autocomplete": "name",
"autodelete": False,
},
# Posts
cms_post={"link": "cms_post_layer",
"pkey": "layer_id",
"joinby": "layer_id",
"key": "post_id",
},
)
cms_post = {"link": "cms_post_layer",
"pkey": "layer_id",
"joinby": "layer_id",
"key": "post_id",
},
)

# =====================================================================
# Layer Config link table
Expand Down Expand Up @@ -2510,15 +2512,21 @@ def model(self):
define_table(tablename,
layer_id,
self.gis_config_id(),
Field("enabled", "boolean", default=True,
Field("enabled", "boolean",
default = True,
label = T("Available in Viewer?"),
represent = s3_yes_no_represent,
label=T("Available in Viewer?")),
Field("visible", "boolean", default=True,
),
Field("visible", "boolean",
default = True,
label = T("On by default?"),
represent = s3_yes_no_represent,
label=T("On by default?")),
Field("base", "boolean", default=False,
),
Field("base", "boolean",
default = False,
label = T("Default Base layer?"),
represent = s3_yes_no_represent,
label=T("Default Base layer?")),
),
# @ToDo: Move to style_id
# @ToDo: Switch type to "json" & Test
Field("style", "text",
Expand Down Expand Up @@ -2549,8 +2557,9 @@ def model(self):
)

self.configure(tablename,
onvalidation=self.gis_layer_config_onvalidation,
onaccept=self.gis_layer_config_onaccept)
onvalidation = self.gis_layer_config_onvalidation,
onaccept = self.gis_layer_config_onaccept,
)

# =====================================================================
# Layer Symbology link table
Expand Down
6 changes: 4 additions & 2 deletions modules/s3db/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ def model(self):
represent = S3Represent(lookup=tablename)
status_id = S3ReusableField("status_id", "reference %s" % tablename,
label = T("Status"),
ondelete = "RESTRICT",
ondelete = "SET NULL",
represent = represent,
requires = IS_EMPTY_OR(
IS_ONE_OF(db, "org_group_membership_status.id",
Expand All @@ -1345,7 +1345,9 @@ def model(self):
#
tablename = "org_group_membership"
define_table(tablename,
group_id(empty = False),
group_id(empty = False,
ondelete = "CASCADE",
),
self.org_organisation_id(empty = False,
ondelete = "CASCADE",
),
Expand Down
44 changes: 41 additions & 3 deletions private/templates/CRMT/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ def org_facility_types(row):
"""
The Types of the Facility
- required since we can't have a component within an Inline Component
UNUSED
"""

if hasattr(row, "org_facility"):
Expand Down Expand Up @@ -878,6 +879,13 @@ def org_organisation_postprocess(form):
# -----------------------------------------------------------------------------
def customise_org_organisation_controller(**attr):

if "summary" in current.request.args:
settings.gis.toolbar = False
from s3.s3utils import s3_set_default_filter
s3_set_default_filter("org_group_membership.group_id",
default_coalition_filter,
tablename = "org_organisation")

# Custom PreP
s3 = current.response.s3
standard_prep = s3.prep
Expand Down Expand Up @@ -1294,9 +1302,38 @@ def facility_onaccept(form):
if match:
break
if match:
ltable.insert(group_id=p[ctable].id,
site_id=site_id,
group_id = p[ctable].id
ltable.insert(group_id = group_id,
site_id = site_id,
)
# Also update the Organisation
stable = db.org_site
site = db(stable.id == site_id).select(stable.organisation_id,
limitby = (0, 1)
).first()
if not site:
return
organisation_id = site.organisation_id
ltable = db.org_group_membership
query = (ltable.organisation_id == organisation_id) & \
(ltable.group_id == group_id)
exists = db(query).select(ltable.id,
limitby=(0, 1))
if not exists:
stable = db.org_group_membership_status
status = db(stable.name == "Located within Coalition").select(stable.id,
cache = s3db.cache,
limitby = (0, 1)
).first()
if status:
status_id = status.id
else:
# Prepop failed or Status deleted/renamed
status_id = None
ltable.insert(group_id = group_id,
organisation_id = organisation_id,
status_id = status_id,
)

# Normal onaccept:
# Update Affiliation, record ownership and component ownership
Expand All @@ -1308,6 +1345,7 @@ def facility_onaccept(form):
},
}

#-----------------------------------------------------------------------------
def customise_org_facility_controller(**attr):

if "summary" in current.request.args:
Expand Down Expand Up @@ -1519,7 +1557,7 @@ def custom_prep(r):
settings.customise_org_facility_controller = customise_org_facility_controller

# -----------------------------------------------------------------------------
# People
# People (Stats People)
#
def customise_stats_people_controller(**attr):

Expand Down
3 changes: 2 additions & 1 deletion private/templates/CRMT/org_group_membership_status.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Name,Description
Recorded,
Contacted,
Member,
Member,
Located within Coalition,

0 comments on commit bd800e6

Please sign in to comment.