From af063838d1013b25ec5e4089ffa87a7030cfdc34 Mon Sep 17 00:00:00 2001 From: kaiyou <pierre@jaury.eu> Date: Sun, 20 Oct 2019 20:30:32 +0200 Subject: [PATCH] Have more flexible help messages --- hiboo/templates/base.html | 23 ++--------------------- hiboo/templates/macros.html | 19 +++++++++++++++++++ hiboo/utils.py | 9 ++++----- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/hiboo/templates/base.html b/hiboo/templates/base.html index c9123b1..ed47229 100644 --- a/hiboo/templates/base.html +++ b/hiboo/templates/base.html @@ -24,7 +24,7 @@ {% if current_user.is_authenticated %} <li class="dropdown user"> <a class="dropdown-toggle"> - {% trans %}Logged in as{% endtrans %} <strong>{{ current_user.username }}</strong> + <i class="fa fa-user"></i>{{ current_user.username }} </a> </li> <li class="dropdown user"> @@ -42,7 +42,7 @@ </li> {% endif %} <li class="dropdown user"> - <a class="dropdown-toggle" data-toggle="modal" data-target="#help_modal"> + <a class="dropdown-toggle" data-toggle="modal" data-target="#help_main"> <i class="fa fa-life-ring"></i> {% trans %}Help{% endtrans %} </a> @@ -77,25 +77,6 @@ <div class="alert alert-{{ category or "info" }}">{{ message }}</div> {% endfor %} {% block content %}{% endblock %} - <div class="{{ "automodal" if utils.display_help() else "" }} modal fade" id="help_modal" tabindex="-1" role="dialog" aria-labelledby="help_modal_label" aria-hidden="true"> - <div class="modal-dialog" role="document"> - <div class="modal-content"> - <div class="modal-header"> - <h4 class="modal-title" id="help_modal_label">{% block help_title %}{% trans %}No help message{% endtrans %}{% endblock %}</h4> - </div> - <div class="modal-body"> - {% block help_body %} - <p>{% trans %}No help message is available for this part of Hiboo, sorry!{% endtrans %}</p> - <p>{% trans %}If you wish to contribute help messages, please contact us.{% endtrans %}</p> - {% endblock %} - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans %}Close{% endtrans %}</button> - {% block help_buttons %}{% endblock %} - </div> - </div> - </div> - </div> </section> </div> diff --git a/hiboo/templates/macros.html b/hiboo/templates/macros.html index ea2370c..0a99a9d 100644 --- a/hiboo/templates/macros.html +++ b/hiboo/templates/macros.html @@ -37,6 +37,25 @@ </div> {% endmacro %} +{% macro help(title, id="main", buttons="", auto=False) %} +<div class="{{ "automodal" if auto else "" }} modal fade" id="help_{{ id }}" tabindex="-1" role="dialog" aria-labelledby="help_{{ id }}_label" aria-hidden="true"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h4 class="modal-title" id="help_{{ id }}_label">{{ title }}</h4> + </div> + <div class="modal-body"> + {{ caller() }} + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans %}Close{% endtrans %}</button> + {{ buttons }} + </div> + </div> + </div> +</div> +{% endmacro %} + {% macro form_fields(fields, prepend='', append='', label=True) %} {% set width = (12 / fields|length)|int %} <div class="form-group"> diff --git a/hiboo/utils.py b/hiboo/utils.py index 847b86e..56afd08 100644 --- a/hiboo/utils.py +++ b/hiboo/utils.py @@ -56,16 +56,15 @@ def force_redirect(destination): raise routing.RequestRedirect(destination) -def display_help(): +def display_help(identifier): """ Check if help messages should be displayed automatically """ - route = flask.request.url_rule.endpoint + route = flask.request.url_rule.endpoint + ":" + identifier seen = flask.session.get("help_seen", []) - if route not in DISPLAY_HELP or route in seen: - return False + result = route not in seen seen.append(route) flask.session["help_seen"] = seen - return True + return result # Request rate limitation -- GitLab