def deploy_index(): """ Custom module homepage for deploy (=RDRT) to display online documentation for the module """ response = current.response def prep(r): default_url = URL(f="mission", args="summary", vars={}) return current.s3db.cms_documentation(r, "RDRT", default_url) response.s3.prep = prep output = current.rest_controller("cms", "post") # Custom view view = path.join(current.request.folder, "modules", "templates", THEME, "views", "deploy", "index.html", ) try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP(404, "Unable to open Custom View: %s" % view) return output
def __call__(self): """ Main entry point """ # Authorization (user must be logged in) auth = current.auth permissions = auth.permission if not auth.user: permissions.fail() fmt = permissions.format if current.request.env.request_method == "POST" and fmt != "dl": return self.update() pe_id = auth.user.pe_id s3 = current.response.s3 # Filter from s3 import S3FieldSelector as FS f = FS("pe_id") == pe_id s3.filter = f # List Fields current.s3db.configure( "pr_filter", list_fields=["title", "resource", "url", "query"], list_layout=self.render_filter, orderby="resource") # Page length s3.dl_pagelength = 10 # Data list current.request.args = ["datalist.%s" % fmt] output = current.rest_controller("pr", "filter", list_ajaxurl=URL(f="index", args="filters.dl")) # Title and view T = current.T if fmt != "dl": output["title"] = T("Saved Filters") self._view(THEME, "filters.html") # Script for inline-editing of filter title options = { "cssclass": "jeditable-input", "tooltip": str(T("Click to edit")) } script = """$('.jeditable').editable('%s', %s);""" % \ (URL(args="filters"), json.dumps(options)) s3.jquery_ready.append(script) return output
def __call__(self): """ Main entry point """ # Authorization (user must be logged in) auth = current.auth permissions = auth.permission if not auth.user: permissions.fail() fmt = permissions.format if current.request.env.request_method == "POST" and fmt != "dl": return self.update() pe_id = auth.user.pe_id s3 = current.response.s3 # Filter from s3 import S3FieldSelector as FS f = FS("pe_id") == pe_id s3.filter = f # List Fields current.s3db.configure("pr_filter", list_fields = ["title", "resource", "url", "query"], list_layout = self.render_filter, orderby = "resource") # Page length s3.dl_pagelength = 10 # Data list current.request.args = ["datalist.%s" % fmt] output = current.rest_controller("pr", "filter", list_ajaxurl = URL(f="index", args="filters.dl")) # Title and view T = current.T if fmt != "dl": output["title"] = T("Saved Filters") self._view(THEME, "filters.html") # Script for inline-editing of filter title options = {"cssclass": "jeditable-input", "tooltip": str(T("Click to edit"))} script = """$('.jeditable').editable('%s', %s);""" % \ (URL(args="filters"), json.dumps(options)) s3.jquery_ready.append(script) return output
def __call__(self): response = current.response def prep(r): default_url = URL(f="index", args=[], vars={}) return current.s3db.cms_documentation(r, "HELP", default_url) response.s3.prep = prep output = current.rest_controller("cms", "post") # Custom view self._view(THEME, "docs.html") current.menu.dashboard = None return output
def homepage(): """ Custom Homepage - DataList of CMS Posts """ if not current.auth.is_logged_in(): return login() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 current.deployment_settings.ui.customize_cms_post() list_layout = render_homepage_posts filter_widgets = [S3TextFilter(["body"], label="", _class="filter-search", _placeholder=T("Search").upper()), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", cols=3), S3OptionsFilter("location_id", label=T("Filter by Location"), represent="%(name)s", widget="multiselect", cols=3), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), represent="%(name)s", widget="multiselect", cols=3), S3DateFilter("created_on", label=T("Filter by Date")), ] s3db.configure("cms_post", filter_formstyle = filter_formstyle, filter_submit = (T("Filter Results"), "btn btn-primary"), filter_widgets = filter_widgets, list_layout = list_layout, ) s3.dl_pagelength = 6 # 5 forces an AJAX call if "datalist_dl_post" in request.args: ajax = True else: ajax = False def prep(r): if ajax: r.representation = "dl" return True s3.prep = prep request.args = ["datalist"] output = current.rest_controller("cms", "post", list_ajaxurl = URL(f="index", args="datalist_dl_post")) if ajax: response.view = "plain.html" else: form = output["form"] # Remove duplicate Submit button form[0][-1] = "" if form.errors: s3.jquery_ready.append('''$("#myModal").modal("show")''') # Set Title & View after REST Controller, in order to override output["title"] = response.title = current.deployment_settings.get_system_name() view = path.join(request.folder, "private", "templates", "CSN", "views", "index.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP("404", "Unable to open Custom View: %s" % view) # Latest 5 Disasters resource = s3db.resource("event_event") list_fields = ["name", "zero_hour", "closed", ] orderby = resource.get_config("list_orderby", ~resource.table.created_on) datalist, numrows, ids = resource.datalist(fields=list_fields, start=None, limit=5, listid="event_datalist", orderby=orderby, layout=render_homepage_events) if numrows == 0: # Empty table or just no match? 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 dl = datalist.html() data = dl output["disasters"] = data return output
def _newsfeed(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ #if not current.auth.is_logged_in(): # current.auth.permission.fail() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 # Ensure that filtered views translate into options which update the Widget if "~.series_id$name" in request.get_vars: series_name = request.vars["~.series_id$name"] table = s3db.cms_series series = current.db(table.name == series_name).select(table.id, limitby=(0, 1)).first() if series: series_id = str(series.id) request.get_vars.pop("~.series_id$name") request.get_vars["~.series_id__belongs"] = series_id current.deployment_settings.ui.customize_cms_post() list_layout = s3.render_posts filter_widgets = [S3TextFilter(["body"], label="", _class="filter-search", #_placeholder=T("Search").upper(), ), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", cols=3, hidden=True, ), S3LocationFilter("location_id", label=T("Filter by Location"), levels=["L1", "L2", "L3"], widget="multiselect", cols=3, hidden=True, ), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), represent="%(name)s", widget="multiselect", cols=3, hidden=True, ), S3DateFilter("created_on", label=T("Filter by Date"), hide_time=True, hidden=True, ), ] s3db.configure("cms_post", # We use a custom Advanced widget filter_advanced = False, filter_formstyle = filter_formstyle, filter_submit = (T("SEARCH"), "btn btn-primary"), filter_widgets = filter_widgets, list_layout = list_layout, # Create form comes via AJAX in a Modal insertable = False, notify_fields = [(T("Type"), "series_id"), (T("Date"), "date"), (T("Location"), "location_id"), (T("Description"), "body"), ], notify_template = "notify_post", ) s3.dl_pagelength = 6 # 5 forces an AJAX call if "datalist_dl_post" in request.args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in request.args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in request.args: # Inline component validation request request.args = [] ajax = True elif current.auth.permission.format == "msg": # Subscription lookup request request.args = [] ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl = URL(f="index", args="datalist_dl_post"), filter_ajax_url = URL(f="index", args="datalist_dl_filter", vars={})) if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = T("News Feed") view = path.join(request.folder, "private", "templates", THEME, "views", "newsfeed.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP("404", "Unable to open Custom View: %s" % view) scripts = [] sappend = scripts.append # Style the Search TextFilter widget sappend('''$('#post-cms_post_body-text-filter__row').addClass('input-append').append('<span class="add-on"><i class="icon-search"></i></span>')''') # Button to toggle Advanced Form sappend('''$('#list-filter').append('<a class="accordion-toggle"><i class="icon-reorder"></i> %s</a>')''' % T("Advanced Search")) sappend('''$('.accordion-toggle').click(function(){$('.advanced').toggle()})''') s3.jquery_ready.append('''\n'''.join(scripts)) # Latest 5 Disasters # resource = s3db.resource("event_event") # layout = render_events # listid = "event_datalist" # limit = 5 # orderby = "zero_hour desc" # list_fields = ["name", # "event_type_id$name", # "zero_hour", # "closed", # ] # output["disasters"] = latest_records(resource, layout, listid, limit, list_fields, orderby) return output
def _newsfeed(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ #if not current.auth.is_logged_in(): # current.auth.permission.fail() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 # Ensure that filtered views translate into options which update the Widget if "~.series_id$name" in request.get_vars: series_name = request.vars["~.series_id$name"] table = s3db.cms_series series = current.db(table.name == series_name).select( table.id, limitby=(0, 1)).first() if series: series_id = str(series.id) request.get_vars.pop("~.series_id$name") request.get_vars["~.series_id__belongs"] = series_id current.deployment_settings.ui.customize_cms_post() list_layout = s3.render_posts filter_widgets = [ S3TextFilter( ["body"], label="", _class="filter-search", #_placeholder=T("Search").upper(), ), S3OptionsFilter( "series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", hidden=True, ), S3LocationFilter( "location_id", label=T("Filter by Location"), levels=["L1", "L2", "L3"], widget="multiselect", hidden=True, ), S3OptionsFilter( "created_by$organisation_id", label=T("Filter by Organization"), # Can't use this for integers, use field.represent instead #represent="%(name)s", widget="multiselect", hidden=True, ), S3DateFilter( "created_on", label=T("Filter by Date"), hide_time=True, hidden=True, ), ] s3db.configure( "cms_post", # We use a custom Advanced widget filter_advanced=False, filter_formstyle=filter_formstyle, filter_submit=(T("SEARCH"), "btn btn-primary"), filter_widgets=filter_widgets, list_layout=list_layout, # Create form comes via AJAX in a Modal insertable=False, notify_fields=[ (T("Type"), "series_id"), (T("Date"), "date"), (T("Location"), "location_id"), (T("Description"), "body"), ], notify_template="notify_post", ) s3.dl_pagelength = 6 # 5 forces an AJAX call old_args = request.args if "datalist_dl_post" in old_args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in old_args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in old_args: # Inline component validation request request.args = [] ajax = True elif current.auth.permission.format == "msg": # Subscription lookup request request.args = [] ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl=URL(f="index", args="datalist_dl_post"), filter_ajax_url=URL( f="index", args="datalist_dl_filter", vars={})) request.args = old_args if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = T("News Feed") view = path.join(request.folder, "private", "templates", THEME, "views", "newsfeed.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP(404, "Unable to open Custom View: %s" % view) scripts = [] sappend = scripts.append # Style the Search TextFilter widget sappend( '''$('#post-cms_post_body-text-filter__row').addClass('input-append').append('<span class="add-on"><i class="icon-search"></i></span>')''' ) # Button to toggle Advanced Form sappend( '''$('#list-filter').append('<a class="accordion-toggle"><i class="icon-reorder"></i> %s</a>')''' % T("Advanced Search")) # Toggle doesn't work directly when removing 'hide' & requires a 2nd click to open without this sappend( '''$('.accordion-toggle').click(function(){var a=$('.advanced');if(a.hasClass('hide')){a.removeClass('hide').show()}else{a.toggle()}})''' ) s3.jquery_ready.append('''\n'''.join(scripts)) # Latest 5 Disasters # resource = s3db.resource("event_event") # layout = render_events # list_id = "event_datalist" # limit = 5 # orderby = "start_date desc" # list_fields = ["name", # "event_type_id$name", # "start_date", # "closed", # ] # output["disasters"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) return output
def _updates(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ #if not current.auth.is_logged_in(): # current.auth.permission.fail() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 current.deployment_settings.ui.customize_cms_post() list_layout = s3.render_posts filter_widgets = [ S3TextFilter( ["body"], label="", _class="filter-search", #_placeholder=T("Search").upper(), ), S3OptionsFilter( "series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", cols=3, hidden=True, ), S3LocationFilter( "location_id", label=T("Filter by Location"), levels=["L1", "L2", "L3"], widget="multiselect", cols=3, hidden=True, ), S3OptionsFilter( "created_by$organisation_id", label=T("Filter by Organization"), represent="%(name)s", widget="multiselect", cols=3, hidden=True, ), S3DateFilter( "created_on", label=T("Filter by Date"), hide_time=True, hidden=True, ), ] s3db.configure( "cms_post", # We use a custom Advanced widget filter_advanced=False, filter_formstyle=filter_formstyle, filter_submit=(T("SEARCH"), "btn btn-primary"), filter_widgets=filter_widgets, list_layout=list_layout, # Create form comes via AJAX in a Modal insertable=False, ) s3.dl_pagelength = 6 # 5 forces an AJAX call if "datalist_dl_post" in request.args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in request.args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in request.args: ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl=URL(f="index", args="datalist_dl_post"), filter_ajax_url=URL( f="index", args="datalist_dl_filter", vars={})) if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = T("News Feed") view = path.join(request.folder, "private", "templates", THEME, "views", "updates.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP("404", "Unable to open Custom View: %s" % view) scripts = [] sappend = scripts.append # Style the Search TextFilter widget sappend( '''$('#post-cms_post_body-text-filter__row').addClass('input-append').append('<span class="add-on"><i class="icon-search"></i></span>')''' ) # Button to toggle Advanced Form sappend( '''$('#list-filter').append('<a class="accordion-toggle"><i class="icon-reorder"></i> %s</a>')''' % T("Advanced Search")) sappend( '''$('.accordion-toggle').click(function(){$('.advanced').toggle()})''' ) s3.jquery_ready.append('''\n'''.join(scripts)) # Latest 5 Disasters resource = s3db.resource("event_event") list_fields = [ "name", "event_type_id$name", "zero_hour", "closed", ] orderby = resource.get_config("list_orderby", ~resource.table.created_on) datalist, numrows, ids = resource.datalist(fields=list_fields, start=None, limit=5, listid="event_datalist", orderby=orderby, layout=render_events) # Render the list data = datalist.html() if numrows == 0: # Empty table or just no match? 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.insert(1, msg) output["disasters"] = data return output
def homepage(): """ Custom Homepage - DataList of CMS Posts """ if not current.auth.is_logged_in(): return login() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 current.deployment_settings.ui.customize_cms_post() list_layout = render_homepage_posts filter_widgets = [ S3TextFilter(["body"], label="", _class="filter-search", _placeholder=T("Search").upper()), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", cols=3), S3OptionsFilter("location_id", label=T("Filter by Location"), represent="%(name)s", widget="multiselect", cols=3), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), represent="%(name)s", widget="multiselect", cols=3), S3DateFilter("created_on", label=T("Filter by Date")), ] s3db.configure( "cms_post", filter_formstyle=filter_formstyle, filter_submit=(T("Filter Results"), "btn btn-primary"), filter_widgets=filter_widgets, list_layout=list_layout, ) s3.dl_pagelength = 6 # 5 forces an AJAX call if "datalist_dl_post" in request.args: ajax = True else: ajax = False def prep(r): if ajax: r.representation = "dl" return True s3.prep = prep request.args = ["datalist"] output = current.rest_controller("cms", "post", list_ajaxurl=URL(f="index", args="datalist_dl_post")) if ajax: response.view = "plain.html" else: form = output["form"] # Remove duplicate Submit button form[0][-1] = "" if form.errors: s3.jquery_ready.append('''$("#myModal").modal("show")''') # Set Title & View after REST Controller, in order to override output[ "title"] = response.title = current.deployment_settings.get_system_name( ) view = path.join(request.folder, "private", "templates", "CSN", "views", "index.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP(404, "Unable to open Custom View: %s" % view) # Latest 5 Disasters resource = s3db.resource("event_event") list_fields = [ "name", "zero_hour", "closed", ] orderby = resource.get_config("list_orderby", ~resource.table.created_on) datalist, numrows, ids = resource.datalist( fields=list_fields, start=None, limit=5, list_id="event_datalist", orderby=orderby, layout=render_homepage_events) if numrows == 0: # Empty table or just no match? 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 dl = datalist.html() data = dl output["disasters"] = data return output
def _newsfeed(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ #if not current.auth.is_logged_in(): # current.auth.permission.fail() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 # Ensure that filtered views translate into options which update the Widget get_vars = request.get_vars if "~.series_id$name" in get_vars: series_name = get_vars["~.series_id$name"] table = s3db.cms_series series = current.db(table.name == series_name).select(table.id, limitby=(0, 1)).first() if series: series_id = str(series.id) get_vars.pop("~.series_id$name") get_vars["~.series_id__belongs"] = series_id current.deployment_settings.customise_controller("cms_post") list_layout = s3.render_posts filter_widgets = [S3TextFilter(["body"], label="", _class="filter-search", #_placeholder=T("Search").upper(), ), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", hidden=True, ), S3LocationFilter("location_id", label=T("Filter by Location"), levels=("L1", "L2", "L3"), widget="multiselect", hidden=True, ), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), # Can't use this for integers, use field.represent instead #represent="%(name)s", widget="multiselect", hidden=True, ), S3DateFilter("created_on", label=T("Filter by Date"), hide_time=True, hidden=True, ), ] s3db.configure("cms_post", # We use a custom Advanced widget filter_advanced = False, filter_formstyle = filter_formstyle, filter_submit = (T("SEARCH"), "btn btn-primary"), filter_widgets = filter_widgets, list_layout = list_layout, # Create form comes via AJAX in a Modal insertable = False, notify_fields = [(T("Type"), "series_id"), (T("Date"), "date"), (T("Location"), "location_id"), (T("Description"), "body"), ], notify_template = "notify_post", ) s3.dl_pagelength = 6 # 5 forces an AJAX call old_args = request.args if "datalist_dl_post" in old_args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in old_args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in old_args: # Inline component validation request request.args = [] ajax = True elif current.auth.permission.format == "msg": # Subscription lookup request request.args = [] ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl = URL(f="index", args="datalist_dl_post"), filter_ajax_url = URL(f="index", args="datalist_dl_filter", vars={}), ) request.args = old_args if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = T("News Feed") view = path.join(request.folder, "modules", "templates", THEME, "views", "newsfeed.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP(404, "Unable to open Custom View: %s" % view) s3.js_global.append('''i18n.adv_search="%s"''' % T("Advanced Search")) s3.scripts.append("/%s/static/themes/%s/js/newsfeed.js" % (request.application, THEME)) # Latest 5 Disasters resource = s3db.resource("event_event") layout = render_events list_id = "event_datalist" limit = 5 orderby = "start_date desc" list_fields = ["name", "event_type_id$name", "start_date", "closed", ] output["disasters"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) return output
def _newsfeed(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ #if not current.auth.is_logged_in(): # current.auth.permission.fail() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 # Ensure that filtered views translate into options which update the Widget get_vars = request.get_vars if "~.series_id$name" in get_vars: series_name = get_vars["~.series_id$name"] table = s3db.cms_series series = current.db(table.name == series_name).select(table.id, limitby=(0, 1)).first() if series: series_id = str(series.id) get_vars.pop("~.series_id$name") get_vars["~.series_id__belongs"] = series_id current.deployment_settings.customise_controller("cms_post") list_layout = s3.render_posts filter_widgets = [S3TextFilter(["body"], label="", _class="filter-search", #_placeholder=T("Search").upper(), ), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", hidden=True, ), S3LocationFilter("location_id", label=T("Filter by Location"), levels=("L1", "L2", "L3"), widget="multiselect", hidden=True, ), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), # Can't use this for integers, use field.represent instead #represent="%(name)s", widget="multiselect", hidden=True, ), S3DateFilter("created_on", label=T("Filter by Date"), hide_time=True, hidden=True, ), ] s3db.configure("cms_post", # We use a custom Advanced widget filter_advanced = False, filter_formstyle = filter_formstyle, filter_submit = (T("SEARCH"), "btn btn-primary"), filter_widgets = filter_widgets, list_layout = list_layout, # Create form comes via AJAX in a Modal insertable = False, notify_fields = [(T("Type"), "series_id"), (T("Date"), "date"), (T("Location"), "location_id"), (T("Description"), "body"), ], notify_template = "notify_post", ) s3.dl_pagelength = 6 # 5 forces an AJAX call old_args = request.args if "datalist_dl_post" in old_args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in old_args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in old_args: # Inline component validation request request.args = [] ajax = True elif current.auth.permission.format == "msg": # Subscription lookup request request.args = [] ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl = URL(f="index", args="datalist_dl_post"), filter_ajax_url = URL(f="index", args="datalist_dl_filter", vars={}), ) request.args = old_args if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = T("News Feed") view = path.join(request.folder, "modules", "templates", THEME, "views", "newsfeed.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP(404, "Unable to open Custom View: %s" % view) s3.js_global.append('''i18n.adv_search="%s"''' % T("Advanced Search")) s3.scripts.append("/%s/static/themes/%s/js/newsfeed.js" % (request.application, THEME)) # Latest 5 Disasters resource = s3db.resource("event_event") layout = render_events list_id = "event_datalist" limit = 5 orderby = "start_date desc" list_fields = ["name", "event_type_id$name", "start_date", "closed", ] output["disasters"] = latest_records(resource, layout, list_id, limit, list_fields, orderby) return output
def _updates(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ #if not current.auth.is_logged_in(): # current.auth.permission.fail() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 current.deployment_settings.ui.customize_cms_post() list_layout = s3.render_posts filter_widgets = [S3TextFilter(["body"], label="", _class="filter-search", #_placeholder=T("Search").upper(), ), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", cols=3, hidden=True, ), S3LocationFilter("location_id", label=T("Filter by Location"), levels=["L1", "L2", "L3"], widget="multiselect", cols=3, hidden=True, ), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), represent="%(name)s", widget="multiselect", cols=3, hidden=True, ), S3DateFilter("created_on", label=T("Filter by Date"), hide_time=True, hidden=True, ), ] s3db.configure("cms_post", # We use a custom Advanced widget filter_advanced = False, filter_formstyle = filter_formstyle, filter_submit = (T("SEARCH"), "btn btn-primary"), filter_widgets = filter_widgets, list_layout = list_layout, # Create form comes via AJAX in a Modal insertable = False, ) s3.dl_pagelength = 6 # 5 forces an AJAX call if "datalist_dl_post" in request.args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in request.args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in request.args: ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl = URL(f="index", args="datalist_dl_post"), filter_ajax_url = URL(f="index", args="datalist_dl_filter", vars={})) if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = T("News Feed") view = path.join(request.folder, "private", "templates", THEME, "views", "updates.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP("404", "Unable to open Custom View: %s" % view) scripts = [] sappend = scripts.append # Style the Search TextFilter widget sappend('''$('#post-cms_post_body-text-filter__row').addClass('input-append').append('<span class="add-on"><i class="icon-search"></i></span>')''') # Button to toggle Advanced Form sappend('''$('#list-filter').append('<a class="accordion-toggle"><i class="icon-reorder"></i> %s</a>')''' % T("Advanced Search")) sappend('''$('.accordion-toggle').click(function(){$('.advanced').toggle()})''') s3.jquery_ready.append('''\n'''.join(scripts)) # Latest 5 Disasters resource = s3db.resource("event_event") list_fields = ["name", "event_type_id$name", "zero_hour", "closed", ] orderby = resource.get_config("list_orderby", ~resource.table.created_on) datalist, numrows, ids = resource.datalist(fields=list_fields, start=None, limit=5, listid="event_datalist", orderby=orderby, layout=render_events) # Render the list data = datalist.html() if numrows == 0: # Empty table or just no match? 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.insert(1, msg) output["disasters"] = data return output
def _updates(): """ Custom Page - Filterable DataList of CMS Posts & a DataList of Events """ if not current.auth.is_logged_in(): return _login() T = current.T s3db = current.s3db request = current.request response = current.response s3 = response.s3 current.deployment_settings.ui.customize_cms_post() list_layout = render_posts filter_widgets = [S3TextFilter(["body"], label="", _class="filter-search", _placeholder=T("Search").upper()), S3OptionsFilter("series_id", label=T("Filter by Type"), represent="%(name)s", widget="multiselect", cols=3), S3LocationFilter("location_id", label=T("Filter by Location"), levels=["L1", "L2", "L3"], #represent="%(name)s", widget="multiselect", cols=3), S3OptionsFilter("created_by$organisation_id", label=T("Filter by Organization"), represent="%(name)s", widget="multiselect", #widget="multiselect-bootstrap", cols=3), S3DateFilter("created_on", label=T("Filter by Date"), hide_time=True), ] s3db.configure("cms_post", filter_formstyle = filter_formstyle, filter_submit = (T("Filter Results"), "btn btn-primary"), filter_widgets = filter_widgets, list_layout = list_layout, # Create form comes via AJAX in a Modal insertable = False, ) s3.dl_pagelength = 6 # 5 forces an AJAX call if "datalist_dl_post" in request.args: # DataList pagination or Ajax-deletion request request.args = ["datalist_f"] ajax = "list" elif "datalist_dl_filter" in request.args: # FilterForm options update request request.args = ["filter"] ajax = "filter" elif "validate.json" in request.args: ajax = True else: # Default request.args = ["datalist_f"] ajax = None def prep(r): if ajax == "list": r.representation = "dl" elif ajax == "filter": r.representation = "json" return True s3.prep = prep output = current.rest_controller("cms", "post", list_ajaxurl = URL(f="index", args="datalist_dl_post"), filter_ajax_url = URL(f="index", args="datalist_dl_filter", vars={})) if ajax == "list": # Don't override view if this is an Ajax-deletion request if not "delete" in request.get_vars: response.view = "plain.html" elif not ajax: # Set Title & View after REST Controller, in order to override output["title"] = response.title = current.deployment_settings.get_system_name() view = path.join(request.folder, "private", "templates", THEME, "views", "updates.html") try: # Pass view as file not str to work in compiled mode response.view = open(view, "rb") except IOError: from gluon.http import HTTP raise HTTP("404", "Unable to open Custom View: %s" % view) # Latest 5 Disasters resource = s3db.resource("event_event") list_fields = ["name", "zero_hour", "closed", ] orderby = resource.get_config("list_orderby", ~resource.table.created_on) datalist, numrows, ids = resource.datalist(fields=list_fields, start=None, limit=5, listid="event_datalist", orderby=orderby, layout=render_events) if numrows == 0: # Empty table or just no match? 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 dl = datalist.html() data = dl output["disasters"] = data return output