Skip to content

Commit

Permalink
messages: clean up messages and errors containers
Browse files Browse the repository at this point in the history
Refactor the messages container to make use of message.tags [1] which
allows for more customization for each level (e.g. success, warning,
error, etc.) of a message through CSS selectors. As basic proof of
concept, customize the text color of each existing message level. Also,
this addition resolves a TODO by stephenfin in the previous code.

Move the errors container after the messages container in the DOM in the
base.html template so that every template can share the same errors
container. Also, add a background color to the errors container so that
both containers blend in as a uniform block. Add bullet points to each
error item in the list of errors.

Change both the messages and errors containers to always exist in
the DOM. With this, the addition of update and error messages is simpler
because it eliminates the need to create the containers if they don't
exist. These changes will be useful in a following patch that introduces
an internal JS module to make client-side requests to the REST API.

[1] https://docs.djangoproject.com/en/3.2/ref/contrib/messages/#message-tags

Signed-off-by: Raxel Gutierrez <raxel@google.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
[dja: converted HTML comment to django template comment, thanks sfin]
Signed-off-by: Daniel Axtens <dja@axtens.net>
  • Loading branch information
raxelg authored and daxtens committed Aug 19, 2021
1 parent 17c08ab commit 5de787c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
43 changes: 33 additions & 10 deletions htdocs/css/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
:root {
--success-color:rgb(92, 184, 92);
--warning-color:rgb(240, 173, 78);
--danger-color:rgb(217, 83, 79);
}

h2 {
font-size: 25px;
margin: 18px 0 18px 0;
Expand Down Expand Up @@ -78,14 +84,27 @@ dl dt {
}

/* messages */
#messages {
.messages {
background: #e0e0f0;
margin: 0.5em 1em 0.0em 0.5em;
margin: 0.5em 1em 0.0em 1em;
padding: 0.3em;
list-style-type: none;
}

.messages:empty {
display: none;
}

.messages .success {
color: var(--success-color);
}

.messages .warning {
color: var(--warning-color);
}

#messages .message {
color: green;
.messages .error {
color: var(--danger-color);
}

.filters {
Expand Down Expand Up @@ -421,13 +440,17 @@ table.loginform {
}

/* form errors */
.errorlist {
color: red;
list-style-type: none;
padding-left: 0.2em;
margin: 0em;
#errors {
background: #e0e0f0;
margin: 0em 1em 0.5em 1em;
padding: 0.3em;
}
.error {

#errors:empty {
display: none;
}

.error-list, .errorlist {
color: red;
}

Expand Down
10 changes: 0 additions & 10 deletions patchwork/templates/patchwork/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@

{% block body %}

{% if errors %}
<p>The following error{{ errors|length|pluralize:" was,s were" }} encountered
while updating patches:</p>
<ul class="errorlist">
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}

{% include "patchwork/partials/patch-list.html" %}

{% endblock %}
5 changes: 1 addition & 4 deletions patchwork/templates/patchwork/user-link-confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@

{% block body %}

{% if errors %}
<p>{{ errors }}</p>
{% else %}
{% if not errors %}
<p>You have successfully linked the email address {{ person.email }} to
your Patchwork account</p>

{% endif %}
<p>Back to <a href="{% url 'user-profile' %}">your
profile</a>.</p>
Expand Down
4 changes: 2 additions & 2 deletions patchwork/templates/patchwork/user-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
on the link provided in the email to confirm that this address belongs to
you.</p>
{% else %}
<p>There was an error submitting your link request:</p>
{% if form.errors %}
<p>There was an error submitting your link request.</p>
{{ form.non_field_errors }}
{% endif %}
{% if error %}
<ul class="errorlist"><li>{{error}}</li></ul>
<ul class="error-list"><li>{{error}}</li></ul>
{% endif %}

<form action="{% url 'user-link' %}" method="post">
Expand Down
29 changes: 21 additions & 8 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,28 @@
</div>
</div>
</nav>
{% if messages %}
<div id="messages">
{% for message in messages %}
{# TODO(stephenfin): Make use of message.tags when completely #}
{# converted to django.contrib.messages #}
<div class="message">{{ message }}</div>
{% endfor %}
{% comment %}
spaceless tag is used to remove automatically added whitespace so that the container
is truly considered empty by the `:empty` pseudo-class that is used for styling
{% endcomment %}{% spaceless %}
<ul class="messages">
{% if messages %}
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
{% endif %}
</ul>
<div id="errors">
{% if errors %}
<p>The following error{{ errors|length|pluralize:" was,s were" }} encountered:</p>
<ul class="error-list">
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endif %}
{% endspaceless %}
<div id="main-content" class="container-fluid">
{% block body %}
{% endblock %}
Expand Down

0 comments on commit 5de787c

Please sign in to comment.