Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Don't show messages on AJAX requests

Roland Geideref20688ed57d
diff --git a/wger/manager/static/js/workout-manager.js b/wger/manager/static/js/workout-manager.js
index 565d8bc50..99131200f 100644
--- a/wger/manager/static/js/workout-manager.js
+++ b/wger/manager/static/js/workout-manager.js
@@ -214,7 +214,13 @@ function modal_dialog_form_edit()
type: "POST",
url: form_action,
data: form_data,
- success: function(data) {
+ beforeSend: function(jqXHR, settings){
+ // Send a custom header so django's messages are not displayed in the next
+ // request which will be not be displayed to the user, but on the next one
+ // that will
+ jqXHR.setRequestHeader("X-wger-no-messages", "1");
+ },
+ success: function(data, textStatus, jqXHR) {
if($(data).find('.ym-form .ym-error').length > 0)
{
// we must do the same with the new form as before, binding the click-event,
diff --git a/wger/manager/templates/base.html b/wger/manager/templates/base.html
index a075b537f..96c9bbf11 100644
--- a/wger/manager/templates/base.html
+++ b/wger/manager/templates/base.html
@@ -4,7 +4,7 @@
<article>
<div class="ym-g66 ym-gl content">
<div class="ym-gbox-left ym-clearfix" id="main-content">
- {% if messages %}
+ {% if messages and not no_messages %}
{% for message in messages %}
<div class="alert {% if message.tags == 'warning'%}alert-error{% elif message.tags == 'info' %}alert-info{% elif message.tags == 'success' %}alert-success{% endif %}">
<a href="#" class="close extra-bold" data-dismiss="alert">&times;</a>
diff --git a/wger/manager/templates/base_wide.html b/wger/manager/templates/base_wide.html
index 23c486a92..1d058e362 100644
--- a/wger/manager/templates/base_wide.html
+++ b/wger/manager/templates/base_wide.html
@@ -3,6 +3,14 @@
<h2 id="page-title">{% block title %}{% endblock %}</h2>
<article class="ym-grid ym-gl content">
<div class="ym-gbox-left ym-clearfix" id="main-content">
+ {% if messages and not no_messages %}
+ {% for message in messages %}
+ <div class="alert {% if message.tags == 'warning'%}alert-error{% elif message.tags == 'info' %}alert-info{% elif message.tags == 'success' %}alert-success{% endif %}">
+ <a href="#" class="close extra-bold" data-dismiss="alert">&times;</a>
+ {{message}}
+ </div>
+ {% endfor %}
+ {% endif %}
{% block content %}{% endblock %}
</div>
</article>
diff --git a/wger/utils/context_processor.py b/wger/utils/context_processor.py
index 97724390f..a1f6972fd 100644
--- a/wger/utils/context_processor.py
+++ b/wger/utils/context_processor.py
@@ -41,7 +41,10 @@ def processor(request):
'contact_email': 'roland @ geider.net',
# Flag for guest users
- 'has_demo_data': request.session.get('has_demo_data', False)
+ 'has_demo_data': request.session.get('has_demo_data', False),
+
+ # Don't show messages on AJAX requests (they are deleted if shown)
+ 'no_messages': request.META.get('HTTP_X_WGER_NO_MESSAGES', False),
}
# Pseudo-intelligent navigation here