def user(): if request.vars._formname == 'login': session.username = request.vars.username session.password = request.vars.password if request.args(0) == 'not_authorized': raise HTTP(403, 'forbidden') else: if auth.user and request.args(0) in ('login', None): redirect('/baadal/user') from gluon.html import INPUT, H2, A form = auth() el = list() el.append(H2('Please log in')) label = LABEL('Email address') label.attributes['_for'] = 'auth_user_username' label.add_class('sr-only') el.append(label) for i in form.elements(): if isinstance(i, INPUT): if i.attributes['_type'] in ('text', 'password'): i.add_class('form-control') if i.attributes['_type'] == 'submit': i.add_class('btn btn-primary btn-lg btn-block') el.append(i) link = A('Request an account', callback='/baadal/user/register') link.add_class('btn btn-link') el.append(link) form.components = el form.add_class('form-signin') return dict(form=form)
def CONFIRM_BOX(request, session, title="Delete Record", label="Are you sure you want to delete this record?", content="", func_yes=lambda v: v, func_no=lambda v: v): form = FORM( DIV( P(LABEL(label), _class="centered"), P(BUTTON("Yes", _type="submit", _name="yes", _value="yes"), _class="centered"), P(BUTTON("No", _type="submit", _name="no", _value="no"), _class="centered"), )) html = DIV( H2(title), DIV(DIV(form, P(content), _id="padding"), _id="user_action"), ) if form.accepts(request.vars, session): if request.vars.yes == "yes": func_yes() else: func_no() elif form.errors: response.flash = "There were errors with the form" return html
def test_H2(self): self.assertEqual( H2('<>', _a='1', _b='2').xml(), b'<h2 a="1" b="2"><></h2>')
def rdrt_member_profile_header(r): """ Custom profile header to allow update of RDRT roster status """ record = r.record if not record: return "" person_id = record.person_id from s3 import s3_fullname, s3_avatar_represent name = s3_fullname(person_id) table = r.table # Organisation comments = table.organisation_id.represent(record.organisation_id) from s3 import s3_unicode from gluon.html import A, DIV, H2, LABEL, P, SPAN # Add job title if present job_title_id = record.job_title_id if job_title_id: comments = (SPAN("%s, " % \ s3_unicode(table.job_title_id.represent(job_title_id))), comments) # Determine the current roster membership status (active/inactive) atable = current.s3db.deploy_application status = atable.active query = atable.human_resource_id == r.id row = current.db(query).select(atable.id, atable.active, limitby=(0, 1)).first() if row: active = 1 if row.active else 0 status_id = row.id roster_status = status.represent(row.active) else: active = None status_id = None roster_status = current.messages.UNKNOWN_OPT if status_id and \ current.auth.s3_has_permission("update", "deploy_application", record_id=status_id): # Make inline-editable roster_status = A(roster_status, data = {"status": active}, _id = "rdrt-roster-status", _title = T("Click to edit"), ) s3 = current.response.s3 script = "/%s/static/themes/IFRC/js/rdrt.js" % r.application if script not in s3.scripts: s3.scripts.append(script) script = '''$.rdrtStatus('%(url)s','%(active)s','%(inactive)s','%(submit)s')''' from gluon import URL options = {"url": URL(c="deploy", f="application", args=["%s.s3json" % status_id]), "active": status.represent(True), "inactive": status.represent(False), "submit": T("Save"), } s3.jquery_ready.append(script % options) else: # Read-only roster_status = SPAN(roster_status) # Render profile header return DIV(A(s3_avatar_represent(person_id, tablename="pr_person", _class="media-object", ), _class="pull-left", ), H2(name), P(comments), DIV(LABEL(status.label + ": "), roster_status), _class="profile-header", )
def apply_method(self, r, **attr): """ Entry point for REST API @param r: the request (S3Request) @param attr: REST controller parameters """ if r.record and r.representation in ("html", "aadata"): T = current.T db = current.db s3db = current.s3db auth = current.auth is_admin = auth.s3_has_role("ADMIN") accessible = auth.s3_accessible_query # Profile widgets profile_widgets = [] add_widget = profile_widgets.append dt_row_actions = self.dt_row_actions from s3 import FS # Organisations widget = { "label": T("My Organizations"), "icon": "organisation", "insert": False, "tablename": "org_organisation", "type": "datatable", "actions": dt_row_actions("org", "organisation"), "list_fields": [ "name", (T("Type"), "organisation_organisation_type.organisation_type_id"), "phone", (T("Email"), "email.value"), "website", ], } if not is_admin: otable = s3db.org_organisation rows = db(accessible("update", "org_organisation")).select(otable.id) organisation_ids = [row.id for row in rows] widget["filter"] = FS("id").belongs(organisation_ids) add_widget(widget) # Facilities widget = { "label": T("My Facilities"), "icon": "facility", "insert": False, "tablename": "org_facility", "type": "datatable", "actions": dt_row_actions("org", "facility"), "list_fields": [ "name", "code", "site_facility_type.facility_type_id", "organisation_id", "location_id", ], } if not is_admin: ftable = s3db.org_facility rows = db(accessible("update", "org_facility")).select(ftable.id) facility_ids = [row.id for row in rows] widget["filter"] = FS("id").belongs(facility_ids) add_widget(widget) # Networks (only if user can update any records) widget_filter = None if not is_admin: gtable = s3db.org_group rows = db(accessible("update", "org_group")).select(gtable.id) group_ids = [row.id for row in rows] if group_ids: widget_filter = FS("id").belongs(group_ids) if is_admin or widget_filter: widget = { "label": T("My Networks"), "icon": "org-network", "insert": False, "tablename": "org_group", "filter": widget_filter, "type": "datatable", "actions": dt_row_actions("org", "group"), } add_widget(widget) # Groups (only if user can update any records) widget_filter = None if not is_admin: gtable = s3db.pr_group rows = db(accessible("update", "pr_group")).select(gtable.id) group_ids = [row.id for row in rows] if group_ids: widget_filter = FS("id").belongs(group_ids) if is_admin or widget_filter: widget = { "label": T("My Groups"), "icon": "group", "insert": False, "tablename": "pr_group", "filter": widget_filter, "type": "datatable", "actions": dt_row_actions("hrm", "group"), "list_fields": [ (T("Network"), "group_team.org_group_id"), "name", "description", (T("Chairperson"), "chairperson"), ], } add_widget(widget) # CMS Content from gluon.html import A, DIV, H2, TAG item = None title = T("Dashboard") if current.deployment_settings.has_module("cms"): name = "Dashboard" ctable = s3db.cms_post query = (ctable.name == name) & (ctable.deleted != True) row = db(query).select(ctable.id, ctable.title, ctable.body, limitby=(0, 1)).first() get_vars = { "page": name, "url": URL(args="dashboard", vars={}), } if row: title = row.title if is_admin: item = DIV( XML(row.body), DIV( A( T("Edit"), _href=URL( c="cms", f="post", args=[row.id, "update"], vars=get_vars, ), _class="action-btn", ), _class="cms-edit", ), ) else: item = DIV(XML(row.body)) elif is_admin: item = DIV( DIV( A( T("Edit"), _href=URL( c="cms", f="post", args="create", vars=get_vars, ), _class="action-btn", ), _class="cms-edit", )) # Rheader if r.representation == "html": profile_header = DIV( DIV( DIV(A( T("Personal Profile"), _href=URL(c="default", f="person"), _class="action-btn", ), _class="dashboard-links right", _style="padding:0.5rem 0;"), H2(title), _class="medium-6 columns end", ), _class="row", ) if item: # Append CMS content profile_header = TAG[""]( profile_header, DIV( DIV( item, _class="medium-12 columns", ), _class="row", ), ) else: profile_header = None # Configure profile tablename = r.tablename s3db.configure( tablename, profile_cols=2, profile_header=profile_header, profile_widgets=profile_widgets, ) # Render profile from s3 import S3Profile profile = S3Profile() profile.tablename = tablename profile.request = r output = profile.profile(r, **attr) if r.representation == "html": output["title"] = \ current.response.title = T("Personal Dashboard") return output else: raise HTTP(501, current.ERROR.BAD_METHOD)