0

About the messaging framework, in the docs it is written that every message has a message.tag property that can be uses for css. so my code looks like this

try:
    models.save()
    message.success(request, "Model successfully saved")
except DatabaseManagementTransaction:
    message.error(request, "Model could not be saved")

in my html template

{% if messages %}
    {% for message in messages %}
        <div class="alert alert-{{message.tag}} alert-dissmissable">
            {{message}}
        </div>
    {%endfor%}
{% endif %}

But when the template is rendered i see no message.tag and the div class looks like this

<div class="alert alert- alert-dissmissable">...</div>

So do i have to create MESSAGE_TAGS in settings file for this to work? Why is the message.tag empty? And another question. What happens to messages after they are presented to user? Are they deleted? If i add a new model will the previous messages be shown to me plus the newly appended one?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Apostolos
  • 7,763
  • 17
  • 80
  • 150

1 Answers1

2

If should be tags as alert-{{message.tags}} in the template.

What happens to messages after they are presented to user? Are they deleted?

Yes, they are cleared once iterated (or displayed through template) from the storage. Refer message expiry.

If i add a new model will the previous messages be shown to me plus the newly appended one?

The messages list will have all currently active messages. So if previous message is still there it will be shown as well.

Rohan
  • 52,392
  • 12
  • 90
  • 87
  • One extra question: Is this the right exception i am checking?How can I make my Db fail :) to test it? I am not familiar with unit testing yet. – Apostolos Nov 11 '13 at 12:44
  • @Apostolos, stop the db service, but timing needs to be right. May be you can add for other errors like data base integrity error (add object with existing primary key or other unique field) etc. – Rohan Nov 11 '13 at 12:52
  • I see thanks for answering. And one last question. Can i make my messages or some messages accessible to all clients? Or maybe to clients with specific users connected?(Like fb notif etc) – Apostolos Nov 11 '13 at 12:56
  • @Apostolos, may be by adding extra attributes in messages. – Rohan Nov 11 '13 at 13:01
  • Thank you again rohan....Any tutorials available?Or how i should look for it my self? – Apostolos Nov 11 '13 at 13:39