Please open a ticket with the problem description.

On Monday, 30 April 2012 14:29:01 UTC-5, Carlos wrote:
>
> After further testing, it looks this proposed fix incorrectly removes the 
> file from the upload field in the record being edited ... not sure yet.
>
> Can something be done along these lines to make onvalidation work 
> properly?.
>
>
> On Monday, April 30, 2012 2:21:37 PM UTC-5, Carlos wrote:
>>
>> Hi Massimo,
>>
>> The onvalidation function is not getting properly executed when editing 
>> an existing record with an upload field with an already uploaded file, as 
>> stated in the following current fix (just after FORM.accepts call in 
>> SQLFORM.accepts @ sqlhtml.py):
>>
>>         if not ret and self.record and self.errors:
>>             ### if there are errors in update mode
>>             # and some errors refers to an already uploaded file
>>             # delete error if
>>             # - user not trying to upload a new file
>>             # - there is existing file and user is not trying to delete it
>>             # this is because removing the file may not pass validation
>>             for key in self.errors.keys():
>>                 if key in self.table \
>>                         and self.table[key].type == 'upload' \
>>                         and request_vars.get(key, None) in (None, '') \
>>                         and self.record[key] \
>>                         and not key + UploadWidget.ID_DELETE_SUFFIX in 
>> request_vars:
>>                     del self.errors[key]
>>             if not self.errors:
>>                 ret = True
>>
>> Unfortunately the above does not fix the onvalidation problem, which is 
>> not being called in these situations (editing an existing record with an 
>> upload field with an already uploaded file).
>>
>> My proposal to fix the above (with polymorphism):
>>
>> + remove the above code for the existing fix.
>>
>> + in FORM.accepts @ html.py, call the following after [ status = 
>> self._traverse(status,hideerror) ]:
>>
>>         status = self.assert_status(status, request_vars)
>>
>> + in FORM @ html.py, create the following method (polymorphism # 1):
>>
>>     def assert_status(self, status, request_vars):
>>         return status
>>
>> + in SQLFORM @ sqlhtml.py, create the following method (polymorphism # 2):
>>
>>     def assert_status(self, status, request_vars):
>>         if not status and self.record and self.errors:
>>             ### if there are errors in update mode
>>             # and some errors refers to an already uploaded file
>>             # delete error if
>>             # - user not trying to upload a new file
>>             # - there is existing file and user is not trying to delete it
>>             # this is because removing the file may not pass validation
>>             for key in self.errors.keys():
>>                 if key in self.table \
>>                         and self.table[key].type == 'upload' \
>>                         and request_vars.get(key, None) in (None, '') \
>>                         and self.record[key] \
>>                         and not key + UploadWidget.ID_DELETE_SUFFIX in 
>> request_vars:
>>                     del self.errors[key]
>>             if not self.errors:
>>                 status = True
>>         return status
>>
>> Now the new fix is executed in FORM.accepts, which causes onvalidation to 
>> be called based on the proper value for status.
>>
>> If you agree and if this does not break anything, can you please include 
>> it in trunk?.
>>
>> Thanks,
>>
>>    Carlos
>>
>

Reply via email to