Re: No request.FILES, but file is still uploaded?

2008-05-09 Thread Beals

> Does your model have a FileField?

Thanks, Karen.  Yes, my model has a FileField.  The doc never says
explicitly that it the save will happen, which was the source of my
confusion.  It appears that it does when you have a FileField (I dove
into the newforms code a bit and am partially convinced this is taking
place).

-Aaron

On May 8, 7:03 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Thu, May 8, 2008 at 3:51 PM, Beals <[EMAIL PROTECTED]> wrote:
> > Correction: request.FILES does exist -- it just wasn't getting printed
> > out with "print request".  An explicit "print request.FILES" did the
> > trick.
>
> > However, my question still stands: is form.save(commit=False) supposed
> > to be writing the file out to disk?  Is this the newforms way of
> > handling uploads, and therefore is checking for request.FILES and
> > writing the file out ourselves passé?
>
> Does your model have a FileField?  If so, then yes, I'd expect save of a
> ModelForm for that model to save the file to disk.  Haven't checked the doc
> to see if it explicitly says that will happen, that is just how I would
> expect it to behave.
>
> Not sure if/how this is different from oldforms, since I never used them.
> But checking request.FILES etc is not necessarily passé, it just depends on
> your model setup.  In my own app, I do upload files, but I don't use
> FileField (nor ModelForms), so I have to handle writing the uploaded file to
> the appropriate place myself.
>
> Karen
>
>
>
> > On May 8, 3:43 pm, Beals <[EMAIL PROTECTED]> wrote:
> > > A while back, I looked for code snippets for uploading files.  Almost
> > > every site I found contained something like the following:
>
> > > if 'file' in request.FILES:
> > >     file = request.FILES['file']
> > >     filename = file['filename']
> > >     fd = open('%s/%s' % (MEDIA_ROOT, filename), 'wb')
> > >     fd.write(file['content'])
> > >     fd.close
> > > else:
> > >     print "No file attached."
>
> > > This seemed to work -- files were uploaded and the pointers from the
> > > model worked fine, so I never thought to look at the logs... until
> > > today, and I noticed that even though the uploads were working
> > > properly, the "No file attached" message kept showing up.  Drilling
> > > in, I found that FILES wasn't even in the request object!  Yet the
> > > file was still written to disk... weird.
>
> > > So I started putting breakpoints in to figure out where in my view the
> > > file was getting written out.  The fourth line is the culprit:
>
> > > if request.method == 'POST':
> > >     form = FooForm(request.POST, request.FILES)
> > >     if form.is_valid():
> > >         new_artifact = form.save(commit=False)
> > >         *BREAKPOINT*
>
> > > So how/why is form.save(commit=False) writing the file out to disk??
> > > Is this expected behavior for ModelForms?  (NOTE: in case it matters,
> > > I'm using the built-in Django webserver.)
>
> > > -Aaron
--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: No request.FILES, but file is still uploaded?

2008-05-09 Thread [EMAIL PROTECTED]

I don't think this matters here, but you're overriding the 'file'
builtin.

On May 8, 7:03 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Thu, May 8, 2008 at 3:51 PM, Beals <[EMAIL PROTECTED]> wrote:
> > Correction: request.FILES does exist -- it just wasn't getting printed
> > out with "print request".  An explicit "print request.FILES" did the
> > trick.
>
> > However, my question still stands: is form.save(commit=False) supposed
> > to be writing the file out to disk?  Is this the newforms way of
> > handling uploads, and therefore is checking for request.FILES and
> > writing the file out ourselves passé?
>
> Does your model have a FileField?  If so, then yes, I'd expect save of a
> ModelForm for that model to save the file to disk.  Haven't checked the doc
> to see if it explicitly says that will happen, that is just how I would
> expect it to behave.
>
> Not sure if/how this is different from oldforms, since I never used them.
> But checking request.FILES etc is not necessarily passé, it just depends on
> your model setup.  In my own app, I do upload files, but I don't use
> FileField (nor ModelForms), so I have to handle writing the uploaded file to
> the appropriate place myself.
>
> Karen
>
>
>
> > On May 8, 3:43 pm, Beals <[EMAIL PROTECTED]> wrote:
> > > A while back, I looked for code snippets for uploading files.  Almost
> > > every site I found contained something like the following:
>
> > > if 'file' in request.FILES:
> > >     file = request.FILES['file']
> > >     filename = file['filename']
> > >     fd = open('%s/%s' % (MEDIA_ROOT, filename), 'wb')
> > >     fd.write(file['content'])
> > >     fd.close
> > > else:
> > >     print "No file attached."
>
> > > This seemed to work -- files were uploaded and the pointers from the
> > > model worked fine, so I never thought to look at the logs... until
> > > today, and I noticed that even though the uploads were working
> > > properly, the "No file attached" message kept showing up.  Drilling
> > > in, I found that FILES wasn't even in the request object!  Yet the
> > > file was still written to disk... weird.
>
> > > So I started putting breakpoints in to figure out where in my view the
> > > file was getting written out.  The fourth line is the culprit:
>
> > > if request.method == 'POST':
> > >     form = FooForm(request.POST, request.FILES)
> > >     if form.is_valid():
> > >         new_artifact = form.save(commit=False)
> > >         *BREAKPOINT*
>
> > > So how/why is form.save(commit=False) writing the file out to disk??
> > > Is this expected behavior for ModelForms?  (NOTE: in case it matters,
> > > I'm using the built-in Django webserver.)
>
> > > -Aaron
--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: No request.FILES, but file is still uploaded?

2008-05-08 Thread Karen Tracey
On Thu, May 8, 2008 at 3:51 PM, Beals <[EMAIL PROTECTED]> wrote:

> Correction: request.FILES does exist -- it just wasn't getting printed
> out with "print request".  An explicit "print request.FILES" did the
> trick.
>
> However, my question still stands: is form.save(commit=False) supposed
> to be writing the file out to disk?  Is this the newforms way of
> handling uploads, and therefore is checking for request.FILES and
> writing the file out ourselves passé?
>

Does your model have a FileField?  If so, then yes, I'd expect save of a
ModelForm for that model to save the file to disk.  Haven't checked the doc
to see if it explicitly says that will happen, that is just how I would
expect it to behave.

Not sure if/how this is different from oldforms, since I never used them.
But checking request.FILES etc is not necessarily passé, it just depends on
your model setup.  In my own app, I do upload files, but I don't use
FileField (nor ModelForms), so I have to handle writing the uploaded file to
the appropriate place myself.

Karen




>
> On May 8, 3:43 pm, Beals <[EMAIL PROTECTED]> wrote:
> > A while back, I looked for code snippets for uploading files.  Almost
> > every site I found contained something like the following:
> >
> > if 'file' in request.FILES:
> > file = request.FILES['file']
> > filename = file['filename']
> > fd = open('%s/%s' % (MEDIA_ROOT, filename), 'wb')
> > fd.write(file['content'])
> > fd.close
> > else:
> > print "No file attached."
> >
> > This seemed to work -- files were uploaded and the pointers from the
> > model worked fine, so I never thought to look at the logs... until
> > today, and I noticed that even though the uploads were working
> > properly, the "No file attached" message kept showing up.  Drilling
> > in, I found that FILES wasn't even in the request object!  Yet the
> > file was still written to disk... weird.
> >
> > So I started putting breakpoints in to figure out where in my view the
> > file was getting written out.  The fourth line is the culprit:
> >
> > if request.method == 'POST':
> > form = FooForm(request.POST, request.FILES)
> > if form.is_valid():
> > new_artifact = form.save(commit=False)
> > *BREAKPOINT*
> >
> > So how/why is form.save(commit=False) writing the file out to disk??
> > Is this expected behavior for ModelForms?  (NOTE: in case it matters,
> > I'm using the built-in Django webserver.)
> >
> > -Aaron
> >
>

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: No request.FILES, but file is still uploaded?

2008-05-08 Thread Beals

Correction: request.FILES does exist -- it just wasn't getting printed
out with "print request".  An explicit "print request.FILES" did the
trick.

However, my question still stands: is form.save(commit=False) supposed
to be writing the file out to disk?  Is this the newforms way of
handling uploads, and therefore is checking for request.FILES and
writing the file out ourselves passé?

On May 8, 3:43 pm, Beals <[EMAIL PROTECTED]> wrote:
> A while back, I looked for code snippets for uploading files.  Almost
> every site I found contained something like the following:
>
> if 'file' in request.FILES:
>     file = request.FILES['file']
>     filename = file['filename']
>     fd = open('%s/%s' % (MEDIA_ROOT, filename), 'wb')
>     fd.write(file['content'])
>     fd.close
> else:
>     print "No file attached."
>
> This seemed to work -- files were uploaded and the pointers from the
> model worked fine, so I never thought to look at the logs... until
> today, and I noticed that even though the uploads were working
> properly, the "No file attached" message kept showing up.  Drilling
> in, I found that FILES wasn't even in the request object!  Yet the
> file was still written to disk... weird.
>
> So I started putting breakpoints in to figure out where in my view the
> file was getting written out.  The fourth line is the culprit:
>
> if request.method == 'POST':
>     form = FooForm(request.POST, request.FILES)
>     if form.is_valid():
>         new_artifact = form.save(commit=False)
>         *BREAKPOINT*
>
> So how/why is form.save(commit=False) writing the file out to disk??
> Is this expected behavior for ModelForms?  (NOTE: in case it matters,
> I'm using the built-in Django webserver.)
>
> -Aaron
--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



No request.FILES, but file is still uploaded?

2008-05-08 Thread Beals

A while back, I looked for code snippets for uploading files.  Almost
every site I found contained something like the following:

if 'file' in request.FILES:
file = request.FILES['file']
filename = file['filename']
fd = open('%s/%s' % (MEDIA_ROOT, filename), 'wb')
fd.write(file['content'])
fd.close
else:
print "No file attached."

This seemed to work -- files were uploaded and the pointers from the
model worked fine, so I never thought to look at the logs... until
today, and I noticed that even though the uploads were working
properly, the "No file attached" message kept showing up.  Drilling
in, I found that FILES wasn't even in the request object!  Yet the
file was still written to disk... weird.

So I started putting breakpoints in to figure out where in my view the
file was getting written out.  The fourth line is the culprit:

if request.method == 'POST':
form = FooForm(request.POST, request.FILES)
if form.is_valid():
new_artifact = form.save(commit=False)
*BREAKPOINT*

So how/why is form.save(commit=False) writing the file out to disk??
Is this expected behavior for ModelForms?  (NOTE: in case it matters,
I'm using the built-in Django webserver.)

-Aaron
--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---