skip to navigation
skip to content

Not Logged In

django-quicky 0.1

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

Package Documentation

Latest Version: 0.6.4

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
 
File Type Py Version Uploaded on Size
django-quicky-0.1.tar.gz (md5) Source 2012-10-08 4KB
django-quicky-0.2.tar.gz (md5) Source 2012-10-09 5KB
django-quicky-0.3.1.tar.gz (md5) Source 2012-10-10 6KB
  • Downloads (All Versions):
  • 135 downloads in the last day
  • 368 downloads in the last week
  • 1534 downloads in the last month