Skip to main content

A collection of toys to skip the forplay with Django and go straight to the point: url and view decorators

Project description

Django-quicky
==============

A collection of toys to skip the forplay with Django and go straight to the point: url and view decorators.

You will fall in love with it if you ever had the fantasm you could do:

@url('/user/\d+')
@view(render_to='user.html'):
def user_view(request, id)
...
return {'users': users}


@user_view.ajax(render_to='json')
def ajax_user_view(request, id, context):
...
return context

And yes, this is alpha software, but you already want it, so don't fight it !


Url decorators
===============

If you like micro frameworks like <a href="http://bottlepy.org/docs/dev/">bottle</a>, you probably miss the very easy way to declare a route.

Shhh, baby. Talk no more:

from django_quicky import routing

url, urlpatterns = routing()


@url('/any/regex/django/accepts')
def an_ordinary_view(request):
...


@url('/you/can/stack/routing')
@url('/any/regex/django/accepts')
def an_ordinary_view(request):
...


Just declare your routing in the view. And use your view file in `URL_ROOT` or any `include()` like you would do with `urls.py`.

Just remember, the order you declare you routing matters as much as it does in urls.py.


View decorators
===============

Rendering template and json bore you to death ? Just say the word:


from django_quicky import view

@view(render_to='template.html')
def an_ordinary_view(request):
return {'stuff': stuff}


@view(render_to='json')
def an_json_view(request):
return {'stuff': stuff}


For the first one, the returned dictionary will be used as a context to render the template. For the second one, it will be serialised to JSON.

Conditional rendering
=======================

Because I know you like dirty talking and big words...

You can also declare alternative rendering:


from django_quicky import view

@view(render_to='template.html')
def common_views(request):
return {'stuff': stuff}

@common_views.post()
def post_view(request, context):
# do more stuff
return context

@common_views.ajax(render_to='json')
def json_view(request, context):
return context

The first view will be rendered as-is if it receives a normal GET request. The second vew will be rendered only for POST requests, but will be passed the result of the first view before. The second vew will be rendered only for AJAX requests, and as JSON, but will be passed the result of the first view before.

Just remember that alternative views must accept `context` as a parameter, because they will always receive the result of the main view.

Oh, and of you can define your own conditions:


@view(render_to='template.html')
def common_views(request):
return {'stuff': stuff}

@common_views.render_if(conditon=a_function_that_returns_a_bool)
def conditional_view(request, context):
# do more stuff
return context

Project details


Release history Release notifications

History Node

0.7.2

History Node

0.7.1

History Node

0.7

History Node

0.6.4

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6

History Node

0.5.2

History Node

0.5.1

History Node

0.5

History Node

0.4.7

History Node

0.4.6

History Node

0.4.5

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4

History Node

0.3.2

This version
History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-quicky-0.1.tar.gz (4.9 kB) Copy SHA256 hash SHA256 Source None Oct 8, 2012
django-quicky-0.2.tar.gz (5.7 kB) Copy SHA256 hash SHA256 Source None Oct 9, 2012
django-quicky-0.3.1.tar.gz (6.4 kB) Copy SHA256 hash SHA256 Source None Oct 10, 2012

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page