Re: File upload and custom manipulator

2006-08-05 Thread didier Belot

2006/8/5, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> I had problems with file uploading time ago and I found this post
>
> http://groups.google.com/group/django-users/browse_thread/thread/d83259c6bdd0151f/3880fdebcef9a367?lnk=gst=uploading+images=5#3880fdebcef9a367
>
> It helped me so much. And I wonder it could help you.
Thanks for the link.


> Notice the atributes of the form in the template, specially
> enctype="multipart/form-data"
>
> Also note that the "real" content of the file is at
>
>  data = request.FILES[ 'file' ][ 'content' ]

Yes. The main point is that my form and view works great with the
automatic AddManipulator, but I want to make it working with a custom
manipulator.

Anyway, i'm currently trying to understand the AutomaticManipulator
code, where certainly is the solution ;-)

Thanks again.
-- 
didier

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



File upload and custom manipulator

2006-08-04 Thread didier Belot

Hello,

I have a model with a FileField.
When using the MyModel.AddManipulator() in the view, everything works
as expected.

But I need a custom manipulator. I've already made some custom
manipulators that works pretty well, so I'm sure I'm not too wrong
here. The one that don"t works is the one that need to save an
uploaded file.

Here it is:

class CsvDataManipulator(forms.Manipulator):
def __init__(self, pk=None):
if pk:
self.original_object = CsvData.objects.get(id=pk)
self.pk = pk
else:
self.original_object = None
self.pk = None

self.fields = (
forms.FileUploadField(field_name='csv_file', is_required=False),
forms.TextField(field_name='csv_sep', is_required=True,
maxlength=1),
)

def save(self, new_data):
if self.original_object:
temp = dict(
csv_file=new_data['csv_file'],
csv_sep=new_data['csv_sep']
)
for k,v in temp.iteritems():
self.original_object.__setattr__(k, v)
self.original_object.save()
return CsvData.objects.get(id=pk)
else:
temp = CsvData(
csv_file=new_data['csv_file'],
csv_sep=new_data['csv_sep']
)

temp.save()
return temp

In the view, it's used like this:
...
manipulator = CsvDataManipulator()
new_data = request.POST.copy()
if request.FILES:
new_data.update(request.FILES)
errors = manipulator.get_validation_errors(new_data)


Then i have an error that show that new_data['csv_file'] hold  the
content of the uploaded file:

Any help welcome.

Thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---