alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

SQLFORM.widgets.text.widget doesn't set multi-line property in datastore #167

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From nathan...@gmail.com on January 29, 2011 12:01:48

What steps will reproduce the problem? 1. Build an SQLFORM.Factory with a widget=SQLFORM.widgets.text.widget)

form = SQLFORM.factory(
    Field('rightAnswerA',
          widget=horizontal_radios, 
          requires=IS_IN_SET(likertRightAnswer,
                             error_message=T('Please choose a response.'))),
    Field('rightAnswerB',
          widget=horizontal_radios, 
          requires=IS_IN_SET(likertRightAnswer,
                             error_message=T('Please choose a response.'))),
    Field('comment', widget=SQLFORM.widgets.text.widget),
    hidden={'timestart':request.get_vars.timestart,
            'assignmentId':request.get_vars.assignmentId,
            'experimentId':request.get_vars.experimentId,
            'workerId':request.get_vars.workerId,
            'studentIds':request.get_vars.studentIds,
            'rubricCode':request.get_vars.rubricCode,
            'studentIds':request.get_vars.studentIds,
            'width':'tmp',
            'height':'tmp', 
            'element':'tmp',
            'value':'tmp'}
    )
  1. Display the form and on form.accepts(request.vars) send to a different part of the app:

    if form.accepts(request.vars):

    ## SOME PROCESSING HERE
    
    extraURLvariables = {'studentIds':request.post_vars.studentIds,
                        'rawAnswers':"%s:%s" % (rightAnswerA, rightAnswerB),
                        'subscores':subscore,
                        }
    extraURLvariables.update(request.post_vars)
    form_data = urllib.urlencode(extraURLvariables)
    redirect( '../default/commitRubric?%s' % form_data )   
  2. Manually update the db using the data processed in step2

def commitRubric(): db.allRatings.insert( timeend = request.now.strftime('%Y-%m-%d %H:%M:%S'), timestart = request.vars.timestart, assignmentId = request.vars.assignmentId, experimentId = request.vars.experimentId, workerId = request.vars.workerId, studentIds = request.vars.studentIds, rubricCode = request.vars.rubricCode, ipaddress = request.client, comment = request.vars.comment, rawAnswers = request.vars.rawAnswers, subscores = request.vars.subscores, )

The model definition is:

db.define_table('allRatings', Field('timeend','datetime',requires= IS_NOT_EMPTY() ), Field('timestart','datetime',requires= IS_NOT_EMPTY() ), Field('assignmentId',requires= IS_NOT_EMPTY() ), Field('experimentId',requires= IS_NOT_EMPTY() ), Field('workerId',requires= IS_NOT_EMPTY() ), Field('studentIds',requires= IS_NOT_EMPTY() ), Field('rubricCode',requires= IS_NOT_EMPTY() ), Field('ipaddress' ,default=request.client), Field('comment',widget=SQLFORM.widgets.text.widget), Field('rawAnswers',requires= IS_NOT_EMPTY() ), Field('subscores',requires= IS_NOT_EMPTY() ) )

Need this for some of the rubric options.

def horizontal_radios(f,v): table = SQLFORM.widgets.radio.widget(f,v) rows = table.elements('tr') table.components = [] table.append([row.elements('td') for row in rows]) return table What is the expected output? What do you see instead? I expect that the inclusion of widget=SQLFORM.widgets.text.widget in the FIELD definition of comment would set the GAE multi-line property to true.

Instead, this doesn't get set, and it barfs with: Traceback (most recent call last): File "/home/vanhoudn/Dropbox/workspace-linux/creatia-rubrics/src/gluon/restricted.py", line 188, in restricted exec ccode in environment File "/home/vanhoudn/Dropbox/workspace-linux/creatia-rubrics/src/applications/rubrics/controllers/default.py:commitRubric", line 183, in File "/home/vanhoudn/Dropbox/workspace-linux/creatia-rubrics/src/gluon/globals.py", line 95, in self._caller = lambda f: f() File "/home/vanhoudn/Dropbox/workspace-linux/creatia-rubrics/src/applications/rubrics/controllers/default.py:commitRubric", line 75, in commitRubric File "/home/vanhoudn/Dropbox/workspace-linux/creatia-rubrics/src/gluon/dal.py", line 3875, in insert return self._db._adapter.insert(self,self._listify(fields)) File "/home/vanhoudn/Dropbox/workspace-linux/creatia-rubrics/src/gluon/dal.py", line 2729, in insert tmp = table._tableobj(dfields) File "/home/vanhoudn/google_appengine.1.4.1/google/appengine/ext/db/init.py", line 812, in init prop.set(self, value) File "/home/vanhoudn/google_appengine.1.4.1/google/appengine/ext/db/init.py", line 541, in set value = self.validate(value) File "/home/vanhoudn/google_appengine.1.4.1/google/appengine/ext/db/init**.py", line 2435, in validate raise BadValueError('Property %s is not multi-line' % self.name) BadValueError: Property comment is not multi-line

If I replace comment = request.vars.comment, with comment = request.vars.comment.replace("\n","\n", during the commit step, it will work. This isn't really ideal though. What version of the product are you using? On what operating system? web2py 1.91.6 google_appengine 1.4.1 Ubuntu 10.04 LTS Please provide any additional information below.

Original issue: http://code.google.com/p/web2py/issues/detail?id=169

alfonsodg commented 10 years ago

From massimo....@gmail.com on February 05, 2011 20:56:00

StringPropery should always be multiline. Now it is.

Status: Fixed