def __call__(self): T = current.T db = current.db s3db = current.s3db s3 = current.response.s3 session_s3 = current.session.s3 output = {} # Recent Updates etable = s3db.event_event stable = s3db.event_sitrep query = (stable.deleted == False) fields = [ etable.name, stable.id, stable.date, stable.name, stable.summary, ] left = [etable.on(etable.id == stable.event_id)] language = session_s3.language if language != current.deployment_settings.get_L10n_default_language(): ntable = s3db.event_event_name left.append(ntable.on((ntable.event_id == etable.id) & \ (ntable.language == language))) fields.append(ntable.name_l10n) use_local_event_name = True else: use_local_event_name = False sitreps = db(query).select(left=left, limitby=(0, 3), orderby=~stable.date, *fields) len_sitreps = len(sitreps) if len_sitreps == 0: from s3 import S3CRUD recent_updates = DIV(S3CRUD.crud_string("event_sitrep", "msg_list_empty"), _class="empty") else: recent_updates = DIV() rappend = recent_updates.append count = 0 for s in sitreps: count += 1 if use_local_event_name: event_name = s["event_event_name.name_l10n"] or s[ "event_event.name"] else: event_name = s["event_event.name"] if not event_name: event_name = s["event_sitrep.name"] rappend( H3( A( event_name, _href=URL( c="event", f="sitrep", args=[s["event_sitrep.id"]], ), ))) rappend(P(XML(s["event_sitrep.summary"]))) if count != len_sitreps: rappend(HR()) output["recent_updates"] = recent_updates map_btn = A( T("MAP OF CURRENT NEEDS"), #_href = URL(c="default", # f="index", # args="dashboard", # ), _href=URL( c="req", f="need_line", args="map", ), _class="small primary button", ) create_btn = A( T("CREATE A NEED"), _href=URL( c="req", f="need", args="create", ), _class="small primary button", ) output["needs_btn"] = DIV( SPAN(map_btn), SPAN(create_btn), _class="button-group radius", ) output["about_btn"] = A( "%s >" % T("Read More"), _href=URL( c="default", f="about", ), ) # Resources section if current.deployment_settings.has_module("cms"): system_roles = current.auth.get_system_roles() ADMIN = system_roles.ADMIN in session_s3.roles table = s3db.cms_post ltable = s3db.cms_post_module module = "default" resource = "index" query = (ltable.module == module) & \ ((ltable.resource == None) | \ (ltable.resource == resource)) & \ (ltable.post_id == table.id) & \ (table.deleted != True) item = current.db(query).select(table.body, table.id, limitby=(0, 1)).first() if item: if ADMIN: item = DIV( XML(item.body), BR(), A(T("Edit"), _href=URL(c="cms", f="post", args=[item.id, "update"]), _class="action-btn")) else: item = DIV(XML(item.body)) elif ADMIN: if s3.crud.formstyle == "bootstrap": _class = "btn" else: _class = "action-btn" item = A(T("Edit"), _href=URL(c="cms", f="post", args="create", vars={ "module": module, "resource": resource }), _class="%s cms-edit" % _class) else: item = "" else: item = "" output["item"] = item # Inject D3 scripts from s3 import S3Report S3Report.inject_d3() # Inject charts-script appname = current.request.application scripts = s3.scripts if s3.debug: script = "/%s/static/scripts/S3/s3.ui.charts.js" % appname if script not in scripts: scripts.append(script) else: script = "/%s/static/scripts/S3/s3.ui.charts.min.js" % appname if script not in scripts: scripts.append(script) # Instantiate charts scriptopts = { # Standard SHARE theme color set: "colors": [ '#0C9CD0', # blue '#E03158', # red '#FBA629', # amber '#8ABC3F', # green '#AFB8BF', # grey ], } script = '''$('.homepage-chart').uiChart(%s)''' % json.dumps( scriptopts) s3.jquery_ready.append(script) # Add last update time of chart data last_update = HomepageStatistics.last_update() if last_update: output["last_stats_update"] = T("Updated on %(date)s") % { "date": last_update } else: output["last_stats_update"] = None self._view(THEME, "index.html") return output
def __call__(self): T = current.T db = current.db s3db = current.s3db s3 = current.response.s3 session_s3 = current.session.s3 output = {} # Recent Updates etable = s3db.event_event stable = s3db.event_sitrep query = (stable.deleted == False) fields = [etable.name, stable.id, stable.date, stable.name, stable.summary, ] left = [etable.on(etable.id == stable.event_id)] language = session_s3.language if language != current.deployment_settings.get_L10n_default_language(): ntable = s3db.event_event_name left.append(ntable.on((ntable.event_id == etable.id) & \ (ntable.language == language))) fields.append(ntable.name_l10n) use_local_event_name = True else: use_local_event_name = False sitreps = db(query).select(left = left, limitby = (0, 3), orderby = ~stable.date, *fields ) len_sitreps = len(sitreps) if len_sitreps == 0: from s3 import S3CRUD recent_updates = DIV(S3CRUD.crud_string("event_sitrep", "msg_list_empty"), _class="empty") else: recent_updates = DIV() rappend = recent_updates.append count = 0 for s in sitreps: count += 1 if use_local_event_name: event_name = s["event_event_name.name_l10n"] or s["event_event.name"] else: event_name = s["event_event.name"] if not event_name: event_name = s["event_sitrep.name"] rappend(H3(A(event_name, _href = URL(c = "event", f = "sitrep", args = [s["event_sitrep.id"]], ), ))) rappend(P(XML(s["event_sitrep.summary"]))) if count != len_sitreps: rappend(HR()) output["recent_updates"] = recent_updates map_btn = A(T("MAP OF CURRENT NEEDS"), #_href = URL(c="default", # f="index", # args="dashboard", # ), _href = URL(c="req", f="need_line", args="map", ), _class = "small primary button", ) create_btn = A(T("CREATE A NEED"), _href = URL(c="req", f="need", args="create", ), _class = "small primary button", ) output["needs_btn"] = DIV(SPAN(map_btn), SPAN(create_btn), _class="button-group radius", ) output["about_btn"] = A("%s >" % T("Read More"), _href = URL(c="default", f="about", ), ) # Resources section if current.deployment_settings.has_module("cms"): system_roles = current.auth.get_system_roles() ADMIN = system_roles.ADMIN in session_s3.roles table = s3db.cms_post ltable = s3db.cms_post_module module = "default" resource = "index" query = (ltable.module == module) & \ ((ltable.resource == None) | \ (ltable.resource == resource)) & \ (ltable.post_id == table.id) & \ (table.deleted != True) item = current.db(query).select(table.body, table.id, limitby=(0, 1)).first() if item: if ADMIN: item = DIV(XML(item.body), BR(), A(T("Edit"), _href=URL(c="cms", f="post", args=[item.id, "update"]), _class="action-btn")) else: item = DIV(XML(item.body)) elif ADMIN: if s3.crud.formstyle == "bootstrap": _class = "btn" else: _class = "action-btn" item = A(T("Edit"), _href=URL(c="cms", f="post", args="create", vars={"module": module, "resource": resource }), _class="%s cms-edit" % _class) else: item = "" else: item = "" output["item"] = item # Inject D3 scripts from s3 import S3Report S3Report.inject_d3() # Inject charts-script appname = current.request.application scripts = s3.scripts if s3.debug: script = "/%s/static/scripts/S3/s3.ui.charts.js" % appname if script not in scripts: scripts.append(script) else: script = "/%s/static/scripts/S3/s3.ui.charts.min.js" % appname if script not in scripts: scripts.append(script) # Instantiate charts scriptopts = { # Standard SHARE theme color set: "colors": ['#0C9CD0', # blue '#E03158', # red '#FBA629', # amber '#8ABC3F', # green '#AFB8BF', # grey ], } script = '''$('.homepage-chart').uiChart(%s)''' % json.dumps(scriptopts) s3.jquery_ready.append(script) # Add last update time of chart data last_update = HomepageStatistics.last_update() if last_update: output["last_stats_update"] = T("Updated on %(date)s") % {"date": last_update} else: output["last_stats_update"] = None self._view(THEME, "index.html") return output
def __call__(self): T = current.T db = current.db s3db = current.s3db output = {} # Recent Updates etable = s3db.event_event stable = s3db.event_sitrep query = (stable.deleted == False) & \ (stable.event_id == etable.id) fields = [ etable.name, stable.date, stable.summary, ] language = current.session.s3.language if language != current.deployment_settings.get_L10n_default_language(): ntable = s3db.event_event_name left = ntable.on((ntable.event_id == etable.id) & \ (ntable.language == language)) fields.append(ntable.name_l10n) else: left = None sitreps = db(query).select(left=left, limitby=(0, 3), orderby=~stable.date, *fields) len_sitreps = len(sitreps) if len_sitreps == 0: from s3 import S3CRUD recent_updates = DIV(S3CRUD.crud_string("event_sitrep", "msg_list_empty"), _class="empty") else: recent_updates = DIV() rappend = recent_updates.append count = 0 for s in sitreps: count += 1 if left: event_name = s["event_event_name.name_l10n"] or s[ "event_event.name"] else: event_name = s["event_event.name"] rappend(H3(event_name)) rappend(P(s["event_sitrep.summary"])) if count != len_sitreps: rappend(HR()) output["recent_updates"] = recent_updates map_btn = A( T("MAP OF CURRENT NEEDS"), #_href = URL(c="default", # f="index", # args="dashboard", # ), _href=URL( c="req", f="need_line", args="map", ), _class="small primary button", ) create_btn = A( T("CREATE A NEED"), _href=URL( c="req", f="need", args="create", ), _class="small primary button", ) output["needs_btn"] = DIV( SPAN(map_btn), SPAN(create_btn), _class="button-group radius", ) output["about_btn"] = A( "%s >" % T("Read More"), _href=URL( c="default", f="about", ), ) self._view(THEME, "index.html") # Inject D3 scripts from s3 import S3Report S3Report.inject_d3() # Inject charts-script appname = current.request.application s3 = current.response.s3 scripts = s3.scripts if s3.debug: script = "/%s/static/scripts/S3/s3.ui.charts.js" % appname if script not in scripts: scripts.append(script) else: script = "/%s/static/scripts/S3/s3.ui.charts.min.js" % appname if script not in scripts: scripts.append(script) # Instantiate charts scriptopts = { # Standard SHARE theme color set: "colors": [ '#0C9CD0', # blue '#E03158', # red '#FBA629', # amber '#8ABC3F', # green '#AFB8BF', # grey ], } script = '''$('.homepage-chart').uiChart(%s)''' % json.dumps( scriptopts) s3.jquery_ready.append(script) return output
def __call__(self): T = current.T db = current.db s3db = current.s3db output = {} # Recent Updates etable = s3db.event_event stable = s3db.event_sitrep query = (stable.deleted == False) fields = [etable.name, stable.date, stable.name, stable.summary, ] left = [etable.on(etable.id == stable.event_id)] language = current.session.s3.language if language != current.deployment_settings.get_L10n_default_language(): ntable = s3db.event_event_name left.append(ntable.on((ntable.event_id == etable.id) & \ (ntable.language == language))) fields.append(ntable.name_l10n) use_local_event_name = True else: use_local_event_name = False sitreps = db(query).select(left = left, limitby = (0, 3), orderby = ~stable.date, *fields ) len_sitreps = len(sitreps) if len_sitreps == 0: from s3 import S3CRUD recent_updates = DIV(S3CRUD.crud_string("event_sitrep", "msg_list_empty"), _class="empty") else: recent_updates = DIV() rappend = recent_updates.append count = 0 for s in sitreps: count += 1 if use_local_event_name: event_name = s["event_event_name.name_l10n"] or s["event_event.name"] else: event_name = s["event_event.name"] if not event_name: event_name = s["event_sitrep.name"] rappend(H3(event_name)) rappend(P(XML(s["event_sitrep.summary"]))) if count != len_sitreps: rappend(HR()) output["recent_updates"] = recent_updates map_btn = A(T("MAP OF CURRENT NEEDS"), #_href = URL(c="default", # f="index", # args="dashboard", # ), _href = URL(c="req", f="need_line", args="map", ), _class = "small primary button", ) create_btn = A(T("CREATE A NEED"), _href = URL(c="req", f="need", args="create", ), _class = "small primary button", ) output["needs_btn"] = DIV(SPAN(map_btn), SPAN(create_btn), _class="button-group radius", ) output["about_btn"] = A("%s >" % T("Read More"), _href = URL(c="default", f="about", ), ) self._view(THEME, "index.html") # Inject D3 scripts from s3 import S3Report S3Report.inject_d3() # Inject charts-script appname = current.request.application s3 = current.response.s3 scripts = s3.scripts if s3.debug: script = "/%s/static/scripts/S3/s3.ui.charts.js" % appname if script not in scripts: scripts.append(script) else: script = "/%s/static/scripts/S3/s3.ui.charts.min.js" % appname if script not in scripts: scripts.append(script) # Instantiate charts scriptopts = { # Standard SHARE theme color set: "colors": ['#0C9CD0', # blue '#E03158', # red '#FBA629', # amber '#8ABC3F', # green '#AFB8BF', # grey ], } script = '''$('.homepage-chart').uiChart(%s)''' % json.dumps(scriptopts) s3.jquery_ready.append(script) # Add last update time of chart data last_update = HomepageStatistics.last_update() if last_update: output["last_stats_update"] = T("Updated on %(date)s") % {"date": last_update} else: output["last_stats_update"] = None return output