[web2py] Re: DB Insert Variable Names
I've fixed the issue with the variable names by prefixing a letter to the variable. However, the insert still does not function. Here's the error: 127.0.0.1.2013-03-04.11-38-23.96eaf75d-0524-4eb8-8848-6000d1993dcd class 'gluon.contrib.pymysql.err.InternalError' (1048, uColumn 'Q4_3A' cannot be null) Traceback (most recent call last): File gluon/restricted.py, line 212, in restricted File C:/Users/abond2/Desktop/web2py/web2py/web2py/applications/Teacher_Evaluation_System/controllers/evaluation.py http://127.0.0.1:8000/admin/default/edit/Teacher_Evaluation_System/controllers/evaluation.py, line 84, in module File gluon/globals.py, line 193, in lambda File gluon/tools.py, line 2929, in f File C:/Users/abond2/Desktop/web2py/web2py/web2py/applications/Teacher_Evaluation_System/controllers/evaluation.py http://127.0.0.1:8000/admin/default/edit/Teacher_Evaluation_System/controllers/evaluation.py, line 28, in Take_Eval File gluon/dal.py, line 7918, in insert File gluon/dal.py, line 1176, in insert InternalError: (1048, uColumn 'Q4_3A' cannot be null) line 28, in Take_Eval refers to the insert method. Just a thought - do I need to append something extra to form.vars.Q4_3A to get the value of that particular drop down list? On Sunday, March 3, 2013 2:34:29 PM UTC-5, Alan Etkin wrote: My attempts at resolving this issue have made the implementation of the form much simpler, but I'm still unable to get the code to compile after I put the insert in. I would appreciate and assistance you could provide in enlightening me as to why that insert statement would not compile. Could you post the relevant part of the error ticket? -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Creating a form using a for loop
I figured this out later on - I've adjusted all the variables and field names to start with a Q. Thanks. On Saturday, March 2, 2013 5:57:30 PM UTC-5, Arglanir wrote: I think your compilation error comes from the fact that in Python you cannot have a variable name starting with a number. Try changing the field names of Evaluation table to letter_1_1A... Then remember that only one form can be submitted in HTML, so your controler will be called only for one submitted form, not all. Le samedi 2 mars 2013 07:26:18 UTC+1, Anthony Bond a écrit : I've been working with web2py for about two months now. I've figured out how to do a lot of awesome things with it; however, the problem I'm having now has me stumped. I'm working on an application that allows a user to submit a self-evaluation, based on criteria that the user will find on a page. I have a table with 33 rows of of criteria. The table contains a column which hosts the criteria, pre-formatted in HTML. Each HTML section contains a table the gives the users the criteria for each of six levels - these individual tables are almost large enough to take up the entire content section of the webpage, so I've placed them all in a jQuery accordion. Below each table, I've placed a drop down list, where the user can select what criteria they feel as though they've met. I've added a small screenshot to show the look and feel I'm trying to achieve (and currently have). The problem I'm having is getting the values of those drop down lists back from the database. Currently, I iterate through the table containing the HTML using a for loop, tacking a drop down list at the end of each. Right now, I'm unable to get the data back from the page. Here is my code: def Take_Eval(): user = db(db.Person.auth_userUserId == auth.user.id).select().first().PersonId table = db(db.PageContent.ContentId 0).select() submit = INPUT(_name='submit', _type='submit') formlist = [] for row in table: newForm = FORM(H2(row['ContentDescription'], _style=padding-left: 10px;), DIV(XML(row.ContentHTML), BR(), P(SELECT(OPTGROUP(OPTION('Does not Attempt', _value=0), OPTION('Developing', _value=1), OPTION('Progressing', _value=2), OPTION('Established', _value=3), OPTION('Advanced', _value=4), OPTION('Master', _value=5)), _id=row['QuestionNumber']), _style='text-align: center;'))) formlist.append(newForm) for form in formlist: if form.accepts(request, session): response.flash = 'Profile Saved Successfully on ' + str(time.strftime(%Y-%m-%d %H:%M:%S, time.localtime())) #db.Evaluation.insert(PersonBeingEvaluated, PersonEvaluating, EvalDate ,1_1A ,1_1B ,1_2 ,1_3 ,1_4 , 1_5, 1_6, 2_1, 2_2A , 2_2B, 2_3A ,2_3B ,2_4 ,2_5 ,3_1 , 3_2 , 3_3, 3_4, 3_5A, 3_5B, 3_6, 3_7, 3_8, 3_9A, 3_9B, 3_9C, 4_1, 4_2, 4_3A, 4_3B, 4_4, BeliefsScore, CharacterScore) redirect(URL('default', 'index')) elif form.errors: response.flash = 'Profile could not be submitted. Please try again later. ' db.Evaluation.insert(PersonBeingEvaluated=user, PersonEvaluating=0, EvalDate=datetime.now(), 1_1A = formlist[0].vars.1_1A, 1_1B = formlist[1].vars.1_1B, 1_2 = formlist[2].vars.1_2, 1_3 = formlist[3].vars.1_3, 1_4 = formlist[4].vars.1_4, 1_5 = formlist[5].vars.1_5, 1_6 = formlist[6].vars.1_6, 2_1 = formlist[7].vars.2_1, 2_2A = formlist[8].vars.2_2A, 2_2B = formlist[9].vars.2_2B, 2_3A = formlist[10].vars.2_3A, 2_3B = formlist[11].vars.2_3B, 2_4 = formlist[12].vars.2_4, 2_5 = formlist[13].vars.2_5, 3_1 = formlist[14].vars.3_1, 3_2 = formlist[15].vars.3_2, 3_3 = formlist[16].vars.3_3, 3_4 = formlist[17].vars.3_4, 3_5A = formlist[18].vars.3_5A, 3_5B = formlist[19].vars.3_5B, 3_6 = formlist[20].vars.3_6, 3_7 = formlist[21].vars.3_7, 3_8 = formlist[22].vars.3_8, 3_9A = formlist[23].vars.3_9A, 3_9B = formlist[24].vars.3_9B, 3_9C = formlist[25].vars.3_9C, 4_1 = formlist[26].vars.4_1, 4_2 = formlist[27].vars.4_2, 4_3A = formlist[28].vars.4_3A, 4_3B = formlist[29].vars.4_3B, 4_4 = formlist[30].vars.4_4, BeliefsScore = formlist[31].vars.BeliefsScore, CharacterScore = formlist[32].vars.CharacterScore) return locals() The code is not letting me compile due to a syntax error on the area I've highlighted above. I'm okay with not using a form, or a bunch of forms, as long as I can get the values from the drop down list back to the controller when the submit button is clicked. I originally looped through the table in the view to make the display. Each drop down has a unique name that I'd be able to access in the controller, but I haven't been able to figure out how to do that only after post back. I appreciate
[web2py] Re: DB Insert Variable Names
The values shouldn't be null - it should be a int value from between 0 and 5. Even if the user didn't select any items, the default value will still be 0 from the drop down list. On Monday, March 4, 2013 11:51:01 AM UTC-5, Anthony wrote: Did you previously define that column with notnull=True? If so, you may need to alter that column directly in MySQL so it allows null values. Anthony On Monday, March 4, 2013 11:41:05 AM UTC-5, Anthony Bond wrote: I've fixed the issue with the variable names by prefixing a letter to the variable. However, the insert still does not function. Here's the error: 127.0.0.1.2013-03-04.11-38-23.96eaf75d-0524-4eb8-8848-6000d1993dcd class 'gluon.contrib.pymysql.err.InternalError' (1048, uColumn 'Q4_3A' cannot be null) Traceback (most recent call last): File gluon/restricted.py, line 212, in restricted File C:/Users/abond2/Desktop/web2py/web2py/web2py/applications/Teacher_Evaluation_System/controllers/evaluation.py http://127.0.0.1:8000/admin/default/edit/Teacher_Evaluation_System/controllers/evaluation.py, line 84, in module File gluon/globals.py, line 193, in lambda File gluon/tools.py, line 2929, in f File C:/Users/abond2/Desktop/web2py/web2py/web2py/applications/Teacher_Evaluation_System/controllers/evaluation.py http://127.0.0.1:8000/admin/default/edit/Teacher_Evaluation_System/controllers/evaluation.py, line 28, in Take_Eval File gluon/dal.py, line 7918, in insert File gluon/dal.py, line 1176, in insert InternalError: (1048, uColumn 'Q4_3A' cannot be null) line 28, in Take_Eval refers to the insert method. Just a thought - do I need to append something extra to form.vars.Q4_3A to get the value of that particular drop down list? On Sunday, March 3, 2013 2:34:29 PM UTC-5, Alan Etkin wrote: My attempts at resolving this issue have made the implementation of the form much simpler, but I'm still unable to get the code to compile after I put the insert in. I would appreciate and assistance you could provide in enlightening me as to why that insert statement would not compile. Could you post the relevant part of the error ticket? -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: DB Insert Variable Names
Whoops - true sign of a neophyte. Is there a reason why web2py uses names as opposed to IDs? On Monday, March 4, 2013 3:20:15 PM UTC-5, Anthony wrote: Looks like you don't assign names to any of the selects, so their values are not passed via request.post_vars (and therefore don't make it into form.vars). On Monday, March 4, 2013 11:54:23 AM UTC-5, Anthony Bond wrote: The values shouldn't be null - it should be a int value from between 0 and 5. Even if the user didn't select any items, the default value will still be 0 from the drop down list. On Monday, March 4, 2013 11:51:01 AM UTC-5, Anthony wrote: Did you previously define that column with notnull=True? If so, you may need to alter that column directly in MySQL so it allows null values. Anthony On Monday, March 4, 2013 11:41:05 AM UTC-5, Anthony Bond wrote: I've fixed the issue with the variable names by prefixing a letter to the variable. However, the insert still does not function. Here's the error: 127.0.0.1.2013-03-04.11-38-23.96eaf75d-0524-4eb8-8848-6000d1993dcd class 'gluon.contrib.pymysql.err.InternalError' (1048, uColumn 'Q4_3A' cannot be null) Traceback (most recent call last): File gluon/restricted.py, line 212, in restricted File C:/Users/abond2/Desktop/web2py/web2py/web2py/applications/Teacher_Evaluation_System/controllers/evaluation.py http://127.0.0.1:8000/admin/default/edit/Teacher_Evaluation_System/controllers/evaluation.py, line 84, in module File gluon/globals.py, line 193, in lambda File gluon/tools.py, line 2929, in f File C:/Users/abond2/Desktop/web2py/web2py/web2py/applications/Teacher_Evaluation_System/controllers/evaluation.py http://127.0.0.1:8000/admin/default/edit/Teacher_Evaluation_System/controllers/evaluation.py, line 28, in Take_Eval File gluon/dal.py, line 7918, in insert File gluon/dal.py, line 1176, in insert InternalError: (1048, uColumn 'Q4_3A' cannot be null) line 28, in Take_Eval refers to the insert method. Just a thought - do I need to append something extra to form.vars.Q4_3A to get the value of that particular drop down list? On Sunday, March 3, 2013 2:34:29 PM UTC-5, Alan Etkin wrote: My attempts at resolving this issue have made the implementation of the form much simpler, but I'm still unable to get the code to compile after I put the insert in. I would appreciate and assistance you could provide in enlightening me as to why that insert statement would not compile. Could you post the relevant part of the error ticket? -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Creating a form using a for loop
I've been working with web2py for about two months now. I've figured out how to do a lot of awesome things with it; however, the problem I'm having now has me stumped. I'm working on an application that allows a user to submit a self-evaluation, based on criteria that the user will find on a page. I have a table with 33 rows of of criteria. The table contains a column which hosts the criteria, pre-formatted in HTML. Each HTML section contains a table the gives the users the criteria for each of six levels - these individual tables are almost large enough to take up the entire content section of the webpage, so I've placed them all in a jQuery accordion. Below each table, I've placed a drop down list, where the user can select what criteria they feel as though they've met. I've added a small screenshot to show the look and feel I'm trying to achieve (and currently have). The problem I'm having is getting the values of those drop down lists back from the database. Currently, I iterate through the table containing the HTML using a for loop, tacking a drop down list at the end of each. Right now, I'm unable to get the data back from the page. Here is my code: def Take_Eval(): user = db(db.Person.auth_userUserId == auth.user.id).select().first().PersonId table = db(db.PageContent.ContentId 0).select() submit = INPUT(_name='submit', _type='submit') formlist = [] for row in table: newForm = FORM(H2(row['ContentDescription'], _style=padding-left: 10px;), DIV(XML(row.ContentHTML), BR(), P(SELECT(OPTGROUP(OPTION('Does not Attempt', _value=0), OPTION('Developing', _value=1), OPTION('Progressing', _value=2), OPTION('Established', _value=3), OPTION('Advanced', _value=4), OPTION('Master', _value=5)), _id=row['QuestionNumber']), _style='text-align: center;'))) formlist.append(newForm) for form in formlist: if form.accepts(request, session): response.flash = 'Profile Saved Successfully on ' + str(time.strftime(%Y-%m-%d %H:%M:%S, time.localtime())) #db.Evaluation.insert(PersonBeingEvaluated, PersonEvaluating, EvalDate ,1_1A ,1_1B ,1_2 ,1_3 ,1_4 , 1_5, 1_6, 2_1, 2_2A , 2_2B, 2_3A ,2_3B ,2_4 ,2_5 ,3_1 , 3_2 , 3_3, 3_4, 3_5A, 3_5B, 3_6, 3_7, 3_8, 3_9A, 3_9B, 3_9C, 4_1, 4_2, 4_3A, 4_3B, 4_4, BeliefsScore, CharacterScore) redirect(URL('default', 'index')) elif form.errors: response.flash = 'Profile could not be submitted. Please try again later. ' db.Evaluation.insert(PersonBeingEvaluated=user, PersonEvaluating=0, EvalDate=datetime.now(), 1_1A = formlist[0].vars.1_1A, 1_1B = formlist[1].vars.1_1B, 1_2 = formlist[2].vars.1_2, 1_3 = formlist[3].vars.1_3, 1_4 = formlist[4].vars.1_4, 1_5 = formlist[5].vars.1_5, 1_6 = formlist[6].vars.1_6, 2_1 = formlist[7].vars.2_1, 2_2A = formlist[8].vars.2_2A, 2_2B = formlist[9].vars.2_2B, 2_3A = formlist[10].vars.2_3A, 2_3B = formlist[11].vars.2_3B, 2_4 = formlist[12].vars.2_4, 2_5 = formlist[13].vars.2_5, 3_1 = formlist[14].vars.3_1, 3_2 = formlist[15].vars.3_2, 3_3 = formlist[16].vars.3_3, 3_4 = formlist[17].vars.3_4, 3_5A = formlist[18].vars.3_5A, 3_5B = formlist[19].vars.3_5B, 3_6 = formlist[20].vars.3_6, 3_7 = formlist[21].vars.3_7, 3_8 = formlist[22].vars.3_8, 3_9A = formlist[23].vars.3_9A, 3_9B = formlist[24].vars.3_9B, 3_9C = formlist[25].vars.3_9C, 4_1 = formlist[26].vars.4_1, 4_2 = formlist[27].vars.4_2, 4_3A = formlist[28].vars.4_3A, 4_3B = formlist[29].vars.4_3B, 4_4 = formlist[30].vars.4_4, BeliefsScore = formlist[31].vars.BeliefsScore, CharacterScore = formlist[32].vars.CharacterScore) return locals() The code is not letting me compile due to a syntax error on the area I've highlighted above. I'm okay with not using a form, or a bunch of forms, as long as I can get the values from the drop down list back to the controller when the submit button is clicked. I originally looped through the table in the view to make the display. Each drop down has a unique name that I'd be able to access in the controller, but I haven't been able to figure out how to do that only after post back. I appreciate any guidance that could be given. Thanks! -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. attachment: tesscreenshot.png