def custom_form(id=None): form = Form(db.person, id, deletable=False, formstyle=FormStyleDefault) rows = db(db.person).select() return dict(form=form, rows=rows)
def tagsinput_form(): form = Form([Field("colors", "list:string")], keep_values=True) return dict(form=form)
def tagsinput_form(): form = Form([Field('colors', 'list:string')], keep_values=True) return dict(form=form)
def mycomponent(): flash.set('Welcome') form = Form([Field("your_name")]) return DIV("Hello " + request.forms["your_name"] if form.accepted else form).xml()
def form_example2(id): form = Form(db.order, id) rows = db(db.order).select() return dict(form=form, rows=rows)
def example_form(id=None): form = Form(db.person, id, deletable=False, formstyle=FormStyleBulma) rows = db(db.person).select() return dict(form=form, rows=rows)
def process(self): query = None db = self.db if not self.param.search_form and self.param.search_queries: search_type = safe_int(request.query.get("search_type", 0), default=0) search_string = request.query.get("search_string") if search_type < len(self.param.search_queries) and search_string: query_lambda = self.param.search_queries[search_type][1] try: query = query_lambda(search_string) except: pass # flash a message here if not query: query = self.param.query else: query &= self.param.query parts = self.path.split("/") self.action = parts[0] or "select" self.tablename = self.get_tablenames( self.param.query)[0] # what if there ar 2? self.record_id = safe_int(parts[1] if len(parts) > 1 else None, default=None) if self.param.fields: if not isinstance(self.param.fields, list): self.param.fields = [self.param.fields] else: table = db[self.tablename] self.param.fields = [field for field in table if field.readable] self.readonly_fields = [ field for field in self.param.fields if not field.writable ] self.referrer = None if not self.tablename: raise HTTP(400) if self.action in ["new", "details", "edit"]: # SECURITY: if the record does not exist or does not match query, than we are not allowed if self.record_id: if (db((db[self.tablename]._id == self.record_id) & self.param.query).count() == 0): redirect(self.endpoint) ## maybe flash readonly = self.action == "details" for field in self.readonly_fields: db[field.tablename][field.name].writable = False if not self.param.show_id: # if not show id, find the "id" field and set readable/writable to False for field in db[self.tablename]: if field.type == "id": db[self.tablename][field.name].readable = False db[self.tablename][field.name].writable = False self.form = Form( db[self.tablename], record=self.record_id, readonly=readonly, formstyle=self.param.formstyle, ) # SECURITY: if the new record was created but does not match filter, delete it if self.form.accepted and not self.record_id: new_record = db[self.tablename]._id == self.form.vars["id"] if db(new_record & self.param.query).count() == 0: db(new_record).delete() # TODO: SHOULD FLASH SOME MESSAGE # redirect to the referrer if self.form.accepted or (readonly and request.method == "POST"): referrer = request.query.get("_referrer") if referrer: redirect( base64.b16decode( referrer.encode("utf8")).decode("utf8")) else: redirect(self.endpoint) elif self.action == "delete": db(db[self.tablename].id == self.record_id).delete() redirect(self.endpoint) elif self.action == "select": self.referrer = "_referrer=%s" % base64.b16encode( request.url.encode("utf8")).decode("utf8") # find the primary key of the primary table pt = db[self.tablename] key_is_missing = True for field in self.param.fields: if field.table._tablename == pt._tablename and field.name == pt._id.name: key_is_missing = False if key_is_missing: # primary key wasn't included, add it and set show_id to False so it doesn't display self.param.fields.append(pt._id) self.param.show_id = False self.current_page_number = safe_int(request.query.get("page"), default=1) select_params = dict() # try getting sort order from the request sort_order = request.query.get("orderby", "") try: parts = sort_order.lstrip("~").split(".") orderby = db[parts[0]][parts[1]] if sort_order.startswith("~"): orderby = ~orderby select_params["orderby"] = orderby except (IndexError, KeyError, TypeError, AttributeError): select_params["orderby"] = self.param.orderby if self.param.left: select_params["left"] = self.param.left if self.param.left: # TODO: maybe this can be made more efficient self.total_number_of_rows = len( db(query).select(db[self.tablename].id, **select_params)) else: self.total_number_of_rows = db(query).count() # if at a high page number and then filter causes less records to be displayed, reset to page 1 if (self.current_page_number - 1) * self.param.rows_per_page > self.total_number_of_rows: self.current_page_number = 1 if self.total_number_of_rows > self.param.rows_per_page: self.page_start = self.param.rows_per_page * ( self.current_page_number - 1) self.page_end = self.page_start + self.param.rows_per_page select_params["limitby"] = (self.page_start, self.page_end) else: self.page_start = 0 if self.total_number_of_rows > 1: self.page_start = 1 self.page_end = self.total_number_of_rows if self.param.fields: self.rows = db(query).select(*self.param.fields, **select_params) else: self.rows = db(query).select(**select_params) self.number_of_pages = self.total_number_of_rows // self.param.rows_per_page if self.total_number_of_rows % self.param.rows_per_page > 0: self.number_of_pages += 1 else: redirect(self.endpoint)
def form_example(id): form = Form(db.thing, id) rows = db(db.thing).select() return dict(form=form, rows=rows)
def new(): #form=Form(db.post,formstyle=FormStyleBulma) form = Form(db.post) return dict(form=form)
def add_contact(): form = Form(db.contact, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: # We always want POST requests to be redirected as GETs. redirect(URL('index')) return dict(form=form)
def forms(): ctrl_info = "ctrl: forms, view: forms.html" page_url = "\'" + URL('forms') + "\'" messages = [] fforms0 = Form(db.dfforms0, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms0.accepted: prn_form_vars(fforms0, db.dfforms0) elif fforms0.errors: print("fforms0 has errors: %s " % (fforms0.errors)) fforms1 = Form(db.dfforms1, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms1.accepted: prn_form_vars(fforms1, db.dfforms1) elif fforms1.errors: print("fforms1 has errors: %s " % (fforms1.errors)) fforms2 = Form(db.dfforms2, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms2.accepted: prn_form_vars(fforms2, db.dfforms2) elif fforms2.errors: print("fforms2 has errors: %s " % (fforms2.errors)) fforms3 = Form(db.dfforms3, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms3.accepted: prn_form_vars(fforms3, db.dfforms3) elif fforms3.errors: print("fforms3 has errors: %s " % (fforms3.errors)) fforms4 = Form(db.dfforms4, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms4.accepted: prn_form_vars(fforms4, db.dfforms4) elif fforms4.errors: print("fforms4 has errors: %s " % (fforms4.errors)) fforms5 = Form(db.dfforms5, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms5.accepted: prn_form_vars(fforms5, db.dfforms5) elif fforms5.errors: print("fforms5 has errors: %s " % (fforms5.errors)) fforms6 = Form(db.dfforms6, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms6.accepted: prn_form_vars(fforms6, db.dfforms6) elif fforms6.errors: print("fforms6 has errors: %s " % (fforms6.errors)) return locals()
def forms(): ctrl_info = "ctrl: forms, view: forms.html" page_url = "\'" + URL('forms') + "\'" messages = [] fforms0 = Form(db.dfforms0, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms0.accepted: prn_form_vars(fforms0, db.dfforms0) elif fforms0.errors: print("fforms0 has errors: %s " % (fforms0.errors)) fforms1 = Form(db.dfforms1, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms1.accepted: prn_form_vars(fforms1, db.dfforms1) elif fforms1.errors: print("fforms1 has errors: %s " % (fforms1.errors)) fforms2 = Form(db.dfforms2, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms2.accepted: prn_form_vars(fforms2, db.dfforms2) elif fforms2.errors: print("fforms2 has errors: %s " % (fforms2.errors)) fforms3 = Form(db.dfforms3, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms3.accepted: prn_form_vars(fforms3, db.dfforms3) elif fforms3.errors: print("fforms3 has errors: %s " % (fforms3.errors)) fforms4 = Form(db.dfforms4, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms4.accepted: prn_form_vars(fforms4, db.dfforms4) elif fforms4.errors: print("fforms4 has errors: %s " % (fforms4.errors)) fforms5 = Form(db.dfforms5, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms5.accepted: prn_form_vars(fforms5, db.dfforms5) elif fforms5.errors: print("fforms5 has errors: %s " % (fforms5.errors)) fforms6 = Form(db.dfforms6, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms6.accepted: prn_form_vars(fforms6, db.dfforms6) elif fforms6.errors: print("fforms6 has errors: %s " % (fforms6.errors)) fforms7 = Form(db.dfforms7, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms7.accepted: prn_form_vars(fforms7, db.dfforms7) elif fforms7.errors: print("fforms7 has errors: %s " % (fforms7.errors)) fforms8 = Form(db.dfforms8, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms8.accepted: prn_form_vars(fforms8, db.dfforms8) elif fforms8.errors: print("fforms8 has errors: %s " % (fforms8.errors)) fforms9 = Form(db.dfforms9, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms9.accepted: prn_form_vars(fforms9, db.dfforms9) elif fforms9.errors: print("fforms9 has errors: %s " % (fforms9.errors)) fforms10 = Form(db.dfforms10, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms10.accepted: prn_form_vars(fforms10, db.dfforms10) elif fforms10.errors: print("fforms10 has errors: %s " % (fforms10.errors)) fforms11 = Form(db.dfforms11, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms11.accepted: prn_form_vars(fforms11, db.dfforms11) elif fforms11.errors: print("fforms11 has errors: %s " % (fforms11.errors)) fforms12 = Form(db.dfforms12, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms12.accepted: prn_form_vars(fforms12, db.dfforms12) elif fforms12.errors: print("fforms12 has errors: %s " % (fforms12.errors)) fforms13 = Form(db.dfforms13, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms13.accepted: prn_form_vars(fforms13, db.dfforms13) elif fforms13.errors: print("fforms13 has errors: %s " % (fforms13.errors)) fforms14 = Form(db.dfforms14, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms14.accepted: prn_form_vars(fforms14, db.dfforms14) elif fforms14.errors: print("fforms14 has errors: %s " % (fforms14.errors)) fforms15 = Form(db.dfforms15, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms15.accepted: prn_form_vars(fforms15, db.dfforms15) elif fforms15.errors: print("fforms15 has errors: %s " % (fforms15.errors)) fforms16 = Form(db.dfforms16, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms16.accepted: prn_form_vars(fforms16, db.dfforms16) elif fforms16.errors: print("fforms16 has errors: %s " % (fforms16.errors)) fforms17 = Form(db.dfforms17, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms17.accepted: prn_form_vars(fforms17, db.dfforms17) elif fforms17.errors: print("fforms17 has errors: %s " % (fforms17.errors)) fforms18 = Form(db.dfforms18, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms18.accepted: prn_form_vars(fforms18, db.dfforms18) elif fforms18.errors: print("fforms18 has errors: %s " % (fforms18.errors)) fforms19 = Form(db.dfforms19, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms19.accepted: prn_form_vars(fforms19, db.dfforms19) elif fforms19.errors: print("fforms19 has errors: %s " % (fforms19.errors)) fforms20 = Form(db.dfforms20, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms20.accepted: prn_form_vars(fforms20, db.dfforms20) elif fforms20.errors: print("fforms20 has errors: %s " % (fforms20.errors)) fforms21 = Form(db.dfforms21, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms21.accepted: prn_form_vars(fforms21, db.dfforms21) elif fforms21.errors: print("fforms21 has errors: %s " % (fforms21.errors)) fforms22 = Form(db.dfforms22, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms22.accepted: prn_form_vars(fforms22, db.dfforms22) elif fforms22.errors: print("fforms22 has errors: %s " % (fforms22.errors)) fforms23 = Form(db.dfforms23, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms23.accepted: prn_form_vars(fforms23, db.dfforms23) elif fforms23.errors: print("fforms23 has errors: %s " % (fforms23.errors)) fforms24 = Form(db.dfforms24, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms24.accepted: prn_form_vars(fforms24, db.dfforms24) elif fforms24.errors: print("fforms24 has errors: %s " % (fforms24.errors)) fforms25 = Form(db.dfforms25, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms25.accepted: prn_form_vars(fforms25, db.dfforms25) elif fforms25.errors: print("fforms25 has errors: %s " % (fforms25.errors)) fforms26 = Form(db.dfforms26, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms26.accepted: prn_form_vars(fforms26, db.dfforms26) elif fforms26.errors: print("fforms26 has errors: %s " % (fforms26.errors)) fforms27 = Form(db.dfforms27, dbio=False, keep_values=True, formstyle=FormStyleBulma) if fforms27.accepted: prn_form_vars(fforms27, db.dfforms27) elif fforms27.errors: print("fforms27 has errors: %s " % (fforms27.errors)) return locals()
def view_event(eid='0'): eventrow = db(db.event.id == eid).select().first() next_event_name = '' next_event_id = None if eventrow: session['eventid'] = eid session['projid'] = eventrow.projid if eventrow.next_event: next_eventrow = db( db.event.id == eventrow.next_event).select().first() next_event_name = next_eventrow.event_name next_event_id = next_eventrow.id else: redirect(URL('eventgrid')) actions = get_items(qtype='action', status='In Progress', event=eid, eventstatus=eventrow.status) questions = get_items(qtype='quest', status='In Progress', event=eid, eventstatus=eventrow.status) issues = get_items(qtype='issue', event=eid, eventstatus=eventrow.status) res_questions = get_items(qtype='quest', status='Resolved', event=eid, eventstatus=eventrow.status) res_actions = get_items(qtype='action', status='Resolved', event=eid, eventstatus=eventrow.status, execstatus='Incomplete') comp_actions = get_items(qtype='action', status='Resolved', event=eid, eventstatus=eventrow.status, execstatus='Completed') eventlevel = 0 parentquest = 0 quests, nodes, links, resultstring = getd3graph('event', eid, eventrow.status, 1, eventlevel, parentquest) projrow = db(db.project.id == eventrow.projid).select().first() editable = 'true' if projrow.proj_shared or projrow.proj_owner == auth.user else 'false' db.comment.auth_userid.default = auth.user_id db.comment.parenttable.default = 'event' db.comment.parentid.default = eid commentform = Form(db.comment, formstyle=FormStyleBulma) return dict(eventrow=eventrow, eventid=eid, qactions=actions, questions=questions, issues=issues, res_actions=res_actions, res_questions=res_questions, comp_actions=comp_actions, get_class=get_class, get_disabled=get_disabled, quests=quests, nodes=nodes, links=links, resultstring=resultstring, redraw='false', eventowner=editable, projid=eventrow.projid, myconverter=myconverter, auth=auth, like=like, commentform=commentform, next_event_name=next_event_name, next_event_id=next_event_id)