I did supply a file, just NOT a PDF format file which causes
ValidationError to be raised (yea, probably want to make sure that
wasn't the problem :-{})  When I don't supply a filename, I do get the
correct error message back in form.errors.

But you could be correct about the FileField's clean method.  If I
detect a file isn't PDF format, I raise the exception so no filename is
passed back.  Could it be that the FileField clean method is called
AFTER mine?  I know my clean method is being called.

On Thu, 2009-05-28 at 13:06 -0700, V wrote:
> my guess is that the validation fails before reaching the
> clean_PDF_File method, that is it fails at the FileField's clean
> method. Perhaps, you haven't supplied a file. :)
> 
> On May 28, 3:02 pm, Adam Stein <a...@eng.mc.xerox.com> wrote:
> > Running Django v1.0.2.
> >
> > I have a form with a file field.  The file needs to be in PDF format, so
> > I have a clean routine that checks that (modified slightly to NOT wrap
> > lines):
> >
> >   def clean_PDF_File(self):
> >       """Verify that the content is PDF format"""
> >
> >       type = "application/pdf"
> >       if self.cleaned_data["PDF_File"].content_type != type:
> >           raise forms.ValidationError("File must be in PDF format")
> >
> >       return self.cleaned_data["PDF_File"]
> >
> > A simplified view looks like this:
> >
> >   if form.is_valid():
> >       <do valid stuff>
> >   else:
> >       print "Errors = [", form.errors, "]"
> >
> > I'm expecting form.errors to contain the message I gave to
> > ValidationError().  Instead, this is what prints out:
> >
> > Errors = [ <ul class="errorlist"><li>PDF_File<ul
> > class="errorlist"><li>The submitted file is empty.</li></ul></li></ul> ]
> >
> > What happened to my error message?  I can't pass the correct error
> > message to the form if I don't receive it in the first place.  When the
> > field is blank, I get the correct error message that I expect to see:
> >
> > Errors = [ <ul class="errorlist"><li>PDF_File<ul
> > class="errorlist"><li>This field is required.</li></ul></li></ul> ]
> >
> > Any thoughts on what else I might try or look at?
> > --
> > Adam Stein @ Xerox Corporation       Email: a...@eng.mc.xerox.com
> >
> > Disclaimer: Any/All views expressed
> > here have been proven to be my own.  [http://www.csh.rit.edu/~adam/]
> -- 
Adam Stein @ Xerox Corporation       Email: a...@eng.mc.xerox.com

Disclaimer: Any/All views expressed
here have been proven to be my own.  [http://www.csh.rit.edu/~adam/]


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to