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 car_model_form(): """ Creates a form using web2py helpers. This is the most manual method of creating a form. It allows the specification of every aspect of the resulting html elements. Some notes: Validators must be specified during the INPUT fields creation. form.accepts() must be called to process the form. Database insertion must be handled manually. """ # Must repeat the field validators declared in the db.py car_model_input=INPUT(_name='car_model', requires=IS_NOT_EMPTY()) base_price_input=INPUT(_name='base_price', requires=IS_NOT_EMPTY()) # Manual creation of the html table table_rows = [] table_rows.append(TR('Car Model:', car_model_input)) table_rows.append(TR('Base Price:', base_price_input)) # Fields starting with _ are passed to the html as attribute elements table_rows.append(TR(TD(INPUT(_type='submit'), _colspan='2', _align='center'))) table = TABLE(table_rows) form = FORM(table) # Processing the form submition if form.accepts(request,session): # Retriving the form fields form_car_model = form.vars.car_model form_base_price = form.vars.base_price # Inserting in the database db.car_model.insert(car_model=form_car_model, car_base_price=form_base_price) # Tell the user about the insertion response.flash = 'New car: ' + form_car_model elif form.errors: response.flash = 'Form has errors' else: response.flash = 'Please fill the form' return dict(car_model_form=form)
def apply_method(r, **attr): """ Apply method. @param r: the S3Request @param attr: controller options for this request """ if r.representation == "html": T = current.T response = current.response tracker = S3Trackable(r.table, record_id=r.id) title = T("Check-Out") # Give the user a form to check-out # Test the formstyle formstyle = current.deployment_settings.get_ui_formstyle() row = formstyle("test", "test", "test", "test") if isinstance(row, tuple): # Formstyle with separate row for label (e.g. default Eden formstyle) tuple_rows = True else: # Formstyle with just a single row (e.g. Bootstrap, Foundation or DRRPP) tuple_rows = False form_rows = [] comment = "" _id = "submit" label = "" widget = INPUT(_type="submit", _value=T("Check-Out")) row = formstyle("%s__row" % _id, label, widget, comment) if tuple_rows: form_rows.append(row[0]) form_rows.append(row[1]) else: form_rows.append(row) if tuple_rows: # Assume TRs form = FORM(TABLE(*form_rows)) else: form = FORM(*form_rows) if form.accepts(current.request.vars, current.session): # Check-Out # We're not Checking-out in S3Track terms (that's about removing an interlock with another object) # What we're doing is saying that we're now back at our base location #tracker.check_out() #timestmp = form_vars.get("timestmp", None) #if timestmp: # # @ToDo: Convert from string # pass #tracker.set_location(r.record.location_id, timestmp=timestmp) tracker.set_location(r.record.location_id) response.confirmation = T("Checked-Out successfully!") response.view = "check-in.html" output = dict( form=form, title=title, ) return output # @ToDo: JSON representation for check-out from mobile devices else: raise HTTP(415, current.ERROR.BAD_FORMAT)
def apply_method(r, **attr): """ Apply method. @param r: the S3Request @param attr: controller options for this request """ if r.representation == "html": T = current.T response = current.response tracker = S3Trackable(r.table, record_id=r.id) title = T("Check-Out") # Give the user a form to check-out # Test the formstyle formstyle = current.deployment_settings.get_ui_formstyle() row = formstyle("test", "test", "test", "test") if isinstance(row, tuple): # Formstyle with separate row for label (e.g. default Eden formstyle) tuple_rows = True else: # Formstyle with just a single row (e.g. Bootstrap, Foundation or DRRPP) tuple_rows = False form_rows = [] comment = "" _id = "submit" label = "" widget = INPUT(_type="submit", _value=T("Check-Out")) row = formstyle("%s__row" % _id, label, widget, comment) if tuple_rows: form_rows.append(row[0]) form_rows.append(row[1]) else: form_rows.append(row) if tuple_rows: # Assume TRs form = FORM(TABLE(*form_rows)) else: form = FORM(*form_rows) if form.accepts(current.request.vars, current.session): # Check-Out # We're not Checking-out in S3Track terms (that's about removing an interlock with another object) # What we're doing is saying that we're now back at our base location #tracker.check_out() #timestmp = form_vars.get("timestmp", None) #if timestmp: # # @ToDo: Convert from string # pass #tracker.set_location(r.record.location_id, timestmp=timestmp) tracker.set_location(r.record.location_id) response.confirmation = T("Checked-Out successfully!") response.view = "check-in.html" output = dict(form = form, title = title, ) return output # @ToDo: JSON representation for check-out from mobile devices else: raise HTTP(415, current.ERROR.BAD_FORMAT)
def merge(self, r, **attr): """ Merge form for two records @param r: the S3Request @param **attr: the controller attributes for the request @note: this method can always only be POSTed, and requires both "selected" and "mode" in post_vars, as well as the duplicate bookmarks list in session.s3 """ T = current.T session = current.session response = current.response output = {} tablename = self.tablename # Get the duplicate bookmarks s3 = session.s3 DEDUPLICATE = self.DEDUPLICATE if DEDUPLICATE in s3: bookmarks = s3[DEDUPLICATE] if tablename in bookmarks: record_ids = bookmarks[tablename] # Process the post variables post_vars = r.post_vars mode = post_vars.get("mode") selected = post_vars.get("selected", "") selected = selected.split(",") if mode == "Inclusive": ids = selected elif mode == "Exclusive": ids = [i for i in record_ids if i not in selected] else: # Error ids = [] if len(ids) != 2: r.error(501, T("Please select exactly two records"), next=r.url(id=0, vars={})) # Get the selected records table = self.table query = (table._id == ids[0]) | (table._id == ids[1]) orderby = table.created_on if "created_on" in table else None rows = current.db(query).select(orderby=orderby, limitby=(0, 2)) if len(rows) != 2: r.error(404, current.ERROR.BAD_RECORD, next=r.url(id=0, vars={})) original = rows[0] duplicate = rows[1] # Prepare form construction formfields = [f for f in table if f.readable or f.writable] ORIGINAL, DUPLICATE, KEEP = self.ORIGINAL, self.DUPLICATE, self.KEEP keep_o = KEEP.o in post_vars and post_vars[KEEP.o] keep_d = KEEP.d in post_vars and post_vars[KEEP.d] trs = [] init_requires = self.init_requires index = 1 num_fields = len(formfields) for f in formfields: # Render the widgets oid = "%s_%s" % (ORIGINAL, f.name) did = "%s_%s" % (DUPLICATE, f.name) sid = "swap_%s" % f.name init_requires(f, original[f], duplicate[f]) if keep_o or not any((keep_o, keep_d)): owidget = self.widget(f, original[f], _name=oid, _id=oid, _tabindex=index) else: try: owidget = s3_represent_value(f, value=original[f]) except: owidget = s3_str(original[f]) if keep_d or not any((keep_o, keep_d)): dwidget = self.widget(f, duplicate[f], _name=did, _id=did) else: try: dwidget = s3_represent_value(f, value=duplicate[f]) except: dwidget = s3_str(duplicate[f]) # Swap button if not any((keep_o, keep_d)): swap = INPUT( _value="<-->", _class="swap-button", _id=sid, _type="button", _tabindex=index + num_fields, ) else: swap = DIV(_class="swap-button") if owidget is None or dwidget is None: continue # Render label row label = f.label trs.append( TR(TD(label, _class="w2p_fl"), TD(), TD(label, _class="w2p_fl"))) # Append widget row trs.append( TR(TD(owidget, _class="mwidget"), TD(swap), TD(dwidget, _class="mwidget"))) index = index + 1 # Show created_on/created_by for each record if "created_on" in table: original_date = original.created_on duplicate_date = duplicate.created_on if "created_by" in table: represent = table.created_by.represent original_author = represent(original.created_by) duplicate_author = represent(duplicate.created_by) created = T("Created on %s by %s") original_created = created % (original_date, original_author) duplicate_created = created % (duplicate_date, duplicate_author) else: created = T("Created on %s") original_created = created % original_date duplicate_created = created % duplicate_date else: original_created = "" duplicate_created = "" # Page title and subtitle output["title"] = T("Merge records") #output["subtitle"] = self.crud_string(tablename, "title_list") # Submit buttons if keep_o or not any((keep_o, keep_d)): submit_original = INPUT( _value=T("Keep Original"), _type="submit", _name=KEEP.o, _id=KEEP.o, ) else: submit_original = "" if keep_d or not any((keep_o, keep_d)): submit_duplicate = INPUT( _value=T("Keep Duplicate"), _type="submit", _name=KEEP.d, _id=KEEP.d, ) else: submit_duplicate = "" # Build the form form = FORM( TABLE( THEAD( TR( TH(H3(T("Original"))), TH(), TH(H3(T("Duplicate"))), ), TR( TD(original_created), TD(), TD(duplicate_created), _class="authorinfo", ), ), TBODY(trs), TFOOT(TR( TD(submit_original), TD(), TD(submit_duplicate), ), ), ), # Append mode and selected - required to get back here! hidden={ "mode": "Inclusive", "selected": ",".join(ids), }) output["form"] = form # Add RESET and CANCEL options output["reset"] = FORM( INPUT( _value=T("Reset"), _type="submit", _name="reset", _id="form-reset", ), A(T("Cancel"), _href=r.url(id=0, vars={}), _class="action-lnk"), hidden={ "mode": mode, "selected": ",".join(ids), }, ) # Process the merge form formname = "merge_%s_%s_%s" % (tablename, original[table._id], duplicate[table._id]) if form.accepts( post_vars, session, formname=formname, onvalidation=lambda form: self.onvalidation(tablename, form), keepvalues=False, hideerror=False): s3db = current.s3db if form.vars[KEEP.d]: prefix = "%s_" % DUPLICATE original, duplicate = duplicate, original else: prefix = "%s_" % ORIGINAL data = Storage() for key in form.vars: if key.startswith(prefix): fname = key.split("_", 1)[1] data[fname] = form.vars[key] search = False resource = s3db.resource(tablename) try: resource.merge(original[table._id], duplicate[table._id], update=data) except current.auth.permission.error: r.unauthorised() except KeyError: r.error(404, current.ERROR.BAD_RECORD) except Exception: import sys r.error(424, T("Could not merge records. (Internal Error: %s)") % sys.exc_info()[1], next=r.url()) else: # Cleanup bookmark list if mode == "Inclusive": bookmarks[tablename] = [ i for i in record_ids if i not in ids ] if not bookmarks[tablename]: del bookmarks[tablename] search = True elif mode == "Exclusive": bookmarks[tablename].extend(ids) if not selected: search = True # Confirmation message # @todo: Having the link to the merged record in the confirmation # message would be nice, but it's currently not clickable there :/ #result = A(T("Open the merged record"), #_href=r.url(method="read", #id=original[table._id], #vars={})) response.confirmation = T("Records merged successfully.") # Go back to bookmark list if search: self.next = r.url(method="", id=0, vars={}) else: self.next = r.url(id=0, vars={}) # View response.view = self._view(r, "merge.html") return output
def merge(self, r, **attr): """ Merge form for two records @param r: the S3Request @param **attr: the controller attributes for the request @note: this method can always only be POSTed, and requires both "selected" and "mode" in post_vars, as well as the duplicate bookmarks list in session.s3 """ T = current.T session = current.session response = current.response output = dict() tablename = self.tablename # Get the duplicate bookmarks s3 = session.s3 DEDUPLICATE = self.DEDUPLICATE if DEDUPLICATE in s3: bookmarks = s3[DEDUPLICATE] if tablename in bookmarks: record_ids = bookmarks[tablename] # Process the post variables post_vars = r.post_vars mode = post_vars.get("mode") selected = post_vars.get("selected", "") selected = selected.split(",") if mode == "Inclusive": ids = selected elif mode == "Exclusive": ids = [i for i in record_ids if i not in selected] else: # Error ids = [] if len(ids) != 2: r.error(501, T("Please select exactly two records"), next = r.url(id=0, vars={})) # Get the selected records table = self.table query = (table._id == ids[0]) | (table._id == ids[1]) orderby = table.created_on if "created_on" in table else None rows = current.db(query).select(orderby=orderby, limitby=(0, 2)) if len(rows) != 2: r.error(404, current.ERROR.BAD_RECORD, next = r.url(id=0, vars={})) original = rows[0] duplicate = rows[1] # Prepare form construction formfields = [f for f in table if f.readable or f.writable] ORIGINAL, DUPLICATE, KEEP = self.ORIGINAL, self.DUPLICATE, self.KEEP keep_o = KEEP.o in post_vars and post_vars[KEEP.o] keep_d = KEEP.d in post_vars and post_vars[KEEP.d] trs = [] init_requires = self.init_requires index = 1 num_fields = len(formfields) for f in formfields: # Render the widgets oid = "%s_%s" % (ORIGINAL, f.name) did = "%s_%s" % (DUPLICATE, f.name) sid = "swap_%s" % f.name init_requires(f, original[f], duplicate[f]) if keep_o or not any((keep_o, keep_d)): owidget = self.widget(f, original[f], _name=oid, _id=oid, _tabindex=index) else: try: owidget = s3_represent_value(f, value=original[f]) except: owidget = s3_str(original[f]) if keep_d or not any((keep_o, keep_d)): dwidget = self.widget(f, duplicate[f], _name=did, _id=did) else: try: dwidget = s3_represent_value(f, value=duplicate[f]) except: dwidget = s3_str(duplicate[f]) # Swap button if not any((keep_o, keep_d)): swap = INPUT(_value="<-->", _class="swap-button", _id=sid, _type="button", _tabindex = index+num_fields) else: swap = DIV(_class="swap-button") if owidget is None or dwidget is None: continue # Render label row label = f.label trs.append(TR(TD(label, _class="w2p_fl"), TD(), TD(label, _class="w2p_fl"))) # Append widget row trs.append(TR(TD(owidget, _class="mwidget"), TD(swap), TD(dwidget, _class="mwidget"))) index = index + 1 # Show created_on/created_by for each record if "created_on" in table: original_date = original.created_on duplicate_date = duplicate.created_on if "created_by" in table: represent = table.created_by.represent original_author = represent(original.created_by) duplicate_author = represent(duplicate.created_by) created = T("Created on %s by %s") original_created = created % (original_date, original_author) duplicate_created = created % (duplicate_date, duplicate_author) else: created = T("Created on %s") original_created = created % original_date duplicate_created = created % duplicate_date else: original_created = "" duplicate_created = "" # Page title and subtitle output["title"] = T("Merge records") #output["subtitle"] = self.crud_string(tablename, "title_list") # Submit buttons if keep_o or not any((keep_o, keep_d)): submit_original = INPUT(_value=T("Keep Original"), _type="submit", _name=KEEP.o, _id=KEEP.o) else: submit_original = "" if keep_d or not any((keep_o, keep_d)): submit_duplicate = INPUT(_value=T("Keep Duplicate"), _type="submit", _name=KEEP.d, _id=KEEP.d) else: submit_duplicate = "" # Build the form form = FORM(TABLE( THEAD( TR(TH(H3(T("Original"))), TH(), TH(H3(T("Duplicate"))), ), TR(TD(original_created), TD(), TD(duplicate_created), _class="authorinfo", ), ), TBODY(trs), TFOOT( TR(TD(submit_original), TD(), TD(submit_duplicate), ), ), ), # Append mode and selected - required to get back here! hidden = { "mode": "Inclusive", "selected": ",".join(ids), } ) output["form"] = form # Add RESET and CANCEL options output["reset"] = FORM(INPUT(_value=T("Reset"), _type="submit", _name="reset", _id="form-reset"), A(T("Cancel"), _href=r.url(id=0, vars={}), _class="action-lnk"), hidden = {"mode": mode, "selected": ",".join(ids), }, ) # Process the merge form formname = "merge_%s_%s_%s" % (tablename, original[table._id], duplicate[table._id]) if form.accepts(post_vars, session, formname=formname, onvalidation=lambda form: self.onvalidation(tablename, form), keepvalues=False, hideerror=False): s3db = current.s3db if form.vars[KEEP.d]: prefix = "%s_" % DUPLICATE original, duplicate = duplicate, original else: prefix = "%s_" % ORIGINAL data = Storage() for key in form.vars: if key.startswith(prefix): fname = key.split("_", 1)[1] data[fname] = form.vars[key] search = False resource = s3db.resource(tablename) try: resource.merge(original[table._id], duplicate[table._id], update=data) except current.auth.permission.error: r.unauthorized() except KeyError: r.error(404, current.ERROR.BAD_RECORD) except Exception: import sys r.error(424, T("Could not merge records. (Internal Error: %s)") % sys.exc_info()[1], next=r.url()) else: # Cleanup bookmark list if mode == "Inclusive": bookmarks[tablename] = [i for i in record_ids if i not in ids] if not bookmarks[tablename]: del bookmarks[tablename] search = True elif mode == "Exclusive": bookmarks[tablename].extend(ids) if not selected: search = True # Confirmation message # @todo: Having the link to the merged record in the confirmation # message would be nice, but it's currently not clickable there :/ #result = A(T("Open the merged record"), #_href=r.url(method="read", #id=original[table._id], #vars={})) response.confirmation = T("Records merged successfully.") # Go back to bookmark list if search: self.next = r.url(method="", id=0, vars={}) else: self.next = r.url(id=0, vars={}) # View response.view = self._view(r, "merge.html") return output
def BD_Apostila(): #############seleciona os registros com informações print 'lendo antes de inserir' registros = db(db.minhatabela.meucampo!=None).select() for registro in registros: print registro.meucampo ############seleciona os registros com a palavra teste, porém só mostra no terminal minhaquery = (db.minhatabela.meucampo == 'pepino') # definir o conjunto de registros ' SELECT * FROM minhatabela where meucampo = 'Teste' conjunto = db(minhaquery) # executar o select acima e popula o objeto registros registros = conjunto.select() # alterar os registros 'UPDATE minhatabela set meucampo = 'Teste2' where meucampo = 'Teste' conjunto.update(meucampo='arroz') ########################################################################## print 'lendo depois de trocar' registros = db(db.minhatabela.meucampo!=None).select() for registro in registros: print registro.meucampo ############seleciona os registros com a palavra arroz, porém só mostra no terminal minhaquery2 = (db.minhatabela.meucampo == 'verde') # definir o conjunto de registros ' SELECT * FROM minhatabela where meucampo = 'Teste' conjunto2 = db(minhaquery2) # executar o select acima e popula o objeto registros registros2 = conjunto2.select() # deletar os registros 'DELETE FROM minhatabela where meucampo = 'Teste' conjunto2.delete() ########################################################################## print 'lendo depois de deletar' registros = db(db.minhatabela.meucampo!=None).select() for registro in registros: print registro.meucampo ########################################################################## ################## print 'lendo na minhaordem' minhaordem = db.minhatabela.meucampo.upper() | db.minhatabela.id registro = db().select(db.minhatabela.ALL, orderby=minhaordem) for registro in registros: print registro.meucampo ###########Adicionando um elemento no form/db############################ meucampo_input=INPUT(_name='meucampo', requires=IS_NOT_EMPTY(error_message='você deve informar algo')) table_rows = [] table_rows.append(TR('Meu campo:',meucampo_input)) table_rows.append(TR(TD(INPUT(_type='submit'),colspan='2',align='center'))) table=TABLE(table_rows) form_db = FORM(table) if form_db.accepts(request,session): form_meucampo = form_db.vars.meucampo db.minhatabela.insert(meucampo=form_meucampo) response.flash = 'tabela:'+ form_meucampo elif form_db.errors: response.flash = 'form errors' else: response.flash = 'please fill the form' ##########################adicionando um elemento SQLFORM/db form99=SQLFORM(db.minhatabela) ########################################################################## print 'lendo depois de inserir' registros = db(db.minhatabela.meucampo!=None).select() for registro in registros: print registro.meucampo ########################################################################## print 'Inserindo mais dados' db.minhatabela.insert(meucampo = 'verde') print 'lendo depois de inserir' registros = db(db.minhatabela.meucampo!=None).select() for registro in registros: print registro.meucampo print 'Inserindo muitos dados' maisdados = [{'meucampo':'azul'}, {'meucampo':'amarelo'}, {'meucampo':'pepino'} ] #############falta o código query = db.minhatabela.meucampo != 'verde' conjunto = db(query) registros = conjunto.select() print 'lendo query' for registro in registros: print registro.meucampo meuregistro = db.minhatabela(10) print meuregistro meuregistro = db.minhatabela(db.minhatabela.id == 10 ) print meuregistro meuregistro = db.minhatabela(10,meucampo='laranja') print meuregistro print 'Orderby' for registro in db().select(db.minhatabela.ALL, orderby=db.minhatabela.meucampo): print registro.meucampo print 'query multipla' for registro in db((db.minhatabela.meucampo=='laranja')|(db.minhatabela.meucampo=='verde')).select(): print registro.meucampo print db(db.minhatabela.id>0).count() print 'alterar campo' teste = db.minhatabela(10) print teste.meucampo teste.meucampo = 'rosa' print teste.meucampo print 'alterando todos' teste = db().select(db.minhatabela.ALL) for test in teste: test.update(meucampo='estragou') for registro in teste: print registro.meucampo return dict(form_db_table=form_db, registros=registros, form99=form99)
def carro(): title = "Cadastro de Carros" if not session.flashed: response.flash = T('Bem vindo a loja de carros!') #lista todos os carros na tela car_grid = SQLFORM.smartgrid(db2.carro) #CRUD #aqui ele formata tudo sozinho e ainda envia para o banco sozinho também #mostra a mensagem de falha sozinho carro_crud = crud.create(db2.carro) ####################################################### #aqui ele formata tudo sozinho e ainda envia para o banco sozinho também #mas não mostra a mensagem de falha ou aceitação sozinho carro_sqlform = SQLFORM(db2.carro) if carro_sqlform.accepts(request,session): response.flash = 'Form accepted' elif carro_sqlform.errors: response.flash = 'Form has errors' else: response.flash = 'Please fill the form' excluir_carro(1) alterar_carro(2) ####################################################### # Must repeat the field validators declared in the db.py marca_input=INPUT(_name='marca_input', requires=IS_IN_DB(db2, 'marca.id','marca.nome',error_message=e_m['not_in_db'])) modelo_input=INPUT(_name='modelo_input') y1 = request.now.year-20 y2 = request.now.year+2 ano_input=INPUT(_name='ano_input', requires=IS_INT_IN_RANGE(y1,y2,error_message=e_m['not_in_range'])) cor_input=INPUT(_name='cor_input', requires=IS_IN_SET(cores)) valor_input=INPUT(_name='valor_input') itens_input=INPUT(_name='itens_input',requires=IS_IN_SET(('Alarme','Trava','Som', 'Ar'),multiple=True,error_message=e_m['not_in_set'])) estado_input=INPUT(_name='estado_input',requires=IS_IN_SET(estados,error_message=e_m['not_in_set'])) desc_input=INPUT(_name='desc_input') foto_input=INPUT(_name='foto_input',requires=IS_IMAGE(IS_IMAGE(extensions=('jpeg', 'png', '.gif'),error_message=e_m['image']))) #neste ponto define a posição dos dados dentro de uma tabela # Manual creation of the html table table_rows = [] table_rows.append(TR('Marca:', marca_input)) table_rows.append(TR('Modelo:', modelo_input)) table_rows.append(TR('Ano:', ano_input)) table_rows.append(TR('Cor:', cor_input)) table_rows.append(TR('Valor:', valor_input)) table_rows.append(TR('Itens:', itens_input)) table_rows.append(TR('Estado:', estado_input)) table_rows.append(TR('Descrição:', desc_input)) table_rows.append(TR('Foto:', foto_input)) # Fields starting with _ are passed to the html as attribute elements table_rows.append(TR(TD(INPUT(_type='submit'), _colspan='2', _align='center'))) table = TABLE(table_rows) form = FORM(table) #momento em que realmente o dado é colocado dentro do banco de dados # Processing the form submition if form.accepts(request,session): # Retriving the form fields form_marca_input = form.vars.marca form_modelo_input = form.vars.modelo form_ano_input = form.vars.ano form_cor_input = form.vars.cor form_valor_input = form.vars.valor form_itens_input = form.vars.itens form_estado_input = form.vars.estado form_desc_input = form.vars.desc form_foto_input = form.vars.foto # Inserting in the database db.car_model.insert(marca=form_marca_input, modelo = form_modelo_input,ano = form_ano_input, cor = form_cor_input, valor = form_valor_input, itens = form_itens_input, estado = form_estado_input, desc = form_desc_input, foto = form_foto_input) # Tell the user about the insertion response.flash = 'New car: ' + form_modelo_input elif form.errors: response.flash = 'Form has errors' else: response.flash = 'Please fill the form' ####################################################### form_carro = detalhes_geral(db2.carro,2) (form_crud,table_crud) = pesquisa_geral(db2.carro) return locals()