Massimo, the strange behavior continues to occur...
I had to make a change and store the number of lines that the file has.
Added a function to the oncreate SQLFORM.grid as follows:
def set_total_emails(form):
print request.vars.file_name
form.vars.file_name = request.post_vars.file_name
sent_file = request.vars.file_name.file
file_name = request.vars.file_name.filename
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())
db(db.files_uploaded.id == form.vars.id).update(total_lines =
len(file_lines))
If I do not enter the "print request.vars.file_name" I can not get the
total rows, it returns 0.
Note: web2py 2.7.2
Is there any other way I can do the same thing?
Thanks!!
On Fri, Jul 26, 2013 at 4:52 AM, Massimo Di Pierro <
[email protected]> wrote:
> This is very very strange. One possibility is that something is wrong with
> your version of python. Another possibility is that you are using
> current.request incorrectly in one of your modules (for example request =
> current.request used outside a function).
>
>
> On Thursday, 25 July 2013 18:55:54 UTC-5, __pyslan__ wrote:
>
>> Works with:
>>
>> print request
>> print request.vars
>> print request.vars.file_name
>>
>> But if i put for example:
>> print request.var._formname
>> Doesn't work! I have to print something related with file_name field.
>>
>>
>>
>>
>> On Thu, Jul 25, 2013 at 8:30 PM, __pyslan__ - Ayslan Jenken <
>> [email protected]> wrote:
>>
>>> I'm sorry, web2py version is 2.5.1.
>>>
>>>
>>> On Thu, Jul 25, 2013 at 8:27 PM, __pyslan__ - Ayslan Jenken <
>>> [email protected]> wrote:
>>>
>>>> I don't understand too, I do not see any connection, but I'm sure...
>>>> Without "print request" command the file uploaded has 0 bytes. With "print
>>>> request" command the file uploaded has the correct size...
>>>>
>>>>
>>>> On Thu, Jul 25, 2013 at 10:04 AM, Massimo Di Pierro <
>>>> [email protected]> wrote:
>>>>
>>>>> Are you sure about your point 2. I do not see how adding a print
>>>>> statement can affect the working (or not working) of this form.
>>>>>
>>>>>
>>>>> 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_**uploade**d',
>>>>>> 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__
>>>>>>
>>>>>>
>>>>>> --
>>>>>
>>>>> ---
>>>>> 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 web2py+un...@**googlegroups.com.
>>>>>
>>>>> For more options, visit
>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>>> .
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>> --
>
> ---
> 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.