On Thu, Jul 22, 2010 at 4:30 AM, Russell Keith-Magee
<russ...@keith-magee.com> wrote:
> I accept the need for this, but this seems like a bit of a wart. This
> method wouldn't be required at all if the Form took a request
> argument. This isn't an unusual requirement, either -- perhaps we
> should introduce a RequestForm/RequestModelForm that formalizes the
> availability of the request object during form processing.

OK, I've now added a Request(Model)Form. The tag is based on
<cls.__module__>.<cls.__name__>, so you don't have to manually specify
it. FileField takes an optional parameter to override this. Forms
currently only allow to set the tag by subclassing. Not sure if this
is sufficient.
http://code.djangoproject.com/attachment/ticket/13960/filetransfers.3.diff

I could need some feedback. Does this go in the right direction? Is
anything important missing?

class UploadForm(RequestModelForm):
    class Meta:
        model = bla

form = UploadForm(request)
render_to_response(... {... 'form': form} ...)

<form action="{{ form.upload_url }}">
{{ form }}
</form>

Apart from that you can call file.serve() and file.download_url() as
discussed in the previous posts. You can see another example in the
unit tests of my patch. It also contains a delegation backend which
allows to easily specify which backend should be used for which
app/form/model/field via the settings:

DEFAULT_FILE_TRANSFER_BACKENDS = {
    'myapp.*': 'some.backend',
    'myapp.models.MyModel.s3_file': 'S3Backend',
    'otherapp.models.SomeModel.*': 'OtherBackend',
}

If you need more control you can use FILE_TRANSFER_BACKENDS which
works more like the routers API.

Bye,
Waldemar Kornewald

--
Django on App Engine, MongoDB, ...? Browser-side Python? It's open-source:
http://www.allbuttonspressed.com/blog/django

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to