Snippet List
In an admin custom view I had the requirement to modify the upload handlers.
However, the @staff_member_required locked the Files upload handlers as it uses the request.POST - see [Ticket 7654](http://code.djangoproject.com/ticket/7654).
These decorators can be used before other decorators to allow setting of the upload handlers.
Usage example:
@upload_handlers_insert(0, QuotaUploadHandler)
@staff_member_required
def upload(request):
pass
- admin
- decorator
- file
- uploadhandler
Based on [danjak's](http://www.djangosnippets.org/users/danjak/) [snippet](http://www.djangosnippets.org/snippets/99/) but updated to use ModelForms - so can easily handle generic CRUD operations.
A replacement create_update.py for use with ModelForm
create_object and update_project modified to handle newforms (including FileFields) with ModelForm - it also had delete_object as well for completeness.
In addition, it has some extras:
* extra_fields - this is a dict or callable that contains additional fields to be passed to the form, for example stuff that is in the session.
* on_success - callback called if form is valid and object created/updated, if this is not set the default behaviour is to send a redirect
* on_failure - callback called if form is invalid, the default is to redisplay the form.
Note that once newforms are finally done these functions are likely to be redundant, as generic views will be updated to use the newforms API, so use with caution!
- newforms
- forms
- generic-views
- modelform
Rozza has posted 2 snippets.