How do I display notifications from `django-notification`?
Asked Answered
G

2

8

I've been reading the docs for django-notification, and they seem to cover creating notifications just fine, but not how to display them to users. Is there a good reference for this out there, and my Google-fu has just failed me? If not, can someone give me some pointers here? Thanks.

Gutow answered 22/10, 2009 at 20:31 Comment(0)
G
4

The answer is you have to build it into your own templates. This can be as simple as the following snippet:

<table>
    <caption>{% trans "Notices" %}</caption> 
    <thead>
        <tr>
            <th>{% trans "Type" %}</th>
            <th>{% trans "Message" %}</th>
            <th>{% trans "Date of the Notice" %}</th>
        </tr>
    </thead>
    <tbody>
        {% for notice in notices %}
            {% if notice.is_unseen %}
                <tr class="unseen_notice">
            {% else %}
                <tr class="notice">
            {% endif %}
                <td class="notice_type">[{% trans notice.notice_type.display %}]</td>
                <td class="notice_message">{{ notice.message|safe }}</td>
                <td class="notice_time">{{ notice.added|timesince }} {% trans "ago" %}</td>
            </tr>
        {% endfor %}
    </tbody>
</table>

As @googletorp answered, Pinax is the goto place for figuring out how the authors are using django-notification. In particular, there is a notification administration page that can serve as a handy guide.

Gutow answered 23/12, 2009 at 15:58 Comment(7)
It took me a trip to code to see that notice.is_unseen call marks the message as seen. Just wanted to mention...Abednego
Incidentally, can you show us your context processor that leads to sets the "notices" variable? I am trying to look through their API but they don't provide anything like that.Recede
@disappearedng It's been a while, but I believe the only context processor I was using is notification.context_processors.notification, which is provided by django-notification itself. The example above is the template for the notices view that django-notification defines; that should be the notification/notices.html template. See github.com/pinax/django-notification/blob/master/notification/… for more.Gutow
@828 It's been a while, but I seem to recall that it gets marked as read just by being displayed on the screen, similar to email. I don't remember if there is a "Mark as Unread" sort of functionality, though.Gutow
where can we find the settings needed for it to work ? there is no settings file on githubUnruffled
seems like its no longer saving notice specifically with the newer version, and pickle the whole message when you use queue. Any idea whats the solution to display the individual notifications on sign-in?Inkberry
@Inkberry Sorry, I haven't used Django or this app in over a year.Gutow
H
2

Tale a look at Pinax the source can be found on github. They use notifications a lot for their project site http://code.pinaxproject.com .

Edit:
I just gave it a look. It seems all that Pinax does to make it work is to list it in installed apps before any the other external apps and include it's urls file like you usually would do.

Honebein answered 22/10, 2009 at 20:37 Comment(1)
I've been digging through the Pinax source for a while, and it actually seems to rely on templates that aren't part of django-notification (I believe notification/notices.html is one such example). I was hoping for a Getting Started-style tutorial that would explain how the different pieces fit together.Gutow

© 2022 - 2024 — McMap. All rights reserved.