On 5/15/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
>
> Jay Parlar wrote:
>
> >I'm still curious though if doing the
> >new_data.update(request.FILES.copy()) is the best way to do that part
> >of it.
> >
> >
> Only if you don't care of lost files in your upload :-). Here's the code
> that I use in my project to handle this. The function receives list of
> file fields excludes them from saving by manipulator and handles deletes
> and overrides manually. It assumes that file should be deleted if its
> associated field in POST is empty.
>
> def process_file_post(manipulator,request,field_names):
> data=request.POST.copy()
> # file data is not included in data for manipulator.save because
> # Django can't handle file deletes and overrides
> validation_data=data.copy()
> validation_data.update(request.FILES.copy())
> errors=manipulator.get_validation_errors(validation_data)
> manipulator.do_html2python(data)
> if errors:
> raise EManipulatorErrors, (errors,data)
> for field_name in field_names:
> old_filename=getattr(manipulator.original_object,field_name) and
> getattr(manipulator.original_object,'get_%s_filename'%field_name)()
> obj=manipulator.save(data)
> file_field=request.FILES.get('%s_file'%field_name,'')
> if (not data[field_name] or file_field) and old_filename:
> os.remove(old_filename)
> if file_field:
>
> getattr(obj,'save_%s_file'%field_name)(file_field['filename'],file_field['content'])
> return obj
>
>
Hmm... So let me get this straight... When someone does an upload via
my form, Django *temporarily* stores it in my uploads directory, with
the "_" at the end of the filename, right? And then when we do the
save(), it saves it again in uploads/, but this time with the proper
filename?
Jay P.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---