Browse files

minify, cleanup

  • Loading branch information...
1 parent 81ba345 commit 31a7f69a1aade8a74c84640d41e164a6c98f8b1a @flavour committed Oct 4, 2012
View
2 VERSION
@@ -1 +1 @@
-vita-0.5.5-devel-1839-g269c8eb (2012-10-04 15:10:35)
+81ba345 (2012-10-04 17:44:22)
View
14 controllers/project.py
@@ -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
1 modules/eden/org.py
@@ -179,6 +179,7 @@ def model(self):
tooltip=help),
label=SECTOR,
ondelete="SET NULL")
+
# =====================================================================
# (Cluster) Subsector
#
View
88 modules/eden/project.py
@@ -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
55 modules/eden/stats.py
@@ -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
View
17 modules/eden/vulnerability.py
@@ -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,
View
2 static/formats/s3csv/project/activity_type.xsl
@@ -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
View
2 static/formats/s3csv/project/theme.xsl
@@ -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
View
336 static/scripts/S3/S3.js
@@ -583,16 +583,16 @@ function S3FilterFieldChange (setting) {
var selField = $('[name = "' + Field + '"]');
//var selFieldRows = $('[id *= "' + Field + '__row"]');
- if (setting.FilterOnLoad != undefined) {
- var FilterOnLoad = setting.FilterOnLoad;
- } else {
- var FilterOnLoad = true;
+ if (setting.FilterOnLoad != undefined) {
+ var FilterOnLoad = setting.FilterOnLoad;
+ } else {
+ var FilterOnLoad = true;
}
- selFilterField.change( function() {
+ selFilterField.change(function() {
- // Cancel previous request
- try {
+ // Cancel previous request
+ try {
S3.JSONRequest[$(this).attr('id')].abort();
} catch(err) {};
@@ -610,45 +610,45 @@ function S3FilterFieldChange (setting) {
});
}
- if ( FilterVal == "" || FilterVal == undefined) {
- // No value to filter
- //selFieldRows.hide();
- selField.attr('disabled', 'disabled');
- return;
- }
-
- var FieldResource = setting.FieldResource;
-
- if (setting.Widget != undefined) {
- var Widget = setting.Widget;
- } else {
- var Widget = Field;
- }
- var selWidget = $('[name = "' + Widget + '"]');
-
- if (setting.FieldKey != undefined) {
- var FieldKey = setting.FieldKey;
- } else {
- var FieldKey = FilterField;
- }
-
- var FieldID = setting.FieldID;
- if (FieldID == undefined) {
- var FieldID = "id";
- }
-
- if (setting.url != undefined && setting.url != null) {
- var url = setting.url
- } else {
- var FieldPrefix = setting.FieldPrefix;
- var url = S3.Ap.concat('/', FieldPrefix, '/', FieldResource, '.json?',
- FieldResource, '.', FieldKey, '=' );
- }
- url = url.concat(FilterVal)
-
+ if ( FilterVal == "" || FilterVal == undefined) {
+ // No value to filter
+ //selFieldRows.hide();
+ selField.attr('disabled', 'disabled');
+ return;
+ }
+
+ var FieldResource = setting.FieldResource;
+
+ if (setting.Widget != undefined) {
+ var Widget = setting.Widget;
+ } else {
+ var Widget = Field;
+ }
+ var selWidget = $('[name = "' + Widget + '"]');
+
+ if (setting.FieldKey != undefined) {
+ var FieldKey = setting.FieldKey;
+ } else {
+ var FieldKey = FilterField;
+ }
+
+ var FieldID = setting.FieldID;
+ if (FieldID == undefined) {
+ var FieldID = "id";
+ }
+
+ if (setting.url != undefined && setting.url != null) {
+ var url = setting.url
+ } else {
+ var FieldPrefix = setting.FieldPrefix;
+ var url = S3.Ap.concat('/', FieldPrefix, '/', FieldResource, '.json?',
+ FieldResource, '.', FieldKey, '=' );
+ }
+ url = url.concat(FilterVal)
+
// Get Field Val from Select or CheckBoxes
if (selField.length == 0 || selField.length == undefined ) {
- FieldVal = ""
+ FieldVal = ""
} else if (selField.length == 1) {
FieldVal = selField.val();
} else {
@@ -657,130 +657,132 @@ function S3FilterFieldChange (setting) {
FieldVal.push($(this).val());
});
}
- if (url.indexOf("?")) {
- url = url.concat("&value=");
- } else {
- url = url.concat("?value=");
- }
- url = url.concat(FieldVal);
-
- var GetWidgetHTML = setting.GetWidgetHTML;
- if (GetWidgetHTML == undefined) {
- var GetWidgetHTML = false;
- }
-
- if (setting.ShowEmptyField != undefined) {
- var ShowEmptyField = setting.ShowEmptyField;
- } else {
- var ShowEmptyField = true;
- }
- if (setting.msgNoRecords != undefined) {
- var msgNoRecords = setting.msgNoRecords;
- } else {
- var msgNoRecords = '-';
- setting.msgNoRecords = msgNoRecords;
- }
- if (setting.fncPrep != undefined) {
- var fncPrep = setting.fncPrep;
- } else {
- var fncPrep = function(data) {return null};
- setting.fncPrep = fncPrep;
- }
- if (setting.fncRepresent != undefined) {
- var fncRepresent = setting.fncRepresent;
- } else {
- var fncRepresent = function(record) {return record.name};
- setting.fncRepresent = fncRepresent;
- }
-
- //if ($('[id$="' + FilterField + '__row1"]:visible').length > 0) {
- // Only show if the filter field is shown
- //selFieldRows.show();
- //}
-
- /* Show Throbber */
- selWidget.hide();
- if ($('#' + FieldResource + '_ajax_throbber').length == 0 ) {
- selWidget.after('<div id="' + FieldResource + '_ajax_throbber" class="ajax_throbber"/>')
- }
-
- var data;
-
- // Save JSON Request by element id
- if (!GetWidgetHTML) {
- S3.JSONRequest[$(this).attr('id')] = $.ajax( {
- url: url,
- dataType: 'json',
- context: setting,
- success: function(data) {
- /* Create Select Element */
- var options = '';
- var FilterField = this.FilterField;
- var FieldResource = this.FieldResource;
- var selField = $('[name = "' + this.Field + '"]');
- var selFilterField = $('[name = "' + FilterField + '"]');
-
- PrepResult = fncPrep(data);
-
- if (data.length == 0) {
- if (ShowEmptyField) {
- var first_value = 0;
- options += '<option value="">' + this.msgNoRecords + '</options>';
- }
- } else {
- for (var i = 0; i < data.length; i++) {
- if (i == 0) {first_value = data[i][FieldID]};
- options += '<option value="' + data[i][FieldID] + '">';
- options += this.fncRepresent( data[i], PrepResult);
- options += '</option>';
- }
- }
- /* Set field value */
- if (options != '') {
- selField.html(options)
- .val(first_value)
- .change()
- .removeAttr('disabled')
- .show();
- } else {
- //selFieldRows.hide();
- selField.attr('disabled', 'disabled');
- }
- /* Show "Add" Button & modify link */
- selFieldAdd = $('#' + FieldResource + '_add')
- href = selFieldAdd.attr('href') + "&' + FilterField + '=" + $('[name = "' + FilterField + '"]').val();
- selFieldAdd.attr('href', href)
- .show();
+ if (url.indexOf("?")) {
+ url = url.concat("&value=");
+ } else {
+ url = url.concat("?value=");
+ }
+ url = url.concat(FieldVal);
+
+ var GetWidgetHTML = setting.GetWidgetHTML;
+ if (GetWidgetHTML == undefined) {
+ var GetWidgetHTML = false;
+ }
+
+ if (setting.ShowEmptyField != undefined) {
+ var ShowEmptyField = setting.ShowEmptyField;
+ } else {
+ var ShowEmptyField = true;
+ }
+ if (setting.msgNoRecords != undefined) {
+ var msgNoRecords = setting.msgNoRecords;
+ } else {
+ var msgNoRecords = '-';
+ setting.msgNoRecords = msgNoRecords;
+ }
+ if (setting.fncPrep != undefined) {
+ var fncPrep = setting.fncPrep;
+ } else {
+ var fncPrep = function(data) {return null};
+ setting.fncPrep = fncPrep;
+ }
+ if (setting.fncRepresent != undefined) {
+ var fncRepresent = setting.fncRepresent;
+ } else {
+ var fncRepresent = function(record) {return record.name};
+ setting.fncRepresent = fncRepresent;
+ }
+
+ //if ($('[id$="' + FilterField + '__row1"]:visible').length > 0) {
+ // Only show if the filter field is shown
+ //selFieldRows.show();
+ //}
+
+ /* Show Throbber */
+ selWidget.hide();
+ if ($('#' + FieldResource + '_ajax_throbber').length == 0 ) {
+ selWidget.after('<div id="' + FieldResource + '_ajax_throbber" class="ajax_throbber"/>')
+ }
+
+ var data;
+
+ // Save JSON Request by element id
+ if (!GetWidgetHTML) {
+ S3.JSONRequest[$(this).attr('id')] = $.ajax( {
+ url: url,
+ dataType: 'json',
+ context: setting,
+ success: function(data) {
+ /* Create Select Element */
+ var options = '';
+ var FilterField = this.FilterField;
+ var FieldResource = this.FieldResource;
+ var selField = $('[name = "' + this.Field + '"]');
+ var selFilterField = $('[name = "' + FilterField + '"]');
+
+ PrepResult = fncPrep(data);
+
+ if (data.length == 0) {
+ if (ShowEmptyField) {
+ var first_value = 0;
+ options += '<option value="">' + this.msgNoRecords + '</options>';
+ }
+ } else {
+ for (var i = 0; i < data.length; i++) {
+ if (i == 0) {
+ first_value = data[i][FieldID]
+ };
+ options += '<option value="' + data[i][FieldID] + '">';
+ options += this.fncRepresent( data[i], PrepResult);
+ options += '</option>';
+ }
+ }
+ /* Set field value */
+ if (options != '') {
+ selField.html(options)
+ .val(first_value)
+ .change()
+ .removeAttr('disabled')
+ .show();
+ } else {
+ //selFieldRows.hide();
+ selField.attr('disabled', 'disabled');
+ }
+ /* Show "Add" Button & modify link */
+ selFieldAdd = $('#' + FieldResource + '_add')
+ href = selFieldAdd.attr('href') + "&' + FilterField + '=" + $('[name = "' + FilterField + '"]').val();
+ selFieldAdd.attr('href', href)
+ .show();
- /* Remove Throbber */
- $('#' + FieldResource + '_ajax_throbber').remove();
- }
- });
- } else {
- S3.JSONRequest[$(this).attr('id')] = $.ajax( {
- url: url,
- dataType: 'html',
- context: setting,
- success: function(data) {
- /* Replace widget with data */
- var selField = $('[name = "' + this.Field + '"]');
-
- /* Set field widget */
- if (data != '') {
- selWidget.html(data)
- .change()
- .removeAttr('disabled')
- .show();
- } else {
- //selFieldRows.hide();
- selWidget.attr('disabled', 'disabled');
- }
-
- /* Remove Throbber */
- $('#' + FieldResource + '_ajax_throbber').remove();
- }
- });
- }
+ /* Remove Throbber */
+ $('#' + FieldResource + '_ajax_throbber').remove();
+ }
+ });
+ } else {
+ S3.JSONRequest[$(this).attr('id')] = $.ajax( {
+ url: url,
+ dataType: 'html',
+ context: setting,
+ success: function(data) {
+ /* Replace widget with data */
+ var selField = $('[name = "' + this.Field + '"]');
+
+ /* Set field widget */
+ if (data != '') {
+ selWidget.html(data)
+ .change()
+ .removeAttr('disabled')
+ .show();
+ } else {
+ //selFieldRows.hide();
+ selWidget.attr('disabled', 'disabled');
+ }
+
+ /* Remove Throbber */
+ $('#' + FieldResource + '_ajax_throbber').remove();
+ }
+ });
+ }
});
// If the field value is empty
View
137 static/scripts/S3/S3.min.js
69 additions, 68 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
13 static/scripts/S3/s3.search.js
@@ -231,7 +231,7 @@ $(document).ready(function() {
Hide all the expanding/collapsing letter widgets that don't have
any options selected
*/
- $('.search_select_letter_label,.s3-grouped-checkboxes-widget-label').live("click", function(event) {
+ $('.search_select_letter_label,.s3-grouped-checkboxes-widget-label').live('click', function(event) {
/*
Listen for click events on the expanding/collapsing letter widgets
*/
@@ -244,18 +244,17 @@ $(document).ready(function() {
if ($(':checked', widget).length < 1) {
$(this).click();
}
- })
- ;
+ });
/* Search AutoComplete */
// Events to capture autocomplete input
- $('div.simple-form').keyup( S3.search.AutocompleteTimer )
- .click( S3.search.AutocompleteTimer )
+ $('div.simple-form').keyup(S3.search.AutocompleteTimer)
+ .click(S3.search.AutocompleteTimer)
.keypress(S3.search.CancelEnterPress);
- $('div.advanced-form').keyup( S3.search.AutocompleteTimer )
- .click( S3.search.AutocompleteTimer )
+ $('div.advanced-form').keyup(S3.search.AutocompleteTimer)
+ .click(S3.search.AutocompleteTimer)
.keypress(S3.search.ancelEnterPress);
// Select Item for Autocomplete

0 comments on commit 31a7f69

Please sign in to comment.