diff --git a/modules/templates/SAMBRO/config.py b/modules/templates/SAMBRO/config.py index d5948d1cc3..2b88c4f7ec 100644 --- a/modules/templates/SAMBRO/config.py +++ b/modules/templates/SAMBRO/config.py @@ -50,6 +50,7 @@ def onaccept(form): s3db.msg_parser_enable(_id) async = current.s3task.async + # Poll async("msg_poll", args=["msg_rss_channel", channel_id]) diff --git a/modules/templates/SAMBRO/controllers.py b/modules/templates/SAMBRO/controllers.py index a646553e93..8ef0173eb2 100644 --- a/modules/templates/SAMBRO/controllers.py +++ b/modules/templates/SAMBRO/controllers.py @@ -7,14 +7,63 @@ import simplejson as json # try external module except: import gluon.contrib.simplejson as json # fallback to pure-Python module - from gluon import current from gluon.html import * from gluon.storage import Storage from s3 import S3LocationFilter, S3OptionsFilter, S3FilterForm, S3CustomController -THEME = "CAP" +THEME = "SAMBRO" + +# ============================================================================= +class index(S3CustomController): + """ Custom Home Page """ + + def __call__(self): + response = current.response + s3 = response.s3 + T = current.T + + map = current.gis.show_map() + + output = {} + output["map"] = map + + # Image Carousel + # Latest 4 Events and Alerts + from s3.s3query import FS + s3db = current.s3db + layout = s3.render_posts + list_id = "news_datalist" + limit = 4 + list_fields = ["series_id", + "location_id", + "date", + "body", + "created_by", + "created_by$organisation_id", + "document.file", + "event_post.event_id", + ] + + resource = s3db.resource("cms_post") + resource.add_filter(FS("series_id$name") == "Event") + # Only show Future Events + resource.add_filter(resource.table.date >= current.request.now) + # Order with next Event first + orderby = "date" + output["events"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) + + resource = s3db.resource("cms_post") + resource.add_filter(FS("series_id$name") == "Alert") + # Order with most recent Alert first + orderby = "date desc" + output["alerts"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) + + + self._view(THEME, "index.html") + + return output # ============================================================================= class subscriptions(S3CustomController): @@ -37,8 +86,7 @@ def __call__(self): # Available resources resources = [dict(resource="cap_alert", url="cap/alert", - label=T("Updates")), - ] + label=T("Updates")),] # Filter widgets # @note: subscription manager has no resource context, so @@ -49,23 +97,19 @@ def __call__(self): options = s3db.cap_info_category_opts, represent = "%(name)s", resource = "cap_info", - _name = "category-filter", - ), + _name = "category-filter",), S3LocationFilter("location_id", label = T("Location(s)"), levels = ("L0",), resource = "cap_area_location", options = gis.get_countries().keys(), - _name = "location-filter", - ), + _name = "location-filter",), S3OptionsFilter("language", label = T("Language"), options = settings.get_cap_languages(), represent = "%(name)s", resource = "cap_info", - _name = "language-filter", - ), - ] + _name = "language-filter",),] # Title and view title = T("Notification Settings") @@ -91,20 +135,16 @@ def _manage_subscriptions(self, resources, filters): # L10n T = current.T - labels = Storage( - RESOURCES = T("Subscribe To"), + labels = Storage(RESOURCES = T("Subscribe To"), NOTIFY_ON = T("Notify On"), FREQUENCY = T("Frequency"), NOTIFY_BY = T("Notify By"), MORE = T("More Options"), - LESS = T("Less Options"), - ) - messages = Storage( - ERROR = T("Error: could not update notification settings"), - SUCCESS = T("Notification settings updated"), - ) - - # Get current subscription settings resp. form defaults + LESS = T("Less Options"),) + messages = Storage(ERROR = T("Error: could not update notification settings"), + SUCCESS = T("Notification settings updated"),) + + # Get current subscription settings resp. form defaults subscription = self._get_subscription() # Formstyle bootstrap @@ -320,8 +360,7 @@ def _update_subscription(self, subscription): method=subscription["method"]) subscription_id = success else: - success = db(stable.id == subscription_id).update( - pe_id=pe_id, + success = db(stable.id == subscription_id).update(pe_id=pe_id, filter_id=filter_id, notify_on=subscription["notify_on"], frequency=frequency, @@ -397,4 +436,42 @@ def _update_subscription(self, subscription): subscription["filter_id"] = filter_id return subscription + # ============================================================================= +def latest_records(resource, layout, list_id, limit, list_fields, orderby): + """ + Display a dataList of the latest records for a resource + @todo: remove this wrapper + """ + + #orderby = resource.table[orderby] + datalist, numrows, ids = resource.datalist(fields=list_fields, + start=None, + limit=limit, + list_id=list_id, + orderby=orderby, + layout=layout) + if numrows == 0: + # Empty table or just no match? + from s3.s3crud import S3CRUD + table = resource.table + if "deleted" in table: + available_records = current.db(table.deleted != True) + else: + available_records = current.db(table._id > 0) + if available_records.select(table._id, + limitby=(0, 1)).first(): + msg = DIV(S3CRUD.crud_string(resource.tablename, + "msg_no_match"), + _class="empty") + else: + msg = DIV(S3CRUD.crud_string(resource.tablename, + "msg_list_empty"), + _class="empty") + data = msg + else: + # Render the list + data = datalist.html() + + return data + # END ========================================================================= diff --git a/modules/templates/SAMBRO/css.cfg b/modules/templates/SAMBRO/css.cfg new file mode 100644 index 0000000000..0af9f05d63 --- /dev/null +++ b/modules/templates/SAMBRO/css.cfg @@ -0,0 +1,42 @@ +../themes/default/layout.css +../themes/default/footer.css +../themes/default/widgets.css +../themes/default/shortcut.css +../themes/default/homepage.css +bootstrap/font-awesome.css +plugins/jquery.cluetip.css +plugins/jquery.dataTables.css +plugins/jquery.dataTables.responsive.css +#ui/accordion.css +ui/core.css +ui/autocomplete.css +ui/button.css +ui/datepicker.css +ui/dialog.css +# Needed for Delphi +ui/draggable.css +ui/menu.css +#ui/progressbar.css +ui/resizable.css +ui/selectmenu.css +ui/slider.css +#ui/sortable.css +#ui/spinner.css +ui/tabs.css +#ui/tooltip.css +ui/fgtimepicker.css +ui/multiselect.css +ui/timepicker-addon.css +calendars/ui-smoothness.calendars.picker.css +foundation/jquery-ui.theme.css +gis/style.css +zocial/zocial.css +../themes/default/gis.css +../themes/foundation/map.css +../themes/default/mobile.css +../themes/default/print.css +d3/nv.d3.css +../themes/default/report.css +../themes/default/survey.css +../themes/SAMBRO/style.css +# Final line required for parsing \ No newline at end of file diff --git a/modules/templates/SAMBRO/views/index.html b/modules/templates/SAMBRO/views/index.html new file mode 100644 index 0000000000..9c3e577ff5 --- /dev/null +++ b/modules/templates/SAMBRO/views/index.html @@ -0,0 +1,53 @@ +{{extend "layout.html"}}{{theme=response.s3.theme}} + + +