2014-05-25 10 views
1

Так у меня есть следующий рабочий код, который я использую в течение последних нескольких месяцевСтранные деформировать/поведение дуршлаг «строковые индексы должны быть целыми числами»

class UserSchema(colander.MappingSchema): 
    dob = colander.SchemaNode(
      colander.Date(), 
      title='Date of birth:') 

if 'submit' in request.POST: 

    controls = request.POST.items() 
    try: 
     appstruct = myform.validate(controls) 
    except ValidationFailure, e: 
     return {'form':e.render(), 'values': False} 

Теперь это базовая дата выбора, как показано на рисунке здесь:

http://deform2demo.repoze.org/dateinput/

Но вдруг, когда с помощью этого виджета я получаю ошибку:

Traceback (most recent call last): 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.9-py2.7.egg/pyramid_debugtoolbar/panels/performance.py", line 55, in resource_timer_handler 
    result = handler(request) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween 
    response = handler(request) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 82, in tm_tween 
    reraise(*exc_info) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 63, in tm_tween 
    response = handler(request) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/router.py", line 161, in handle_request 
    response = view_callable(context, request) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/config/views.py", line 347, in rendered_view 
    result = view(context, request) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/config/views.py", line 493, in _requestonly_view 
    response = view(request) 
    File "/home/luke/pyramids/getwork2day.co.uk/getwork2day/views/signup.py", line 244, in user_signup 
    appstruct = myform.validate(controls) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 636, in validate 
    return self.validate_pstruct(pstruct) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 661, in validate_pstruct 
    cstruct = self.deserialize(pstruct) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 512, in deserialize 
    return self.widget.deserialize(self, pstruct) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/widget.py", line 1274, in deserialize 
    result[name] = subfield.deserialize(subval) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 512, in deserialize 
    return self.widget.deserialize(self, pstruct) 
    File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/widget.py", line 551, in deserialize 
    date = pstruct['date'].strip() 
TypeError: string indices must be integers 

ответ

0

По меньшей мере, форма управления формой дампа регистрируется и публикуется здесь. Постарайтесь быть более подробным & с примерами кода и не смешивать код схемы коллаборатора и код представления пирамиды.

if 'submit' in request.POST: 

    controls = request.POST.items() 
    try: 
     appstruct = myform.validate(controls) 
    except ValidationFailure, e: 
     log.debug('form validation fails for %r' % controls) 
     return {'form':e.render(), 'values': False}