web2py

How to dynamically change variable name in form.vars.var_name

ぃ、小莉子 提交于 2019-12-12 05:28:48
问题 I have defined counter variable in controller. I can define tables and fields dynamically. tables = [db.define_table('example_table_%s' % x, Field('example_field_%s' % x, type='string', ...) ... ) for x in range(0, counter+1)] I can add defined tables to SQLFORM. form = SQLFORM.factory( db.table_1, db.table_2, *tables, submit_button='Submit') I can control process manually if the counter value is '2'. if form.process.accepted(): id = db.table_1.insert(**db.table_1._filter_fields(form.vars))

Insert multiple data using SQLFROM.grid with selectable signature in another table

萝らか妹 提交于 2019-12-12 04:08:38
问题 Good day to all stackoverflow web2py Guru's here.... I found this link and its 2 years old now. I have a problem and I don't know how to code it. I have 2 Entities(Tables) and it's a M:M relationship First table: The Instructors (Advisers) Second table: The Lists of Students now Advisers handled many students and students have many advisers right? so I create a third table and I named it to Student_Adviser School Year db.define_table('school_year', Field('sy',), Field('current_year', 'boolean

web2py autocomplete widget not “CSS-friendly”?

痞子三分冷 提交于 2019-12-12 03:59:12
问题 In model: db.define_table('mytable', Field('auto'), Field('manual') ) db.mytable.auto.widget=SQLFORM.widgets.autocomplete(request,db.mytable.auto) In controller: def index(): form = SQLFORM(db.mytable) return locals() Result: The field with autocomplete looks shitty like it doesn't get any CSS-styling, while the other field looks nice. As descibed here I can do in the controller: form.custom.widget['auto'][0].add_class('form-control') Which makes the autocompleted field look nice, too. But

rendering foreign keys as a pulldown in web2py appadmin

六眼飞鱼酱① 提交于 2019-12-12 03:42:22
问题 part of my web2py database schema looks like so: db.define_table('asset', Field('name', unique=True, requires=IS_NOT_EMPTY()), Field('description', 'text') ) db.define_table('wallet', Field('name', unique=True, requires=IS_NOT_EMPTY()), Field('description', type='text') ) db.define_table('wallet_asset', Field('wallet_id', 'reference wallet'), Field('asset_id', 'reference asset') ) When I visit appadmin to enter a new wallet_asset record, I would like for the wallet_id and asset_id fields to

Web2Py - rendering AJAX response as HTML table

∥☆過路亽.° 提交于 2019-12-12 03:33:39
问题 I am new to Web2Py, Python stack. I have a simple requirement to implement. I need to pass some data from a UI form to a Controller action for processing. After processing the data that action returns a response back to the view which I need to render as an HTML table on the same view. I am using AJAX for this purpose. I am able to get the response back to the view but don't know how to iterate over the elements of that response to render as an HTML table. When I run the below code all it

why is successful task timing out in web2py scheduler?

╄→гoц情女王★ 提交于 2019-12-12 03:19:42
问题 I am running a task in web2py scheduler. The task is completing successfully but web2py says that the task is still running until timeout expires and then logs the task with a status of TIMEOUT . Can anyone shed light on this? 来源: https://stackoverflow.com/questions/38186032/why-is-successful-task-timing-out-in-web2py-scheduler

File upload at web2py

北战南征 提交于 2019-12-12 03:04:30
问题 I am using the web2py framework. I have uploaded txt a file via SQLFORM and the file is stored in the "upload folder", now I need to read this txt file from the controller, what is the file path I should use in the function defined in the default.py ? def readthefile(uploaded_file): file = open(uploaded_file, "rb") file.read() .... 回答1: You can do join of application directory and upload folder to build path to file. Do something like this: import os filepath = os.path.join(request.folder,

How to convert id into referenced field in Web2py?

无人久伴 提交于 2019-12-12 02:25:56
问题 Consider the 3 tables below ( A , B & C ) where table C has 2 fields referenced to table A and B . Model: db.define_table('A', Field('A1', 'string', required =True), Field('A2', 'string', required =True), Field('A3', 'string', required =True), format=lambda r: '%s, %s' % (r.A.A1, r.A.A2)) db.define_table('B', Field('B1', 'string', required=True), Field('B2', 'string', required=True), Field('B3', 'string', required=True), format=lambda r: '%s, %s' % (r.B.B1, r.B.B2)) db.define_table('C', Field

How do I specify utf8mb4 for a mySQL column in web2py?

空扰寡人 提交于 2019-12-12 01:43:46
问题 In web2py, how do I make sure that a column of type='string' uses the full 4-byte unicode format (utf8mb4) when creating tables in a mySQL database? 回答1: From the web2py side, you can specify the encoding via the set_encoding parameter in the connection string: db = DAL('mysql://username:password@localhost/test?set_encoding=utf8mb4') 来源: https://stackoverflow.com/questions/39349972/how-do-i-specify-utf8mb4-for-a-mysql-column-in-web2py

Web2py comparing part of a request.vars element

天涯浪子 提交于 2019-12-12 01:18:21
问题 I have a form with a table with rows containing SELECTs with _names with IDs attached, like this: TD_list.append(TD(SELECT(lesson_reg_list, _name='lesson_reg_' + str(student[4])))) When the form is submitted I want to extract both the student[4] value and the value held by request.vars.lesson_reg_student[4]. I've tried something like: for item in request.vars: if item[0:9] == "lesson_reg": enrolment_id = int(item[10:]) code = request.vars.item I also tried treating request.vars like a