Can I change request.vars before inserting to sqlform ?

60 views
Skip to first unread message

JorgeH

unread,
Sep 5, 2014, 9:52:37 AM9/5/14
to web...@googlegroups.com
Hello

I've been trying to use a compute field that needs to use a class I created . But I get the error  : TypeError: unhashable type: 'list'

Thus I intend to instead of a computed field, just do the calculations before  processing the form.

  if form1.process(session=None, formname='tabla1').accepted:

The field I intend to calculate before inserting is 'consumo_mensual'

my code so  far is similar to this:

form1 = SQLFORM(db.energia_termica)

request.vars.consumo_mensual = ConvEtermica(request.vars.tipo ,request.vars.consumo_teorico, request.vars.horas_uso_mes).consumo_mensual()

form1.vars.consumo_mensual = request.vars.consumo_mensual
 if form1.process(session=None, formname='tabla1').accepted:



but it really is ignoring my tweak

What is the correct way to doing it?

Thanks


Anthony

unread,
Sep 5, 2014, 10:32:57 AM9/5/14
to web...@googlegroups.com
Make the change before creating the form. But perhaps we should figure out how to make your computed field work instead.

JorgeH

unread,
Sep 5, 2014, 10:54:44 AM9/5/14
to web...@googlegroups.com
Thanks for your reply:

This does not work:


  request.vars.consumo_mensual = ConvEtermica(request.vars.tipo ,request.vars.consumo_teorico, request.vars.horas_uso_mes).consumo_mensual()
  form1 = SQLFORM(db.energia_termica)

and this:
  form1.vars.consumo_mensual = ConvEtermica(request.vars.tipo ,request.vars.consumo_teorico, request.vars.horas_uso_mes).consumo_mensual()
  form1 = SQLFORM(db.energia_termica)
 
give me this error;

    form1.vars.consumo_mensual = ConvEtermica(request.vars.tipo ,request.vars.consumo_teorico, request.vars.horas_uso_mes).consumo_mensual()
UnboundLocalError: local variable 'form1' referenced before assignment

Error snapshot help

<type 'exceptions.UnboundLocalError'>(local variable 'form1' referenced before assignment)




Anthony

unread,
Sep 5, 2014, 11:11:01 AM9/5/14
to web...@googlegroups.com
Try request.post_vars instead of request.vars.

JorgeH

unread,
Sep 5, 2014, 11:27:14 AM9/5/14
to web...@googlegroups.com
Ok

this do the trick:

  request.post_vars.consumo_mensual= ConvEtermica(request.vars.tipo ,request.vars.consumo_teorico, request.vars.horas_uso_mes).consumo_mensual()
  form1 = SQLFORM(db.energia_termica)
 

Thanks!
Reply all
Reply to author
Forward
0 new messages