Login

A action decorator for URLs

Author:
Batiste
Posted:
March 28, 2008
Language:
Python
Version:
.96
Tags:
rest url decorator action crud
Score:
3 (after 3 ratings)

This decorator handle a extra "action" parameter from an url and call this desired action in the provided views module.

Example:

from posts import views

urlpatterns = patterns('posts.views',
    ...
    url(r'^(?P<id>\d+)/(?P<action>delete|publish|edit)/$', action(views), name="posts-action"),
    ...
)

In templates:

{% url posts-action id=post.id,action="delete" %}
1
2
3
4
5
6
def action(views):
    def _dec(request, *args, **kwargs):
        action = kwargs['action']
        del kwargs['action']
        return getattr(views, action)(request, *args, **kwargs)
    return _dec

More like this

  1. Using class methods as views by panyam 5 years, 8 months ago
  2. load m2m fields objects by dirol 4 years, 8 months ago
  3. ParentModel and ChildManager for Model Inheritance by jpwatts 6 years, 5 months ago
  4. PK->objects in view signature by AdamKG 6 years, 11 months ago
  5. Resolve URLs to view name and args/kwargs by fahhem 4 years, 3 months ago

Comments

Please login first before commenting.