def __call__(self): T = current.T db = current.db s3db = current.s3db request = current.request response = current.response s3 = response.s3 output = {} output["title"] = response.title = current.deployment_settings.get_system_name() # Map auth = current.auth is_logged_in = auth.is_logged_in() callback = None if is_logged_in: # Show the User's Coalition's Polygon org_group_id = auth.user.org_group_id if org_group_id: # Lookup Coalition Name table = s3db.org_group row = db(table.id == org_group_id).select(table.name, limitby=(0, 1) ).first() if row: callback = '''S3.gis.show_map(); var layer,layers=S3.gis.maps.default_map.layers; for(var i=0,len=layers.length;i<len;i++){ layer=layers[i]; if(layer.name=='%s'){layer.setVisibility(true)}}''' % row.name if not callback: # Show all Coalition Polygons callback = '''S3.gis.show_map(); var layer,layers=S3.gis.maps.default_map.layers; for(var i=0,len=layers.length;i<len;i++){ layer=layers[i]; if(layer.name=='All Coalitions'){layer.setVisibility(true)}} ''' gis = current.gis config = gis.get_config() config.zoom = 8 map = gis.show_map(width=770, height=295, callback=callback, catalogue_layers=True, collapsed=True, save=False, ) output["map"] = map # Description of available data from s3db.cms import S3CMS for item in response.menu: item["cms"] = S3CMS.resource_content(module = item["c"], resource = item["f"]) # Site Activity Log resource = s3db.resource("s3_audit") resource.add_filter(FS("~.method") != "delete") orderby = "s3_audit.timestmp desc" list_fields = ["id", "method", "timestmp", "user_id", "tablename", "record_id", ] #current.deployment_settings.ui.customise_s3_audit() db.s3_audit.user_id.represent = s3_auth_user_represent_name list_id = "log" datalist, numrows, ids = resource.datalist(fields=list_fields, start=None, limit=4, list_id=list_id, orderby=orderby, layout=s3.render_log) # Placeholder filter_form = DIV(_class="filter_form") if numrows == 0: # Empty table or just no match? from s3 import S3CRUD table = resource.table if "deleted" in table: available_records = db(table.deleted != True) else: available_records = 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 ajaxurl = URL(c="default", f="audit", args="datalist_f.dl") popup_url = URL(c="default", f="audit", args="datalist.popup") dl = datalist.html(ajaxurl=ajaxurl, pagesize=4, popup_url=popup_url, popup_title=T("Updates"), ) data = dl if is_logged_in and org_group_id: # Add a Filter filter_widgets = [S3OptionsFilter("user_id$org_group_id", label = "", # Can't just use "" as this is then omitted from rendering options = {"*": T("All"), org_group_id: T("My Community"), }, cols = 2, multiple = False, ), ] filter_submit_url = URL(c="default", f="index") filter_ajax_url = URL(c="default", f="audit", args=["filter.options"]) filter_form = S3FilterForm(filter_widgets, filter_manager = False, formstyle = filter_formstyle, clear = False, submit = True, ajax = True, url = filter_submit_url, ajaxurl = filter_ajax_url, _class = "filter-form", _id = "%s-filter-form" % list_id ) filter_form = filter_form.html(resource, request.get_vars, target=list_id, ) output["updates"] = data output["filter_form"] = filter_form # Add JavaScript appname = request.application debug = s3.debug scripts_append = s3.scripts.append if debug: # Infinite Scroll doesn't make sense here, but currently required by dataLists.js scripts_append("/%s/static/scripts/jquery.infinitescroll.js" % appname) scripts_append("/%s/static/scripts/jquery.viewport.js" % appname) scripts_append("/%s/static/scripts/S3/s3.dataLists.js" % appname) else: scripts_append("/%s/static/scripts/S3/s3.dataLists.min.js" % appname) self._view(THEME, "index.html") return output
def __call__(self): T = current.T output = {} s3db = current.s3db request = current.request #------------------------ # Map to display needs map_id = "default_map" ftable = s3db.gis_layer_feature query = (ftable.controller == "req") & \ (ftable.function == "need_line") layer = current.db(query).select(ftable.layer_id, limitby=(0, 1)).first() try: layer_id = layer.layer_id except AttributeError: current.log.error("Cannot find Layer for Map") layer_id = None feature_resources = [{ "name": T("Needs"), "id": "search_results", "layer_id": layer_id, "active": False, }] _map = current.gis.show_map( callback='''S3.search.s3map()''', catalogue_layers=True, collapsed=True, feature_resources=feature_resources, save=False, search=True, toolbar=True, ) output["_map"] = _map # --------------------------------------------------------------------- # Display needs list resource = s3db.resource("req_need_line") #resource.table.commit_status.represent = None #list_id = "req_datalist" #list_fields = [#"purpose", # "location_id", # #"priority", # #"req_ref", # #"site_id", # "date", # ] # Order with most recent request first #orderby = "req_need.date" #datalist, numrows = resource.datalist(fields = list_fields, # limit = None, # list_id = list_id, # orderby = orderby, # ) #if numrows == 0: # current.response.s3.crud_strings["req_need"].msg_no_match = T("No needs at present.") #ajax_url = URL(c="req", f="need", args="datalist.dl", # vars={"list_id": list_id}) #@ToDo: Implement pagination properly #output[list_id] = datalist.html(ajaxurl = ajax_url, # pagesize = 0, # ) # ---------------------------- # Filter Form # - can we have a single form for both Activities & Needs? # filter_widgets = [ S3TextFilter( [ #"need_id$req_number.value", "item_id$name", # These levels are for SHARE/LK #"location_id$L1", "location_id$L2", #"location_id$L3", #"location_id$L4", "need_id$name", "need_id$comments", ], label=T("Search"), comment= T("Search for a Need by Request Number, Item, Location, Summary or Comments" ), ), S3LocationFilter( "location_id", # These levels are for SHARE/LK levels=("L2", "L3", "L4"), ), S3OptionsFilter("item_id"), S3OptionsFilter( "status", cols=3, label=T("Status"), ), S3OptionsFilter( "need_id$event.event_type_id", hidden=True, ), # @ToDo: Filter this list dynamically based on Event Type: S3OptionsFilter("need_id$event__link.event_id"), S3OptionsFilter( "sector_id", hidden=True, ), S3OptionsFilter( "need_id$organisation__link.organisation_id", hidden=True, ), S3OptionsFilter( "need_id$verified.value", cols=2, label=T("Verified"), hidden=True, ), ] filter_form = S3FilterForm( filter_widgets, ajax=True, submit=True, #url = ajax_url, ) output["req_filter_form"] = filter_form.html( resource, request.get_vars, #target = "%s %s" % list_id, map_id target=map_id) # View title output["title"] = current.deployment_settings.get_system_name() self._view(THEME, "dashboard.html") # Custom JS current.response.s3.scripts.append( "/%s/static/themes/SHARE/js/homepage.js" % request.application) return output
def _manage_subscriptions(self, resources, filters): """ Custom form to manage subscriptions @param resources: available resources config @param filters: filter widgets """ from gluon.sqlhtml import SQLFORM from gluon.validators import IS_IN_SET from s3.s3widgets import S3GroupedOptionsWidget # L10n T = current.T 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 subscription = self._get_subscription() # Formstyle bootstrap formstyle = SQLFORM.formstyles.bootstrap # Initialize form form = FORM(_id="subscription-form", hidden={"subscription-filters": ""}) # Filters filter_form = S3FilterForm(filters, clear=False) fieldset = FIELDSET(filter_form.fields(None, subscription["get_vars"]), _id="subscription-filter-form") form.append(fieldset) # Notification options rows = [] stable = current.s3db.pr_subscription selector = S3GroupedOptionsWidget(cols=1) rows.append(("trigger_selector__row", "%s:" % labels.NOTIFY_ON, selector(stable.notify_on, subscription["notify_on"], _id="trigger_selector"), "")) switch = S3GroupedOptionsWidget(cols=1, multiple=False, sort=False) rows.append(("frequency_selector__row", "%s:" % labels.FREQUENCY, switch(stable.frequency, subscription["frequency"], _id="frequency_selector"), "")) # Deactivated: method selector #rows.append(("method_selector__row", #"%s:" % labels.NOTIFY_BY, #selector(stable.method, #subscription["method"], #_id="method_selector"), #"")) fieldset = formstyle(form, rows) fieldset.insert( 0, DIV(SPAN([I(_class="icon-reorder"), labels.MORE], _class="toggle-text", _style="display:none"), SPAN([I(_class="icon-reorder"), labels.LESS], _class="toggle-text"), _id="notification-options", _class="control-group")) form.append(fieldset) # Submit button row = ("submit__row", "", INPUT(_type="submit", _value="Update Settings"), "") fieldset = formstyle(form, [row]) form.append(fieldset) # Script (to extract filters on submit and toggle options visibility) script = URL(c="static", f="scripts", args=["S3", "s3.subscriptions.js"]) response = current.response response.s3.scripts.append(script) # Accept form if form.accepts(current.request.post_vars, current.session, formname="subscription", keepvalues=True): formvars = form.vars listify = lambda x: None if not x else x if type( x) is list else [x] # Fixed resource selection: subscription["subscribe"] = [resources[0]] # Alternatively, with resource selector: #subscribe = listify(formvars.resources) #if subscribe: #subscription["subscribe"] = \ #[r for idx, r in enumerate(resources) #if str(idx) in subscribe] subscription["filters"] = form.request_vars \ .get("subscription-filters", None) subscription["notify_on"] = listify(formvars.notify_on) subscription["frequency"] = formvars.frequency # Fixed method: subscription["method"] = ["EMAIL"] # Alternatively, with method selector: #subscription["method"] = listify(formvars.method) success = self._update_subscription(subscription) if success: response.confirmation = messages.SUCCESS else: response.error = messages.ERROR return form
def _manage_subscriptions(self, resources, filters): """ Custom form to manage subscriptions @param resources: available resources config @param filters: filter widgets """ # L10n T = current.T 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 subscription = self._get_subscription() # Formstyle bootstrap formstyle = SQLFORM.formstyles.bootstrap # Initialize form form = FORM(_id="subscription-form", hidden={"subscription-filters": ""}) # Deactivated: resource selector #options = [] #selected_resources = set() #subscribed = subscription["resources"] #for idx, rconfig in enumerate(resources): #options.append((idx, rconfig["label"])) #if subscribed: #for s in subscribed: #if s.resource == rconfig["resource"] and \ #s.url == rconfig["url"]: #selected_resources.add(idx) #dummy = Storage(name="resources", requires = IS_IN_SET(options)) #selector = S3GroupedOptionsWidget(cols=2) #row = ("resource_selector__row", #"%s:" % labels.RESOURCES, #selector(dummy, #list(selected_resources), #_id="resource_selector"), #"") #fieldset = formstyle(form, [row]) #form.append(fieldset) # Filters filter_form = S3FilterForm(filters, clear=False) fieldset = FIELDSET(filter_form.fields(None, subscription["get_vars"]), _id="subscription-filter-form") form.append(fieldset) # Notification options rows = [] stable = current.s3db.pr_subscription selector = S3GroupedOptionsWidget(cols=1) rows.append(("trigger_selector__row", "%s:" % labels.NOTIFY_ON, selector(stable.notify_on, subscription["notify_on"], _id="trigger_selector"), "")) switch = S3GroupedOptionsWidget(cols=1, multiple=False, sort=False) rows.append(("frequency_selector__row", "%s:" % labels.FREQUENCY, switch(stable.frequency, subscription["frequency"], _id="frequency_selector"), "")) # Deactivated: method selector #rows.append(("method_selector__row", #"%s:" % labels.NOTIFY_BY, #selector(stable.method, #subscription["method"], #_id="method_selector"), #"")) fieldset = formstyle(form, rows) fieldset.insert( 0, DIV(SPAN([I(_class="icon-reorder"), labels.MORE], _class="toggle-text", _style="display:none"), SPAN([I(_class="icon-reorder"), labels.LESS], _class="toggle-text"), _id="notification-options", _class="control-group")) form.append(fieldset) # Submit button row = ("submit__row", "", INPUT(_type="submit", _value="Update Settings"), "") fieldset = formstyle(form, [row]) form.append(fieldset) # Script (to extract filters on submit and toggle options visibility) script = ''' $('#notification-options').click(function() { $(this).siblings().toggle(); $(this).children().toggle(); }); $('#notification-options').siblings().toggle(); $('#notification-options').children().toggle(); $('#subscription-form').submit(function() { $('input[name="subscription-filters"]') .val(JSON.stringify(S3.search.getCurrentFilters($(this)))); }); ''' response = current.response response.s3.jquery_ready.append(script) # Accept form if form.accepts(current.request.post_vars, current.session, formname="subscription", keepvalues=True): formvars = form.vars listify = lambda x: None if not x else x if type( x) is list else [x] # Fixed resource selection: subscription["subscribe"] = [resources[0]] # Alternatively, with resource selector: #subscribe = listify(formvars.resources) #if subscribe: #subscription["subscribe"] = \ #[r for idx, r in enumerate(resources) #if str(idx) in subscribe] subscription["filters"] = form.request_vars \ .get("subscription-filters", None) subscription["notify_on"] = listify(formvars.notify_on) subscription["frequency"] = formvars.frequency # Fixed method: subscription["method"] = ["EMAIL"] # Alternatively, with method selector: #subscription["method"] = listify(formvars.method) success = self._update_subscription(subscription) if success: response.confirmation = messages.SUCCESS else: response.error = messages.ERROR return form
def __call__(self): output = {} T = current.T request = current.request s3 = current.response.s3 # Check logged in and permissions auth = current.auth roles = current.session.s3.roles system_roles = auth.get_system_roles() AUTHENTICATED = system_roles.AUTHENTICATED # Login/Registration forms self_registration = current.deployment_settings.get_security_self_registration( ) registered = False login_form = None login_div = None register_form = None register_div = None if AUTHENTICATED not in roles: # This user isn't yet logged-in if request.cookies.has_key("registered"): # This browser has logged-in before registered = True if self_registration is True: # Provide a Registration box on front page register_form = auth.register() register_div = DIV(H3(T("Register")), P(XML(T("If you would like to help, then please %(sign_up_now)s") % \ dict(sign_up_now=B(T("sign-up now")))))) if request.env.request_method == "POST": post_script = \ '''$('#register_form').removeClass('hide') $('#login_form').addClass('hide')''' else: post_script = "" register_script = \ '''$('#register-btn').attr('href','#register') $('#login-btn').attr('href','#login') %s $('#register-btn').click(function(){ $('#register_form').removeClass('hide') $('#login_form').addClass('hide') }) $('#login-btn').click(function(){ $('#register_form').addClass('hide') $('#login_form').removeClass('hide') })''' % post_script s3.jquery_ready.append(register_script) # Provide a login box on front page auth.messages.submit_button = T("Login") login_form = auth.login(inline=True) login_div = DIV(H3(T("Login")), P(XML(T("Registered users can %(login)s to access the system") % \ dict(login=B(T("login")))))) output["self_registration"] = self_registration output["registered"] = registered output["login_div"] = login_div output["login_form"] = login_form output["register_div"] = register_div output["register_form"] = register_form # Latest 4 Events and Requests s3db = current.s3db layout = s3db.cms_post_list_layout list_id = "latest_events" 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 >= request.now) # Order with next Event first orderby = "date" output["latest_events"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) list_id = "latest_reqs" resource = s3db.resource("req_req") s3db.req_customise_req_fields() list_fields = s3db.get_config("req_req", "list_fields") layout = s3db.req_req_list_layout resource.add_filter(FS("cancel") != True) # Order with most recent Request first orderby = "date desc" output["latest_reqs"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) # Site Activity Log resource = s3db.resource("s3_audit") resource.add_filter(FS("~.method") != "delete") orderby = "s3_audit.timestmp desc" list_fields = [ "id", "method", "user_id", "tablename", "record_id", ] #current.deployment_settings.ui.customise_s3_audit() db = current.db db.s3_audit.user_id.represent = s3_auth_user_represent_name list_id = "log" datalist, numrows, ids = resource.datalist(fields=list_fields, start=None, limit=4, list_id=list_id, orderby=orderby, layout=s3.render_log) # Placeholder filter_form = DIV(_class="filter_form") if numrows == 0: # Empty table or just no match? from s3 import S3CRUD table = resource.table if "deleted" in table: available_records = db(table.deleted != True) else: available_records = 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 ajaxurl = URL(c="default", f="audit", args="datalist_f.dl") popup_url = URL(c="default", f="audit", args="datalist.popup") dl = datalist.html( ajaxurl=ajaxurl, pagesize=4, popup_url=popup_url, popup_title=T("Updates"), ) data = dl if auth.s3_logged_in() and auth.user.org_group_id: # Add a Filter filter_widgets = [ S3OptionsFilter( "user_id$org_group_id", label="", # Can't just use "" as this is then omitted from rendering options={ "*": T("All"), org_group_id: T("My Community"), }, multiple=False, ), ] filter_submit_url = URL(c="default", f="index") filter_ajax_url = URL(c="default", f="audit", args=["filter.options"]) filter_form = S3FilterForm(filter_widgets, filter_manager=False, formstyle=filter_formstyle, clear=False, submit=True, ajax=True, url=filter_submit_url, ajaxurl=filter_ajax_url, _class="filter-form", _id="%s-filter-form" % list_id) filter_form = filter_form.html( resource, request.get_vars, target=list_id, ) output["updates"] = data output["filter_form"] = filter_form # Add JavaScript appname = request.application debug = s3.debug scripts_append = s3.scripts.append if debug: # Infinite Scroll doesn't make sense here, but currently required by dataLists.js scripts_append("/%s/static/scripts/jquery.infinitescroll.js" % appname) scripts_append("/%s/static/scripts/jquery.viewport.js" % appname) scripts_append("/%s/static/scripts/S3/s3.dataLists.js" % appname) else: scripts_append("/%s/static/scripts/S3/s3.dataLists.min.js" % appname) self._view(THEME, "index.html") return output
def _manage_subscriptions(self, resources, filters): """ Custom form to manage subscriptions @param resources: available resources config @param filters: filter widgets """ # Uses Default Eden formstyle from s3theme import formstyle_foundation as formstyle from gluon.validators import IS_IN_SET from s3.s3widgets import S3GroupedOptionsWidget, S3MultiSelectWidget from s3layouts import S3PopupLink # L10n T = current.T db = current.db s3db = current.s3db response = current.response 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 subscription = self._get_subscription() # Initialize form form = FORM(_id="subscription-form", hidden={"subscription-filters": ""}) # Filters filter_form = S3FilterForm(filters, clear=False) fieldset = FIELDSET(filter_form.fields(None, subscription["get_vars"]), _id="subscription-filter-form") form.append(fieldset) # Notification options rows = [] stable = s3db.pr_subscription selector = S3GroupedOptionsWidget(cols=1) # Deactivated trigger selector #rows.append(("trigger_selector__row", # "%s:" % labels.NOTIFY_ON, # selector(stable.notify_on, # subscription["notify_on"], # _id="trigger_selector"), # "")) #switch = S3GroupedOptionsWidget(cols=1, multiple=False, sort=False) # Deactivated: frequency selector #rows.append(("frequency_selector__row", # "%s:" % labels.FREQUENCY, # switch(stable.frequency, # subscription["frequency"], # _id="frequency_selector"), # "")) methods = [("EMAIL", T("Email")), ("SMS", T("SMS")), ("Sync", T("FTP")), ] method_options = Storage(name = "method", requires = IS_IN_SET(methods)) rows.append(("method_selector__row", "%s:" % labels.NOTIFY_BY, selector(method_options, subscription["method"], _id="method_selector"), "")) # Sync Row properties = subscription["comments"] if properties: properties = json.loads(properties) synctable = s3db.sync_repository query = (synctable.apitype == "ftp") & \ (synctable.deleted != True) & \ (synctable.owned_by_user == current.auth.user.id) ftp_rows = db(query).select(synctable.id, synctable.name, orderby = synctable.id) multiselect = S3MultiSelectWidget(header = False, multiple = False, create = {"c": "sync", "f": "repository", "label": "Create Repository", }, ) if ftp_rows: if properties: user_repository_id = properties["repository_id"] else: user_repository_id = ftp_rows.first().id if current.auth.s3_has_permission("update", "sync_repository", record_id = user_repository_id): repository_comment = S3PopupLink(c = "sync", f = "repository", m = "update", args = [user_repository_id], title = T("Update Repository"), tooltip = T("You can edit your FTP repository here"), ) field = s3db.sync_task.repository_id ftp_ids = [(r.id, T(r.name)) for r in ftp_rows] field.requires = IS_IN_SET(ftp_ids) rows.append(("sync_task_repository_id__row", "", multiselect(field, user_repository_id, _id="sync_task_repository_id"), repository_comment)) else: if current.auth.s3_has_permission("create", "sync_repository"): repository_comment = S3PopupLink(c = "sync", f = "repository", title = T("Create Repository"), tooltip = T("Click on the link to begin creating your FTP repository"), ) rows.append(("sync_task_repository_id__row", "", "", repository_comment)) parent = FIELDSET() for row in rows: parent.append(formstyle(form, [row])) # Deactivated Toggle #parent.insert(0, # DIV(SPAN([I(_class="icon-reorder"), labels.MORE], # _class="toggle-text", # _style="display:none"), # SPAN([I(_class="icon-reorder"), labels.LESS], # _class="toggle-text"), # _id="notification-options", # _class="control-group")) form.append(parent) # Submit button submit_fieldset = FIELDSET(DIV("", INPUT(_type="submit", _value="Update Settings"), _id = "submit__row")) form.append(submit_fieldset) # Script (to extract filters on submit and toggle options visibility) script = URL(c="static", f="scripts", args=["S3", "s3.subscriptions.js"]) response.s3.scripts.append(script) # Script to show/hide the ftp repo row for FTP checkbox on/off repository_script = ''' if($('#method_selector option[value=Sync]').is(':selected')){ $('#sync_task_repository_id__row').show(); } else { $('#sync_task_repository_id__row').hide(); } $('#method_selector').change(function(){ if($(this).val().indexOf('Sync') != -1){ $('#sync_task_repository_id__row').show(); } else { $('#sync_task_repository_id__row').hide(); } }) ''' response.s3.jquery_ready.append(repository_script) # Accept form if form.accepts(current.request.post_vars, current.session, formname="subscription", keepvalues=True): formvars = form.vars listify = lambda x: None if not x else x if type(x) is list else [x] # Fixed resource selection: subscription["subscribe"] = [resources[0]] # Alternatively, with resource selector: #subscribe = listify(formvars.resources) #if subscribe: #subscription["subscribe"] = \ #[r for idx, r in enumerate(resources) #if str(idx) in subscribe] subscription["filters"] = form.request_vars \ .get("subscription-filters", None) # Fixed method subscription["method"] = formvars.method # Fixed Notify On and Frequency subscription["notify_on"] = ["new"] subscription["frequency"] = "immediately" # Alternatively, with notify and frequency selector #subscription["notify_on"] = listify(formvars.notify_on #subscription["frequency"] = formvars.frequency success_subscription = self._update_subscription(subscription) if "Sync" in subscription["method"] and formvars.repository_id: properties = self._update_sync(subscription["subscribe"][0]['resource'], subscription.get("filters"), int(formvars.repository_id), properties) properties = json.dumps(properties) db(stable.pe_id == current.auth.user.pe_id).update(comments=properties) else: self._remove_sync(properties) db(stable.pe_id == current.auth.user.pe_id).update(comments=None) if success_subscription: response.confirmation = messages.SUCCESS else: response.error = messages.ERROR return form
def __call__(self): """ Main entry point, configuration """ logged_in = current.auth.s3_logged_in() if logged_in: fn = "alert" else: fn = "public" T = current.T s3db = current.s3db request = current.request output = {} # Map ftable = s3db.gis_layer_feature query = (ftable.controller == "cap") & \ (ftable.function == fn) layer = current.db(query).select(ftable.layer_id, limitby=(0, 1) ).first() try: layer_id = layer.layer_id except: from s3 import s3_debug s3_debug("Cannot find Layer for Map") layer_id = None feature_resources = [{"name" : T("Alerts"), "id" : "search_results", "layer_id" : layer_id, "tablename" : "cap_alert", "url" : URL(c="cap", f=fn, extension="geojson"), # We activate in callback after ensuring URL is updated for current filter status "active" : False, }] _map = current.gis.show_map(callback='''S3.search.s3map()''', catalogue_layers=True, collapsed=True, feature_resources=feature_resources, save=False, search=True, toolbar=True, ) output["_map"] = _map # Filterable List of Alerts # - most recent first resource = s3db.resource("cap_alert") # Don't show Templates resource.add_filter(FS("is_template") == False) if not logged_in: # Only show Public Alerts resource.add_filter(FS("scope") == "Public") # Only show Alerts which haven't expired resource.add_filter(FS("info.expires") >= request.utcnow) list_id = "cap_alert_datalist" list_fields = ["msg_type", "info.headline", "area.name", #"info.description", "info.sender_name", "info.priority", "status", "scope", "info.event_type_id", "info.severity", "info.certainty", "info.urgency", "sent", ] # Order with most recent Alert first orderby = "cap_info.expires desc" datalist, numrows, ids = resource.datalist(fields = list_fields, #start = None, limit = None, list_id = list_id, orderby = orderby, layout = s3db.cap_alert_list_layout ) ajax_url = URL(c="cap", f=fn, args="datalist.dl", vars={"list_id": list_id}) output[list_id] = datalist.html(ajaxurl = ajax_url, pagesize = None, ) # @ToDo: Options are currently built from the full-set rather than the filtered set filter_widgets = [#S3LocationFilter("location.location_id", # label=T("Location"), # levels=("L0",), # widget="multiselect", # ), S3OptionsFilter("info.priority", #label=T("Priority"), ), S3OptionsFilter("info.event_type_id", #label=T("Event Type"), ), S3OptionsFilter("scope", #label=T("Scope"), ), S3DateFilter("info.expires", label = "", #label=T("Expiry Date"), hide_time=True, ), ] filter_form = S3FilterForm(filter_widgets, ajax=True, submit=True, url=ajax_url, ) output["alert_filter_form"] = filter_form.html(resource, request.get_vars, list_id) # Filterable News Feed # - most recent first resource = s3db.resource("cms_post") # Only show News posts (differentiate from e.g. online user guide) resource.add_filter(FS("series_id$name") == "News") list_id = "cms_post_datalist" list_fields = [#"series_id", "location_id", "date", "body", #"created_by", #"created_by$organisation_id", #"document.file", ] # Order with most recent Post first orderby = "cms_post.date desc" datalist, numrows, ids = resource.datalist(fields = list_fields, #start = None, limit = 5, list_id = list_id, orderby = orderby, # @ToDo: Custom layout with more button to expand content block layout = s3db.cms_post_list_layout ) ajax_url = URL(c="cms", f="post", args="datalist.dl", vars={"list_id": list_id}) output[list_id] = datalist.html(ajaxurl = ajax_url, pagesize = 5 ) # Truncate body #from s3 import s3_trunk8 #s3_trunk8(lines=8) #filter_widgets = [#S3LocationFilter("location_id", # # label="", # # levels=("L0",), # # widget="multiselect", # # ), # # @ToDo: Source (Series? Tag?) # #S3OptionsFilter(), # ] #filter_form = S3FilterForm(filter_widgets, # ajax=True, # submit=True, # url=ajax_url, # ) #output["news_filter_form"] = filter_form.html(resource, request.get_vars, list_id) # Title and view output["title"] = current.deployment_settings.get_system_name() self._view(THEME, "index.html") s3 = current.response.s3 # Custom CSS s3.stylesheets.append("../themes/SAMBRO/style.css") # Custom JS s3.scripts.append("/%s/static/themes/SAMBRO/js/homepage.js" % request.application) return output
def __call__(self): T = current.T output = {} s3db = current.s3db request = current.request #------------------------ # Map to display needs ftable = s3db.gis_layer_feature query = (ftable.controller == "req") & \ (ftable.function == "need") layer = current.db(query).select(ftable.layer_id, limitby=(0, 1)).first() try: layer_id = layer.layer_id except: current.log.error("Cannot find Layer for Map") layer_id = None feature_resources = [{ "name": T("Needs"), "id": "search_results", "layer_id": layer_id, "active": False, }] _map = current.gis.show_map( callback='''S3.search.s3map()''', catalogue_layers=True, collapsed=True, feature_resources=feature_resources, save=False, search=True, toolbar=True, ) output["_map"] = _map # --------------------------------------------------------------------- # Display needs list resource = s3db.resource("req_need") #resource.table.commit_status.represent = None list_id = "req_datalist" list_fields = [ #"purpose", "location_id", "priority", #"req_ref", #"site_id", "date", ] # Order with most recent request first orderby = "req_need.date" datalist, numrows = resource.datalist( fields=list_fields, limit=None, list_id=list_id, orderby=orderby, ) if numrows == 0: current.response.s3.crud_strings["req_need"].msg_no_match = T( "No needs at present.") ajax_url = URL(c="req", f="need", args="datalist.dl", vars={"list_id": list_id}) #@ToDo: Implement pagination properly output[list_id] = datalist.html( ajaxurl=ajax_url, pagesize=0, ) # ---------------------------- # Filter Form # - can we have a single form for both Activities & Needs? # filter_widgets = [ S3OptionsFilter( "priority", label=T("Priority"), ), S3DateFilter( "date", label=T("Date"), hide_time=True, ), ] filter_form = S3FilterForm( filter_widgets, ajax=True, submit=True, url=ajax_url, ) output["req_filter_form"] = filter_form.html(resource, request.get_vars, list_id) # View title output["title"] = current.deployment_settings.get_system_name() self._view(THEME, "dashboard.html") # Custom JS current.response.s3.scripts.append( "/%s/static/themes/SHARE/js/homepage.js" % request.application) return output