I need a multi file uploader. Web2py does not have it yet.
I saw an example using another table for the files.
I dont know how to sqlform 2 tables.
The book showed me how to do it with sqlform.factory



Thank you
António

2013/1/21 Massimo Di Pierro <massimo.dipie...@gmail.com>

> If you want want to interact with a database table why use SQLFORM.factory
> and not simply SQLFORM?
>
>
> On Monday, 21 January 2013 15:25:07 UTC-6, Ramos wrote:
>
>> Thank you Massimo, you are always available to help. Where is Bill Gates
>> when we need it right?
>>
>> I restarted web2py and it works....
>>
>> Strange....
>>
>> Second question.
>> as i am using sqlform.factory to add records how to use it also to update
>> or delete?
>>
>>
>> Thank YOU again!
>>
>> António
>>
>>
>>  2013/1/21 Massimo Di Pierro <massimo....@gmail.com>
>>
>> Here is my test.
>>>
>>> $ python web2py.py -S welcome
>>> (InteractiveConsole)
>>> >>> import sys
>>> >>> form = SQLFORM.factory(Field('name'))
>>> >>> form.process(onvalidation=**lambda form:sys.stdout.write('check!\**
>>> n'),formname=None,session=**None)
>>> check!
>>>
>>> It works. Something else is wrong in your code. If you could post a
>>> complete example we can try help you debug it.
>>>
>>> Massimo
>>>
>>>
>>>
>>>
>>> On Monday, 21 January 2013 12:03:11 UTC-6, Ramos wrote:
>>>
>>>> Sorry for insisting,
>>>>
>>>> I ´m using onvalidation in sqlform but if i use it in sqlform.factory i
>>>> get a flash message
>>>> Errors in Form. Please check it out!!!
>>>>
>>>> *Secondly*
>>>>  as i am using sqlform.factory to add records how to use it also to
>>>> update or delete?
>>>>
>>>> Thank you
>>>> António
>>>>
>>>> 2013/1/21 Massimo Di Pierro <massimo....@gmail.com>
>>>>
>>>> yes.
>>>>>
>>>>>
>>>>> On Monday, 21 January 2013 11:35:00 UTC-6, Ramos wrote:
>>>>>
>>>>>> can onvalidation be used with sqlform.factory ?
>>>>>>
>>>>>> i´m getting error
>>>>>>
>>>>>> Errors in Form. Please check it out!!!
>>>>>>
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>>
>>>>>> António
>>>>>>
>>>>>> 2013/1/17 Massimo Di Pierro <massimo....@gmail.com>
>>>>>>
>>>>>> *You are storing the image twice:*
>>>>>>> *
>>>>>>> *
>>>>>>> *if 
>>>>>>> trabalhador_form.process(onvalidation=attach_image_to_record).accepted:
>>>>>>> # here after validation *
>>>>>>>  *def attach_image_to_record(form):*
>>>>>>>     ...
>>>>>>>     photo=db.trabalhador.foto.**stor******e(temp,'foto.jpg') # here
>>>>>>> on validation
>>>>>>> *    ... *
>>>>>>>     form.vars.photo=photo  *# here is where someting goes wrong....*
>>>>>>> *
>>>>>>> *
>>>>>>> *The problem is that you altering the form on validation.*
>>>>>>> *
>>>>>>> *
>>>>>>> *
>>>>>>> *
>>>>>>> *This this:*
>>>>>>> *
>>>>>>> *
>>>>>>>  **
>>>>>>> *def attach_image_to_record(form):*
>>>>>>>     import cgi
>>>>>>>     response=requests.get(form.**var******s.fp_url)
>>>>>>>      img=Image.open(StringIO(**respon******se.content))
>>>>>>>     img.save('foto1231.jpg','JPEG'********)
>>>>>>>     photo = cgi.FieldStorage()
>>>>>>>     photo.file = open('foto1231.jpg','rb')
>>>>>>>     photo.filename = 'foto.jpg'
>>>>>>>     form.vars.photo=photo # not this on, you let process do upload
>>>>>>>
>>>>>>>
>>>>>>> **
>>>>>>>
>>>>>>> This is very important for me ,
>>>>>>> *
>>>>>>> *
>>>>>>> *
>>>>>>> *
>>>>>>> On Wednesday, 16 January 2013 07:49:30 UTC-6, Ramos wrote:
>>>>>>>
>>>>>>>> I just noticed one image created in upload folder and one txt file.
>>>>>>>> Inside the txt file i see the name of jpg file created above.
>>>>>>>>
>>>>>>>>
>>>>>>>> why is that?
>>>>>>>>
>>>>>>>> help please :)
>>>>>>>>
>>>>>>>> António
>>>>>>>>
>>>>>>>> 2013/1/16 António Ramos <ramst...@gmail.com>
>>>>>>>>
>>>>>>>>>  can onvalidation set upload  file field?
>>>>>>>>>
>>>>>>>>> i was complaining that form.vars was empty.
>>>>>>>>> It is if the controller does not return the form to the view
>>>>>>>>> So i return the form and away with my quest.
>>>>>>>>>
>>>>>>>>> Now, in onvalidation i set  the field with the upload file.
>>>>>>>>> I have to becaue i have a different upload button that goes online
>>>>>>>>> to get a file.
>>>>>>>>> Its working but the image file i set goes as a txt file to the
>>>>>>>>> database, why
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> here my code:
>>>>>>>>> (I use PIL module)
>>>>>>>>>
>>>>>>>>> *if trabalhador_form.process(onvalidation=attach_image_to_record
>>>>>>>>> ).accepted:*
>>>>>>>>>
>>>>>>>>> *def attach_image_to_record(form):*
>>>>>>>>>
>>>>>>>>>     response=requests.get(form.**var******s.fp_url)
>>>>>>>>>     img=Image.open(StringIO(**respon******se.content))
>>>>>>>>>     img.save('foto1231.jpg','JPEG'********)
>>>>>>>>>     temp=open('foto1231.jpg','rb')
>>>>>>>>>     photo=db.trabalhador.foto.**stor******e(temp,'foto.jpg')
>>>>>>>>> *    print photo   # echoes something like     "trabalhador.foto.
>>>>>>>>> 989708787087078.9823492034.jpg*
>>>>>>>>>      form.vars.photo=photo  *# here is where someting goes
>>>>>>>>> wrong....*
>>>>>>>>>
>>>>>>>>> This is very important for me ,
>>>>>>>>> can anyone explain why a jpg is inserted as a txt? how to force
>>>>>>>>> jpg ?
>>>>>>>>>
>>>>>>>>> Thank you
>>>>>>>>> António
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> 2013/1/15 António Ramos <ramst...@gmail.com>
>>>>>>>>>
>>>>>>>>>> I´m testing this book example
>>>>>>>>>> http://web2py.com/books/**defaul******t/chapter/29/07#**
>>>>>>>>>> onvalidation<http://web2py.com/books/default/chapter/29/07#onvalidation>
>>>>>>>>>>  I get error on field named 'a'
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Traceback (most recent call last):
>>>>>>>>>>   File "C:\web2pyGit\web2py\gluon\**res******tricted.py", line 212, 
>>>>>>>>>> in restricted
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     exec ccode in environment
>>>>>>>>>>   File 
>>>>>>>>>> "C:/web2pyGit/web2py/**applicati******ons/teste1/models/db.**py" 
>>>>>>>>>> <http://127.0.0.1:8000/admin/default/edit/teste1/models/db.py>, line 
>>>>>>>>>> 91, in <module>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     Field('c', 'integer', readable=False, writable=False))
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>   File "C:\web2pyGit\web2py\gluon\**dal******.py", line 7189, in 
>>>>>>>>>> define_table
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     table = self.lazy_define_table(tablena********me,*fields,**args)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>   File "C:\web2pyGit\web2py\gluon\**dal******.py", line 7206, in 
>>>>>>>>>> lazy_define_table
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     table = table_class(self, tablename, *fields, **args)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>   File "C:\web2pyGit\web2py\gluon\**dal******.py", line 7612, in 
>>>>>>>>>> __init__
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     db.check_reserved_keyword(fiel********d_name)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>   File "C:\web2pyGit\web2py\gluon\**dal******.py", line 6933, in 
>>>>>>>>>> check_reserved_keyword
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>     'invalid table/column name "%s" is a "%s" reserved SQL keyword' 
>>>>>>>>>> % (name, backend.upper()))
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> SyntaxError: invalid table/column name "a" is a "ALL" reserved SQL 
>>>>>>>>>> keyword
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> So i renamed all to a1,b1,c1 and it works !
>>>>>>>>>>
>>>>>>>>>> Now my initial complain is still not working. I will test
>>>>>>>>>> tomorrow and post some code.
>>>>>>>>>> Meanwhile please check why a is not a valid field name and update
>>>>>>>>>> the book if necessary.
>>>>>>>>>> thank you
>>>>>>>>>>
>>>>>>>>>> 2013/1/15 Anthony <abas...@gmail.com>
>>>>>>>>>>
>>>>>>>>>> form.vars should work. Can you show more code? Note,
>>>>>>>>>>> form.request_vars is simply a copy of the original 
>>>>>>>>>>> request.post_vars, so
>>>>>>>>>>> not equivalent to form.vars.
>>>>>>>>>>>
>>>>>>>>>>> Anthony
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Tuesday, January 15, 2013 10:17:08 AM UTC-5, Ramos wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> hello reading the book online i tried the code
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> def my_form_processing(form):
>>>>>>>>>>>>     c = form.vars.a
>>>>>>>>>>>>
>>>>>>>>>>>>     form.vars.b
>>>>>>>>>>>>     if c < 0:
>>>>>>>>>>>>         form.errors.b = 'a'
>>>>>>>>>>>>     else:
>>>>>>>>>>>>         form.vars.c = c
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> but form.vars was empty
>>>>>>>>>>>>
>>>>>>>>>>>> to access my form vars i changed to form.request_vars
>>>>>>>>>>>>
>>>>>>>>>>>> *Is the book wrong?*
>>>>>>>>>>>>
>>>>>>>>>>>> Thank you
>>>>>>>>>>>> António
>>>>>>>>>>>>
>>>>>>>>>>>  --
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>  --
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>  --
>>>
>>>
>>>
>>>
>>
>>  --
>
>
>
>

-- 



Reply via email to