diff --git a/hiboo/templates/base.html b/hiboo/templates/base.html index c9123b153423fd87b0150951dd73d053c80ed17a..ed472299e88e6b856acefa584967cfc24f1cd404 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 ea2370c4eb2e904836b3e708ebf02671ab9621b7..0a99a9db1b6548b022c4eccde968bd90860713d3 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 847b86ea7320c2ae326bfadd0ba533fde9b82222..56afd08803195cd1993bf5f8169c91e1554de656 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