Skip to content

Commit

Permalink
Configure Django messages framework
Browse files Browse the repository at this point in the history
Use cookie storage and match Bootstrap classes.
  • Loading branch information
jraddaoui committed Jul 30, 2018
1 parent 834c921 commit f8ad326
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions accesspoc/accesspoc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
from django.contrib.messages import constants as messages
from django.utils.translation import gettext_lazy as _

from envparse import env
Expand Down Expand Up @@ -141,6 +142,16 @@

USE_TZ = True

# Messages

# Force cookie storage to reduce the possibility of looking the database
# when using SessionStorage, which saves the data in the database by default.
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'

This comment has been minimized.

Copy link
@sevein

sevein Jul 30, 2018

Collaborator

Perhaps a better option would be to set up the cache engine (in-memory or redis) which can be used for multiple things including becoming the session engine: SESSION_ENGINE.

This comment has been minimized.

Copy link
@jraddaoui

jraddaoui Jul 30, 2018

Author Collaborator

#75

# Fix mismatch with Bootstrap alert classes
MESSAGE_TAGS = {
messages.DEBUG: 'secondary',
messages.ERROR: 'danger',
}

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
Expand Down
10 changes: 10 additions & 0 deletions accesspoc/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@
</div>
</nav>
<div class="main m-4">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.level_tag }} alert-dismissible fade show" role="alert">
{{ message|safe }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}
{% endif %}
{% block content %}
{% endblock %}
</div>
Expand Down

0 comments on commit f8ad326

Please sign in to comment.