Skip to content

Commit

Permalink
Merge pull request #30 from N5GEH/29-general-way-to-display-error-mes…
Browse files Browse the repository at this point in the history
…sage

general way to display error/warning/success message
  • Loading branch information
djs0109 authored Sep 8, 2022
2 parents 8eb29da + b36f26d commit ff34cd2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/Entirety/entirety/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TemplateBackendModel,
)
from utils.generators import generate_secret_key

from django.contrib.messages import constants as messages
__version__ = "0.3.1"


Expand Down Expand Up @@ -78,6 +78,14 @@ class Settings(PydanticSettings):
"mozilla_django_oidc.middleware.SessionRefresh",
]

MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}

ROOT_URLCONF = "entirety.urls"
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
TEMPLATES: List[TemplateBackendModel] = [
Expand Down
7 changes: 7 additions & 0 deletions app/Entirety/examples/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.shortcuts import render, HttpResponse
from django.views.generic import View
from examples.forms import ExampleForm
from django.contrib import messages

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,5 +42,11 @@ def post(self, request):

class Dialog(View):
def get(self, request):
# add messages
messages.debug(request, 'DEBUG: send POST request to orion') # debug level msg will not be displayed
messages.info(request, 'INFO: please do something')
messages.success(request, 'SUCCESS: devices successfully created')
messages.warning(request, 'WARNING: service group not matched, errors may occur')
messages.error(request, 'ERROR: entity name is illegal')
context = {}
return render(request, "examples/dialog.html", context)
1 change: 1 addition & 0 deletions app/Entirety/templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<div class="container-fluid ps-0 d-flex">
{% include 'sidebar.html' %}
<main class="d-flex flex-column flex-fill ps-4 pe-3 py-3">
{% include 'messages.html' %}
{% block content %}(no content - should not be here) {% endblock %}
</main>
{% include 'modal.html' %}
Expand Down
9 changes: 9 additions & 0 deletions app/Entirety/templates/messages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% if messages %}
<ul class="messages">
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible" role="alert">
{{ message }}
</div>
{% endfor %}
</ul>
{% endif %}

0 comments on commit ff34cd2

Please sign in to comment.