Permalink
Browse files

minify, cleanup

  • Loading branch information...
1 parent 81ba345 commit 31a7f69a1aade8a74c84640d41e164a6c98f8b1a @flavour flavour committed Oct 4, 2012
View
@@ -1 +1 @@
-vita-0.5.5-devel-1839-g269c8eb (2012-10-04 15:10:35)
+81ba345 (2012-10-04 17:44:22)
View
@@ -246,6 +246,7 @@ 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
@@ -267,11 +268,13 @@ def set_project_multi_theme_id_requires(sector_ids):
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
@@ -294,20 +297,22 @@ def set_project_multi_activity_type_id_requires(sector_ids):
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]
+ 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():
""" RESTful CRUD controller """
@@ -354,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)
@@ -539,7 +544,10 @@ def represent(record, field):
csv_template="location")
# -----------------------------------------------------------------------------
def demographic_data():
+ """ RESTful CRUD controller """
+
return s3db.stats_demographic_data_controller()
+
# -----------------------------------------------------------------------------
def community_contact():
""" Show a list of all community contacts """
View
@@ -179,6 +179,7 @@ def model(self):
tooltip=help),
label=SECTOR,
ondelete="SET NULL")
+
# =====================================================================
# (Cluster) Subsector
#
View
@@ -83,12 +83,14 @@ class S3ProjectModel(S3Model):
names = ["project_status",
"project_theme",
+ "project_theme_sector",
"project_theme_id",
"project_theme_opts",
"project_hazard",
"project_hfa_opts",
"project_project",
"project_activity_type",
+ "project_activity_type_sector",
"project_project_id",
"project_multi_activity_type_id",
]
@@ -229,7 +231,22 @@ def model(self):
# Projects
add_component("project_theme_percentage", project_theme="theme_id")
+ crud_form = s3forms.S3SQLCustomForm(
+ "name",
+ # Project Organisations
+ s3forms.S3SQLInlineComponent(
+ "theme_sector",
+ label=T("Theme Sectors"),
+ fields=["sector_id"],
+ ),
+ )
+
+ configure(tablename,
+ crud_form=crud_form)
+
+ # ---------------------------------------------------------------------
# Theme - Sector Link Table
+ #
tablename = "project_theme_sector"
location = current.session.s3.location_filter
if location:
@@ -241,30 +258,18 @@ def model(self):
table = define_table(tablename,
theme_id(),
self.org_sector_id(
- requires=IS_ONE_OF(db, "org_sector.id",
- self.org_sector_represent,
- sort=True,
- filterby=filterby,
- filter_opts=filter_opts),
- ),
+ label = "",
+ requires=IS_ONE_OF(db, "org_sector.id",
+ self.org_sector_represent,
+ sort=True,
+ filterby=filterby,
+ filter_opts=filter_opts),
+ ),
*s3_meta_fields())
add_component(tablename, project_theme="theme_id")
add_component(tablename, org_sector="sector_id")
- table.sector_id.label = ""
- crud_form = s3forms.S3SQLCustomForm(
- "name",
- # Project Organisations
- s3forms.S3SQLInlineComponent(
- "theme_sector",
- label=T("Theme Sectors"),
- fields=["sector_id"],
- ),
- )
-
- configure("project_theme", crud_form=crud_form)
-
# ---------------------------------------------------------------------
# Hazard
# @ToDo: Move to link table to move to S3ProjectDRRModel
@@ -758,18 +763,27 @@ def model(self):
CheckboxesWidgetS3.widget(f, v, cols=3),
ondelete = "RESTRICT")
+ crud_form = s3forms.S3SQLCustomForm(
+ "name",
+ # Project Organisations
+ s3forms.S3SQLInlineComponent(
+ "activity_type_sector",
+ label=T("Activity Type Sectors"),
+ fields=["sector_id"],
+ ),
+ )
+
+ configure(tablename,
+ crud_form=crud_form)
+
+ # ---------------------------------------------------------------------
# Activity Type - Sector Link Table
+ #
tablename = "project_activity_type_sector"
- location = current.session.s3.location_filter
- if location:
- filterby = "location_id"
- filter_opts = (location, None)
- else:
- filterby = None
- filter_opts = (None,)
table = define_table(tablename,
activity_type_id(),
self.org_sector_id(
+ label = "",
requires=IS_ONE_OF(db, "org_sector.id",
self.org_sector_represent,
sort=True,
@@ -781,19 +795,6 @@ def model(self):
add_component(tablename, project_activity_type="activity_type_id")
add_component(tablename, org_sector="sector_id") # Doesn't Work???
- table.sector_id.label = ""
- crud_form = s3forms.S3SQLCustomForm(
- "name",
- # Project Organisations
- s3forms.S3SQLInlineComponent(
- "activity_type_sector",
- label=T("Activity Type Sectors"),
- fields=["sector_id"],
- ),
- )
-
- configure("project_activity_type", crud_form=crud_form)
-
# ---------------------------------------------------------------------
# Pass variables back to global scope (s3db.*)
#
@@ -1618,14 +1619,13 @@ def model(self):
#
tablename = "project_beneficiary"
table = define_table(tablename,
- # LINK FIELDS
+ # Link Fields
# populated automatically
project_id(readable=False,
writable=False),
project_location_id(comment=None),
- #STATS_DATA FIELDS
- #beneficiary_type
+ # stats_data Fields
super_link("data_id", "stats_data"),
beneficiary_type_param_id(),
# populated automatically
@@ -4967,9 +4967,6 @@ def project_rheader(r, tabs=[]):
rheader = S3ResourceHeader(rheader_fields, tabs)(r)
elif resourcename == "task":
- db = current.db
- s3db = current.s3db
-
# Tabs
tabs = [(T("Details"), None)]
append = tabs.append
@@ -4986,6 +4983,7 @@ def project_rheader(r, tabs=[]):
rheader_tabs = s3_rheader_tabs(r, tabs)
# RHeader
+ db = current.db
ptable = s3db.project_project
ltable = s3db.project_task_project
query = (ltable.deleted == False) & \
View
@@ -121,16 +121,15 @@ def model(self):
),
Field("value", "double",
label = T("Value")),
- Field("date", "date",
- label = T("Date")),
- Field("date_end", "date",
- label = T("End Date")),
+ s3_date(),
+ s3_date("date_end",
+ label = T("End Date")),
self.stats_group_id(),
Field("approved_by", "integer",
default = None)
)
- self.configure("stats_data",
+ self.configure(tablename,
onapprove = self.stats_data_onapprove,
requires_approval = True,
)
@@ -867,11 +866,10 @@ def stats_demographic_duplicate(item):
item.id = duplicate.id
item.method = item.METHOD.UPDATE
-
# =============================================================================
class S3StatsGroupModel(S3Model):
"""
- Table to hold the group details of the different stats records
+ Tables to hold the group details of the different stats records
"""
names = ["stats_group_type",
@@ -1122,39 +1120,36 @@ def stats_demographic_data_controller():
requests as a tab for a site.
"""
- s3db = current.s3db
- s3 = current.response.s3
- request = current.request
- settings = current.deployment_settings
-
- dtable = s3db.stats_demographic_data
+ vars = current.request.vars
output = dict()
- if "viewing" not in request.vars:
+ if "viewing" not in vars:
return output
else:
- viewing = request.vars.viewing
+ viewing = vars.viewing
if "." in viewing:
tablename, id = viewing.split(".", 1)
else:
return output
- location_id = s3db[tablename][id].location_id
-
- if tablename == "project_location":
- rheader = s3db.project_rheader
- else:
- rheader = None
+ s3db = current.s3db
+ table = s3db[tablename]
+ location_id = current.db(table.id == id).select(table.location_id,
+ limitby=(0, 1)
+ ).first().location_id
- s3.filter = (dtable.location_id == location_id)
- dtable.location_id.default = location_id
- dtable.location_id.readable = False
- dtable.location_id.writable = False
+ s3 = current.response.s3
+ dtable = s3db.stats_demographic_data
+
+ field = dtable.location_id
+ s3.filter = (field == location_id)
+ field.default = location_id
+ field.readable = False
+ field.writable = False
dtable.group_id.readable = False
dtable.group_id.writable = False
-
# Post-process
def postp(r, output):
@@ -1163,7 +1158,13 @@ def postp(r, output):
return output
s3.postp = postp
- output = current.rest_controller("stats", "demographic_data", rheader = rheader)
+ if tablename == "project_location":
+ rheader = s3db.project_rheader
+ else:
+ rheader = None
+
+ output = current.rest_controller("stats", "demographic_data",
+ rheader=rheader)
return output
@@ -140,22 +140,21 @@ def model(self):
table = define_table(tablename,
super_link("data_id", "stats_data"),
self.stats_param_id(
- label = T("Indicator"),
- requires = IS_ONE_OF(db, "stats_parameter.parameter_id",
- self.stats_parameter_represent,
- filterby="instance_type",
- filter_opts=["vulnerability_indicator"],
- orderby="stats_parameter.name",
- sort=True)
+ label = T("Indicator"),
+ requires = IS_ONE_OF(db, "stats_parameter.parameter_id",
+ self.stats_parameter_represent,
+ filterby="instance_type",
+ filter_opts=["vulnerability_indicator"],
+ orderby="stats_parameter.name",
+ sort=True)
),
self.gis_location_id(
widget = S3LocationAutocompleteWidget(),
requires = IS_LOCATION()
),
Field("value", "double",
label = T("Value")),
- Field("date", "date",
- label = T("Date")),
+ s3_date(),
# Unused but needed for the stats_data SE
Field("date_end", "date",
readable=False,
@@ -3,7 +3,7 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- **********************************************************************
- Themes - CSV Import Stylesheet
+ Project Activity Types - CSV Import Stylesheet
CSV column...........Format..........Content
@@ -3,7 +3,7 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- **********************************************************************
- Themes - CSV Import Stylesheet
+ Project Themes - CSV Import Stylesheet
CSV column...........Format..........Content
Oops, something went wrong.

0 comments on commit 31a7f69

Please sign in to comment.