Login

Tag "shortcut"

Snippet List

Shortcuts to your code organized by type (views, models, admin, ...)

Sometimes, when you're working on improving one specific aspect of your site, it's easier to browse your code by type than by application. E.g. you want quick access to all admin.py files because you're improving or customizing your admin site across the board and not for a specific app. This little management command adds a shortcuts dir to your project root that contains a bunch of symlinks to your code, organized in subdirs by type of code. You'll have to put this in `/management/commands/make_shortcuts.py` under an app of your choice. Usage: `python manage.py make_shortcuts`. Don't forget to ignore the /shortcuts directory in your source code management software.

  • shortcut
  • utility
  • organization
Read More

default url routing and shortcut

from url_helper import execute, url_ import views urlpatterns += patterns('', url(r'^(?P<urls>.*)', execute, {'views': views}), ) url_(r’/space/:username/:tag/’, views.url_), equal url(r’^space/(?P[^/]+)/(?P[^/]+)/$’,

  • shortcut
  • url
Read More

render_to

Decorator, written for views simplification. Will render dict, returned by view, as context for template, using RequestContext. Additionally you can override template, returning two-tuple (context's dict and template name) instead of just dict. Usage: @render_to('my/template.html') def my_view(request, param): if param == 'something': return {'data': 'some_data'} else: return {'data': 'some_other_data'}, 'another/template.html'

  • render_to_response
  • requestcontext
  • shortcut
  • decorator
  • rendering
Read More

get_queryset_or_404

Sometimes we want to get a queryset or 404, for example, if we're passing our queryset to a subclassed generic view. This is identical to get_list_or_404 but returns a queryset.

  • shortcut
  • template
  • queryset
  • get_queryset_or_404
  • get_list_or_404
Read More

Renderer decorator

You can use this as a decorator for your views, this way you can return a simple dictionary and the decorator will do the rest. **@TODO:** Automatically set the template based on the app/view request

  • shortcut
  • render
Read More

render_to_response wrapper

Simplifies using RequestContext in render_to_response. Simply call the wrapper with request as the first argument, and the rest of the arguments are as normal for render_to_response. ex: render_response(request, 'foo_list.html', {'foo': Foo.objects.all()})

  • render_to_response
  • requestcontext
  • shortcut
  • template
Read More

9 snippets posted so far.