def __init__(self, user_id): self.user_id = user_id self.card_title = "Upcoming contests" self.cache_key = CARD_CACHE_REDIS_KEYS["upcoming_contests"] self.ctas = [ dict(btn_text="View all", btn_url=URL("default", "contests"), btn_class="upcoming-contests-card-view-all") ] BaseCard.__init__(self, self.user_id)
def hr_name(row): hr_id = row["event_human_resource.human_resource_id"] return A( hr_represent(hr_id), _href=URL( c="event", f=f, args=[record_id, "human_resource", hr_id, "profile"], ), )
def __init__(self, user_id): self.user_id = user_id self.card_title = "Support StopStalk!" self.stats = None self.ctas = [ dict(btn_url=URL("default", "support_us"), btn_text="Show", btn_class="support-us-card-show") ] BaseCard.__init__(self, user_id)
def incident_name(row): return A( row["event_incident.name"], _href=URL( c="event", f="incident", args=[row["event_incident.id"], "custom"], extension="", # ensure no .aadata ), )
def __init__(self, user_id): self.user_id = user_id self.card_title = "Link more accounts" self.cache_key = CARD_CACHE_REDIS_KEYS["more_accounts_prefix"] + str( self.user_id) self.ctas = [ dict(btn_text="Update now", btn_url=URL("user", "update_details"), btn_class="linked-accounts-card-update-now") ] BaseCard.__init__(self, user_id)
def team_name(row): group_id = row["event_team.group_id"] return A( group_represent(group_id), _href=URL( c="event", f=f, args=[record_id, "group", group_id, "profile"], extension="", # ensure no .aadata ), )
def task_name(row): return A( row["project_task.name"], _href=URL( c="event", f=f, args=[ record_id, "task", row["project_task.id"], "profile" ], ), )
def gen_links(row): diff = A( SPAN(_class="glyphicon glyphicon-random"), _href=URL( 'diff', args=[item.unique_id, row.id]), _class="btn btn-default", _title=T("Differences"), ) return CAT(diff)
def customise_event_incident_report_controller(**attr): from gluon import A s3 = current.response.s3 # Custom prep standard_prep = s3.prep def custom_prep(r): # Call standard postp if callable(standard_prep): result = standard_prep(r) if not result: return False if r.method in (None, "create"): current.s3db.gis_location.addr_street.label = T( "Street Address or Location Details") from s3 import S3SQLCustomForm crud_form = S3SQLCustomForm( (T("What is it?"), "name"), "incident_type_id", (T("Who am I speaking with?"), "reported_by"), (T("How can we contact you?"), "contact"), (T("Where did this Incident take place?"), "location_id"), (T("Explain the Situation?"), "description"), (T("What are your immediate needs?"), "needs"), ) r.resource.configure( create_next=URL(args=["[id]", "assign"]), crud_form=crud_form, ) return True s3.prep = custom_prep # No sidebar menu current.menu.options = None req_args = current.request.args if len(req_args) > 1 and req_args[1] == "assign": attr["rheader"] = A( T("New Incident"), _class="action-btn", _href=URL( c="event", f="incident", args=["create"], vars={"incident_report_id": req_args[0]}, ), ) return attr
def redirection(url=None): session = current.session request = current.request _next = session._next or request.vars._next if _next: session._next = None redirect(_next) elif url: redirect(url) else: redirect(URL('default', 'index'))
def customise_event_incident_controller(**attr): s3db = current.s3db s3 = current.response.s3 # Load default model, so we can over-ride s3db.event_incident from gluon import URL s3db.configure("event_incident", create_next = URL(c="event", f="incident", args=["[id]", "plan"]), ) # Custom prep standard_prep = s3.prep def custom_prep(r): # Call standard postp if callable(standard_prep): result = standard_prep(r) if r.method == "create": incident_report_id = r.get_vars.get("incident_report_id") if incident_report_id: if r.http == "GET": from s3 import s3_truncate rtable = s3db.event_incident_report incident_report = current.db(rtable.id == incident_report_id).select(rtable.name, rtable.incident_type_id, rtable.location_id, limitby = (0, 1), ).first() table = r.table table.name.default = s3_truncate(incident_report.name, 64) table.incident_type_id.default = incident_report.incident_type_id table.location_id.default = incident_report.location_id elif r.http == "POST": def create_onaccept(form): s3db.event_incident_report_incident.insert(incident_id = form.vars.id, incident_report_id = incident_report_id, ) r.resource.configure(create_onaccept = create_onaccept, ) return True s3.prep = custom_prep # No sidebar menu current.menu.options = None attr["rheader"] = event_rheader return attr
def _(): # shortcuts # useful links to internal and external resources response.menu += [(SPAN('web2py', _style='color:yellow'), False, None, [ (T('This App'), False, URL('admin', 'default', 'design/%s' % app), [ (T('Controller'), False, URL('admin', 'default', 'edit/%s/controllers/%s.py' % (app, ctr))), (T('View'), False, URL('admin', 'default', 'edit/%s/views/%s' % (app, response.view))), (T('Layout'), False, URL('admin', 'default', 'edit/%s/views/layout.html' % app)), (T('Stylesheet'), False, URL('admin', 'default', 'edit/%s/static/css/web2py.css' % app)), (T('DB Model'), False, URL('admin', 'default', 'edit/%s/models/db.py' % app)), (T('Menu Model'), False, URL('admin', 'default', 'edit/%s/models/menu.py' % app)), (T('Database'), False, URL(app, 'appadmin', 'index')), (T('Errors'), False, URL('admin', 'default', 'errors/' + app)), (T('About'), False, URL('admin', 'default', 'about/' + app)), ]), ('web2py.com', False, 'http://www.web2py.com', [ (T('Download'), False, 'http://www.web2py.com/examples/default/download'), (T('Support'), False, 'http://www.web2py.com/examples/default/support'), (T('Demo'), False, 'http://web2py.com/demo_admin'), (T('Quick Examples'), False, 'http://web2py.com/examples/default/examples'), (T('FAQ'), False, 'http://web2py.com/AlterEgo'), (T('Videos'), False, 'http://www.web2py.com/examples/default/videos/'), (T('Free Applications'), False, 'http://web2py.com/appliances'), (T('Plugins'), False, 'http://web2py.com/plugins'), (T('Layouts'), False, 'http://web2py.com/layouts'), (T('Recipes'), False, 'http://web2pyslices.com/'), (T('Semantic'), False, 'http://web2py.com/semantic'), ]), ])]
def set_paging(self): self.page = (int(self._request.vars["page"] or 0)) self.items_per_page = int( self._request.vars["per"] if int(self._request.vars["per"] or -1) in Paginater.item_limits else Paginater.item_limits[1]) self.limitby = (self.page * self.items_per_page, (self.page + 1) * self.items_per_page) # 1*5 <-> 2*5+1 for each in self.item_limits: href = URL(args=self._request.args, vars=dict(self._old_vars + { 'per': each, 'page': 0 }.items())) self.items_per_page_urls.append( dict(href=href, number=each, current=each == self.items_per_page)) self.item_count = self._query_set.count() division = self.item_count / float(self.items_per_page) self.pages = int(math.floor( division)) # don't need a new page for not full pages ie. 11/12 if division % 1 == 0: # fixed - there may be a bug with left inner join as not all left from (db.table>0) will show up if right is missing, use left outer join instead. self.pages -= 1 # don't need a new page for a full page ie. 12/12 items for each in xrange(self.pages + 1): # xrange doesn't include last href = URL(args=self._request.args, vars=dict(self._old_vars + {'page': each}.items())) self.page_urls.append( dict(href=href, number=each, current=each == self.page)) self.has_next = self.page < self.pages # need a new page for overfull page ie. 13/12 items, need page for 1/12 self.has_prev = bool(self.page) self.next_page = None if not self.has_next else self.page + 1 # href='{{=URL(vars=dict(page=paginater.next_page))}}' self.next_url = URL(args=self._request.args, vars=dict(self._old_vars + {'page': self.next_page}.items())) self.prev_page = None if not self.has_prev else self.page - 1 self.prev_url = URL(args=self._request.args, vars=dict(self._old_vars + {'page': self.prev_page}.items()))
def custom_prep(r): # Call standard postp if callable(standard_prep): result = standard_prep(r) if r.method == "create" and r.http == "POST": from gluon import URL r.resource.configure(create_next=URL(c="event", f="scenario", args=["[id]", "plan"]), ) return True
def menu_personal(cls): """ Personal Menu """ auth = current.auth #s3 = current.response.s3 settings = current.deployment_settings ADMIN = current.auth.get_system_roles().ADMIN if not auth.is_logged_in(): request = current.request login_next = URL(args=request.args, vars=request.vars) if request.controller == "default" and \ request.function == "user" and \ "_next" in request.get_vars: login_next = request.get_vars["_next"] self_registration = settings.get_security_self_registration() menu_personal = MP()( MP("Register", c="default", f="user", m = "register", check = self_registration, ), MP("Login", c="default", f="user", m = "login", vars = {"_next": login_next}, ), ) if settings.get_auth_password_retrieval(): menu_personal(MP("Lost Password", c="default", f="user", m = "retrieve_password", ), ) else: s3_has_role = auth.s3_has_role is_org_admin = lambda i: not s3_has_role(ADMIN) and \ s3_has_role("ORG_ADMIN") menu_personal = MP()( MP("Administration", c="admin", f="index", restrict = ADMIN, ), MP("Administration", c="admin", f="user", check = is_org_admin, ), MP("Profile", c="default", f="person"), MP("Change Password", c="default", f="user", m = "change_password", ), MP("Logout", c="default", f="user", m = "logout", ), ) return menu_personal
def prep(r): # Call standard prep result = standard_prep(r) if callable(standard_prep) else True table = r.table context = r.get_vars.get("resource") if context == "Privacy": page = URL(c="default", f="index", args=["privacy"]) r.resource.configure( create_next=page, update_next=page, ) table.name.default = "Privacy Notice" elif context == "Legal": page = URL(c="default", f="index", args=["legal"]) r.resource.configure( create_next=page, update_next=page, ) table.name.default = "Legal Notice" return result
def ensure_image_url(self, url): if url.startswith("http"): return url else: parts = url.split("/") return URL(parts[1], parts[2], parts[3], args=parts[4:], scheme=True, host=True, extension=False)
def informe_mes_empleado(): empleados = db(db.empleado.is_active is True).select(db.empleado.ALL) fempl = ([" "] + [f"{p.user_code} {p.nombre} {p.apellido}" for p in empleados]) form = FORM( CENTER( H4('Marcadas del personal'), TABLE( TR( TAG('<label class "control-label">Persona</label>'), SELECT(fempl, _name='fempleado', _type='text', _id="persona", _class="form-control string")), TR( TAG('<label class "control-label">Periodo desde</label>'), INPUT(_name='fdesde', _type='date', _id="mesanio", _class="form-control string", requires=IS_NOT_EMPTY())), TR( TAG('<label class "control-label">Periodo hasta</label>'), INPUT( _name='fhasta', _type='date', _id="mesanio", _class="form-control string", ))), BR(), INPUT(_type="submit", _class="btn btn-primary btn-medium", _value='Continuar'))) if form.accepts(request, session): session.empleado = request.vars['fempleado'] session.user_code = request.vars['fempleado'].split()[0] session.fdesde = request.vars['fdesde'] session.fhasta = request.vars['fhasta'] log(f"seleccionado {session.empleado}") log(f"desde: {session.fdesde} hasta {session.fhasta}") # selector = (db.empleado.user_code == user_code) # usuario = db(selector).select().first().as_dict() session.tdesde = datetime.datetime.strptime(session.fdesde, '%Y-%m-%d') session.thasta = datetime.datetime.strptime(session.fhasta, '%Y-%m-%d') lista = aplico_politica(session.user_code, session.fdesde, session.fhasta) nombre_archivo = f'''{session.empleado} -{session.fdesde}-{session.fhasta}''' session.table = list_dict_to_table_sortable(lista, nombre_archivo) redirect(URL('informe')) else: log(f'acceso {request.function}') return dict(form=form)
def link(self, k, v, row=None): """ Represent a (key, value) as hypertext link @param k: the key (br_case_activity.id) @param v: the representation of the key @param row: the row with this key """ url = URL(c = "vol", f = "person", args = [row.id], extension = "") return A(v, _href = url)
def org_name(row): organisation_id = row["event_organisation.organisation_id"] return A( org_represent(organisation_id), _href=URL( c="event", f=f, args=[ record_id, "organisation", organisation_id, "profile" ], ), )
def edit(): desk = db.desk(request.args(0)) session.desk_id = desk.id db.desk.item_list.readable = False db.desk.item_list.writable = False form = SQLFORM(db.desk, record=desk, showid=False) if form.process().accepted: redirect(URL('index', args=[desk.id])) return locals()
def approve_user(r, **args): from gluon import redirect db = current.db user = db(db.auth_user.id == r.id).select(limitby=(0, 1)).first() org_group_id = user.org_group_id if org_group_id: # Check if this is a COVID-19 Test Station ogtable = current.s3db.org_group org_group = db(ogtable.id == org_group_id).select( ogtable.name, limitby=(0, 1)).first() if org_group and org_group.name == TESTSTATIONS: # Custom Approval process redirect( URL(c="default", f="index", args=["approve", r.id])) # Default Approval auth.s3_approve_user(user) current.session.confirmation = T("User Account has been Approved") redirect(URL(args=[r.id, "roles"]))
def get_user(self): """ Returns the user info """ token = self.accessToken() if not token: return None session = current.session user = None try: user = self.call_api(token) except Exception: session.token = None user_dict = None if user: #if "email" not in user: # # Non-standard key for "email" claim # email = user.get("mail") #else: email = user.get("email") if not email: msg = "OpenID Connect: unidentifiable user %s" % user.get( "sub") current.session.warning = msg current.log.warning(msg) redirect(URL(c="default", f="user", args=["login"])) # Check if a user with this email has already registered table = current.auth.settings.table_user query = (table.email == email) existing = current.db(query).select(table.id, table.password, limitby=(0, 1)).first() if existing: user_dict = {"email": email, "password": existing.password} else: first_name = user.get("given_name", "") last_name = user.get("family_name", "") if not first_name and not last_name and "name" in user: # Try to parse the combined 'name' field from nameparser import HumanName name = HumanName(user.get("name", "")) first_name = name.first last_name = name.last user_dict = { "first_name": first_name, "last_name": last_name, "email": email, } return user_dict
def __init__(self, user_id): self.user_id = user_id self.card_title = "Looking for job!" self.cache_key = CARD_CACHE_REDIS_KEYS["job_profile_prefix"] + str( self.user_id) self.ctas = [ dict(btn_text="Update job preferences", btn_url=URL("default", "job_profile"), btn_class="job-profile-card-update-preferences") ] BaseCard.__init__(self, user_id)
def add_to_book_button(self): user = self.session.auth.user if self.session.auth else None if user: already = self.db.CookRecipeBook(article_id=int( self.request.args(0)), user_id=user.id) if already: bt = BUTTON( TAG.I(_class="icon-minus", _style="margin-right:5px"), self.T("Remove from book!"), _class= "button already-on-book btn btn-danger addtobookbutton", _onclick="ajax('%s', [], 'addtobookbutton');" % URL('cookrecipe', 'removefrombook', args=[self.request.args(0), 'show'])) else: bt = BUTTON( TAG.I(_class="icon-plus", _style="margin-right:5px"), self.T("Add to my book"), _class= "button button not-on-book btn btn-success addtobookbutton", _onclick="ajax('%s', [], 'addtobookbutton');" % URL('cookrecipe', 'addtobook', args=[self.request.args(0), 'show'])) else: bt = BUTTON( TAG.I(_class="icon-plus", _style="margin-right:5px"), self.T("Add to my book"), _class= "button button not-on-book btn btn-success addtobookbutton", _onclick="window.location = '%s';" % URL('person', 'account', args='login', vars=dict(_next=self.CURL( 'article', 'show', args=[self.request.args(0), 'show' ])))) return bt
def customise_doc_document_resource(r, tablename): from gluon import URL from s3 import S3SQLCustomForm, S3TextFilter from templates.UCCE.controllers import doc_document_list_layout from templates.UCCE.controllers import text_filter_formstyle current.response.s3.crud_strings[tablename] = Storage( label_create=T("New guide"), title_display=T("Guide Details"), #title_list = T("Guides"), title_list="", title_update=T("Edit Guide"), #title_upload = T("Import Guides"), label_list_button=T("List Guides"), label_delete_button=T("Delete Guide"), msg_record_created=T("Guide added"), msg_record_modified=T("Guide updated"), msg_record_deleted=T("Guide deleted"), msg_list_empty=T("No Guides currently registered")) s3db = current.s3db f = s3db.doc_document.comments f.comment = None s3db.configure( "doc_document", create_next=URL(args="datalist"), crud_form=S3SQLCustomForm( "name", "file", "comments", ), list_fields=[ "name", "file", "comments", ], list_layout=doc_document_list_layout, filter_widgets=[ S3TextFilter( [ "name", ], formstyle=text_filter_formstyle, label="", _placeholder=T("Search guides"), ), ], )
def create(): if not session.marked_items: session.flash = T('You must mark some items first') redirect(URL('default', 'index')) fields = [] # i need the input of the based item fields fdl_headline = db.item.headline fields.append(fdl_headline) fdl_keywords = db.item.keywords keywords_list = [] for item_id in session.marked_items: _item = application.getItemByUUID(item_id) keywords_list.extend(_item.keywords) keywords_list = list(set(keywords_list)) # remove any dup fdl_keywords.default = keywords_list fields.append(fdl_keywords) fields.append(db.item.genre) fdl_item_type = db.item.item_type fdl_item_type.writable = False fdl_item_type.readable = False fdl_item_type.default = 'package' fields.append(db.plugin_package_content.description) form = SQLFORM.factory( *fields, table_name='plugin_package_item' # to allow the correct file name ) if form.process(dbio=False).accepted: form.vars.item_id = application.createItem('package', form.vars) form.vars.item_list = session.marked_items db.plugin_package_content.insert( **db.plugin_package_content._filter_fields(form.vars)) application.indexItem(form.vars.item_id) session.marked_items = [] redirect(URL('default', 'index')) return locals()
def get_html(self): problem_details = self.get_data() self.ctas = [ dict(btn_text="Write Editorial", btn_url=URL("problems", "editorials", args=problem_details["id"], vars=dict(write_editorial=True)), btn_class="last-solved-problem-write-editorial"), dict(btn_text="Suggest tags", btn_url=URL("problems", "index", vars=dict(problem_id=problem_details["id"], suggest_tag=True)), btn_class="last-solved-problem-suggest-tags"), dict(btn_text="Suggest difficulty", btn_url=URL("problems", "index", vars=dict(problem_id=problem_details["id"], suggest_difficulty=True)), btn_class="last-solved-problem-suggest-difficulty") ] card_content = SPAN( "You just solved ", utilities.problem_widget(problem_details["name"], problem_details["link"], "solved-problem", "Solved Problem", problem_details["id"]), ". You can write editorials on StopStalk and help the community.") card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def __init__(self, user_id): self.user_id = user_id self.card_title = "Recent Friends' submissions" self.cache_key = CARD_CACHE_REDIS_KEYS[ "recent_submissions_prefix"] + str(user_id) self.final_data = None self.ctas = [ dict(btn_text="View all", btn_url=URL("default", "submissions", args=[1]), btn_class="recent-submissions-card-view-all") ] BaseCard.__init__(self, user_id)
def __init__(self, user_id): self.user_id = user_id self.final_pid = None self.card_title = "Link AtCoder now!" self.ctas = [ dict(btn_url=URL("user", "update_details"), btn_text="Update Now", btn_class="atcoder-handle-card-update-now") ] BaseCard.__init__(self, user_id) self.sunset_card_date = datetime.datetime.strptime( "2020-10-15 00:00:00", "%Y-%m-%d %H:%M:%S")