Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A few models and a context processor for working with global and direct to user messages
Python
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bulletins
example
README.mkd
manage.py
requirements.txt
setup.py

README.mkd

django-bulletins

The contents of this django app are a few simple models for handling global and direct to user bulletins (a bulletin is a message of some kind) and a simple context processor to add these global and direct to user bulletins to the template context. This implementation of bulletins is kept simple to encourage extending it for your own purposes. One example of this could be the case of working in teams where you want organization and team level bulletins.

Installation

First, install the python module using pip:

$ pip install -e git+git@github.com:t3hh00d/django-bulletins.git#egg=bulletins

Second, install the app in your django settings file:

INSTALLED_APPS = {
    ...
    'bulletins',
}

Finally, install the context processor, note that you may need to add TEMPLATE_CONTEXT_PROCESSORS to the django settings yourself:

TEMPLATE_CONTEXT_PROCESSORS = (
    ...
    'bulletins.context_processors.bulletins',
)

Usage

There are two ways to use the bulletins app. Either you're using the resulting context data in the templates or you're creating bulletins from within your own applications.

Creating Bulletins

Provided that you have two user objects userA and userB created and available you can create bulletins in this way:

from bulletins.models import DirectBulletin, GlobalBulletin

global = GlobalBulletin.objects.create_bulletin(
    message='Something to let all of your users know should go here.',
    creator=userA
)

direct = DirectBulletin.objects.create_bulletin(
    message='Something to let a specific user know should go here.',
    creator=userA,
    recipient=userB
)

Marking Bulletins as Read

This is simple enough, but I wanted to document it here. Note that the global and direct bulletin models themselves don't have the mark_as_read() method. Only the core bulletin model has it.

global_bulletin.bulletin.mark_read()
direct_bulletin.bulletin.mark_read()

Bulletins in Context

With bulletins properly installed you will have new context variables in your templates. Global bulletins can be accessed in this way:

{% for bulletin in bulletins.global %}
    {{ bulletin.bulletin.creator }}
    {{ bulletin.bulletin.created_at }}
    {{ bulletin.bulletin.message }}
    {% if bulletin.bulletin.has_been_read %}
        {{ bulletin.bulletin.read_at }}
    {% endif %}
{% endfor %}

Direct bulletins can be accessed in a similar way. Note that direct bulletin objects have a property in addition to "bulletin", it is "recipient":

{% for bulletin in bulletins.direct %}
    {{ bulletin.recipient }}
    {{ bulletin.bulletin.creator }}
    {{ bulletin.bulletin.created_at }}
    {{ bulletin.bulletin.message }}
    {% if bulletin.bulletin.has_been_read %}
        {{ bulletin.bulletin.read_at }}
    {% endif %}
{% endfor %}
Something went wrong with that request. Please try again.