Snippet List
This is a light-weight flash implementation. Instead of hitting the database it uses cookies. The messages are shown to the user only once, after that the cookies are deleted.
I tested it on Google App Engine, but it should work on vanilla Django as well, there's no GAE specific code.
To set up, add `"path.to.flash.Middleware"` to the `MIDDLEWARE_CLASSES` list.
Also add `'path.to.flash.context_processor'` to the `TEMPLATE_CONTEXT_PROCESSORS` list.
In your views, import and call `flash_error(msg)` and `flash_notice(msg)` passing the message that you want to show.
In your base template use this mark up:
{% if flash.notice %}
<div id="flash_notice">
<p>{{ flash.notice }}</p>
</div>
{% endif %}
{% if flash.error %}
<div id="flash_error">
<p>{{ flash.error }}</p>
</div>
{% endif %}
And finally, add this to your CSS file changing colours as necessary:
#flash_error {
margin-top: 30px;
padding: 20px;
background-color: #FFCCCC;
border: solid 1px #CC0000;
}
#flash_notice {
margin-top: 30px;
padding: 20px;
background-color: #CCFFCC;
border: solid 1px #00CC00;
}
#flash_error p, #flash_notice p {
margin: 0px;
}
Please comment if you notice any FUs. I'm new to Django and will appreciate any feedback.
- error
- flash
- rails
- notification
- notice
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
Middleware for communicating with Flash Player via Flashticle and Django.
Setup a view at /gateway/math/multiply like so:
def multiply(request, m1, m2):
return m1 * m2
Then in your Flex/Flash app you call "math.multiply" on a NetConnection pointing to http://domain.com/gateway/
Does not yet support authentication.
This is an extendend version of the Rails Flash implementation by Sean Patrick Hogan that supports different message types.
**Setting a flash message:**
request.flash.error = 'Item could not be saved'
request.flash['error'] = 'Item could not be saved'
request.flash['foo'] = 'bar'
**Displaying a flash in the view:**
<!-- show the error message -->
{% if flash.error %}An error occured:{{ flash.error }}{% endif %}
<!-- just show the first message found -->
{% if flash %}An error occured:{{ flash }}{% endif %}
<!-- show all messages -->
{% for msg in flash %}{{ msg.type }}: {{ msg.msg }}{% endfor %}
Note that it still works with simple strings as well. Feel free to just use it like this:
request.flash = "Message"
And:
{% if flash %}{{ flash }}{% endif %}
However, be aware that once you did this, you destroyed the Flash() dict and thus lost the extended functionality.
You can use request.flash.clear() to remove all messages.
Flash message add-on for Django. Uses sessions. Behavior is such that you set a flash message in a view. That message is stored in the sesssion. Then whenever it is that the message gets displayed, it is removed from the session (never to be heard from again)
**Installation:**
In your settings, enable the following items.
TEMPLATE_CONTEXT_PROCESSORS
django.core.context_processors.request
MIDDLEWARE_CLASSES
django.contrib.sessions.middleware.SessionMiddleware
Then put it into a file called flash.py in your templatetags directory.
**Usage:**
It's pretty simple. Do something like this in your view ..
>>>request.session['flash_msg'] = 'Your changes have been save'
>>>request.session['flash_params'] = {'type': 'success'}
And maybe put something like this in your template
{% load flash %}
{% flash %}
<h2>{{ params.type }}</h2>
{{ msg }}
{% endflash %}
It also support a flash template, you can specify a file
FLASH_TEMPLATE in your settings file and then that file will be rendered with msg and params as available variable.
Usage for this would simply be `{% flash_template %}` and then you gotta make a template file that does whatever you like.
Outside of that just be aware you need the Django session middleware and request context installed in your app to use this.
5 snippets posted so far.