Gosh! Of course I should!!

Thanks!


On Fri, Oct 11, 2013 at 7:41 PM, Massimo Di Pierro <
[email protected]> wrote:

> If you read the file (csv.reader(sent_file) or sent_file.readlines(),
> etc.) you then have to rewind it:
>
> sent_file.seek(0)
>
>
>
>
> On Tuesday, 23 July 2013 21:18:07 UTC-5, __pyslan__ wrote:
>
>> Hello everybody.
>>
>>
>> I'm trying upload files with SQLFORM.grid.
>>
>> Model:
>>
>> FilesUploaded = db.define_table('files_**uploaded',
>>     Field('name', notnull=True, label=T("Name")),
>>     Field('file_name', 'upload', notnull=False, label=T("File")),
>>     Field('owner_group', 'reference auth_group', notnull=True, 
>> label=T("Owner Group")),
>>     Field('creation', 'datetime', notnull=True, 
>> default=datetime.datetime.now(**), label=T("Creation")),
>>     format='%(name)s')
>>
>>
>> Constraints:
>>
>> FilesUploaded.owner_group.comp**ute = lambda row: 
>> auth.user_groups.keys()[0]FilesUploaded.owner_group.read**able = 
>> FalseFilesUploaded.owner_group.writ**able = False
>> FilesUploaded.creation.writabl**e = FalseFilesUploaded.file_name.requir**es 
>> = IS_LENGTH(maxsize=(1024*(1024***5)), error_message=T("Send files with a 
>> maximum size of") + " 5GB.")
>>
>>
>> def upload_validation(form):
>>     sent_file = request.vars.file_name.file
>>     file_name = request.vars.file_name.filenam**e
>>     extension_file = file_name.split('.')[-1]
>>
>>     if extension_file == 'csv':
>>         import csv
>>         file_lines = list(csv.reader(sent_file, delimiter=',', 
>> quoting=csv.QUOTE_NONE))
>>     elif extension_file == 'txt':
>>         file_lines = list(sent_file.readlines())
>>     else:
>>         form.errors.file_name = T("The file types supported are .csv or 
>> .txt")
>>         return False
>>
>>     max_lines = 100000
>>
>>     if len(lines) > max_lines:
>>         form.errors.file_name = T("Maximum quantity per upload is %(qty)s 
>> lines.") % dict(qty = max_lines)
>>         return False
>>
>> Controller:
>>
>> form=SQLFORM.grid(query, csv=False, fields=fields, links=links, 
>> user_signature=True, onvalidation=upload_validation**)
>>
>>
>>
>> 1 -> The file size is 0 bytes after upload.
>> 2 -> But, if I put the command "print request" on the last line of
>> upload_validation function, works fine.
>>
>>
>> If anyone can help me, I appreciate!
>>
>>
>> __pyslan__
>>
>>
>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
>
> ---
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to