Login

Snippets by tclineks

Snippet List

Notifications Middleware for Session-Backed Messages

simple middleware and context processor for session-based messaging with types Heavily inspired by patches on ticket 4604. Differs in that in this a notification has type. Installation: * add notifications.NotificationMiddleware to MIDDLEWARE_CLASSES * and notifications.notifications to TEMPLATE_CONTEXT_PROCESSORS That assumes notifications.py is on pythonpath. If notifications.py lives in your project dir, prefix those with '(projectname).' Example use: * request.notifications.create('Some bland information message.') * request.notifications.create('Some more exciting error message.', 'error') Example template code: `{% if notifications %} <ul id="notifications"> {% for notification in notifications %}<li class="{{ notification.type }}">{{ notification.content }}</li> {% endfor %} </ul> {% endif %}` [rendered example](http://traviscline.com/blog/2008/08/23/django-middleware-session-backed-messaging/)

  • middleware
  • flash
  • notifications
Read More

quick_url filter

A simple filter that generates a url from an object that has a get_absolute_url method. {{ object|quick_url }} a previous, simpler approach: [#511](http://www.djangosnippets.org/snippets/511/)

  • filter
  • get_absolute_url
  • quick_url
Read More

Simple View Middleware to allow a Prefilter

This allows you to define a 'prefilter' function in your view modules which will be invoked before any view in that same. This provides an easy place to decorate the request or modify arguments. For simplicity it doesn't allow configuration of the name of the prefilter function. I also skipped recursing into parent modules since that's somewhat edgecase.

  • middleware
  • process_view
  • prefilter
  • beforefilter
Read More

tclineks has posted 3 snippets.