Commit 958feca [frontend] fix flash messages not disappearing after page reload

3 files Authored and Committed by dturecek 3 months ago
[frontend] fix flash messages not disappearing after page reload

    
 1 @@ -79,11 +79,19 @@
 2       <div class="container">
 3   
 4         <!-- Flash messages -->
 5 -       {% with messages = get_flashed_messages(with_categories=true) %}
 6 -         {% for type, message in messages %}
 7 +       {% if flashes %}
 8 +         {% for type, message in flashes %}
 9             {{ alert(message, type) }}
10           {% endfor %}
11 -       {% endwith %}
12 +       {% else %}
13 +         {% with messages = get_flashed_messages(with_categories=true) %}
14 +           {% for type, message in messages %}
15 +             {{ alert(message, type) }}
16 +           {% endfor %}
17 +         {% endwith %}
18 +       {% endif %}
19 + 
20 + 
21   
22         <!-- the actual content -->
23         {% block body %}{% endblock %}
 1 @@ -63,11 +63,17 @@
 2   
 3   
 4   def render_copr_builds(copr):
 5 +     flashes = flask.session.pop('_flashes', [])
 6       builds_query = builds_logic.BuildsLogic.get_copr_builds_list(copr=copr)
 7 -     return flask.Response(stream_with_context(helpers.stream_template("coprs/detail/builds.html",
 8 +     response = flask.Response(stream_with_context(helpers.stream_template("coprs/detail/builds.html",
 9                                    copr=copr,
10 -                                  builds=list(builds_query))))
11 +                                  builds=list(builds_query),
12 +                                  flashes=flashes,
13 +                                  )))
14   
15 +     flask.session.pop('_flashes', [])
16 +     app.save_session(flask.session, response)
17 +     return response
18   
19   ################################ Url builds ################################
20   
 1 @@ -3,6 +3,7 @@
 2   
 3   from flask import Response, stream_with_context, url_for
 4   from flask import send_file
 5 + from coprs import app
 6   from coprs import db
 7   from coprs import forms
 8   from coprs import helpers
 9 @@ -20,10 +21,17 @@
10   @coprs_ns.route("/g/<group_name>/<coprname>/packages/")
11   @req_with_copr
12   def copr_packages(copr):
13 +     flashes = flask.session.pop('_flashes', [])
14       packages_query = PackagesLogic.get_copr_packages_list(copr)
15 -     return flask.Response(stream_with_context(helpers.stream_template("coprs/detail/packages.html",
16 +     response = flask.Response(stream_with_context(helpers.stream_template("coprs/detail/packages.html",
17                                    copr=copr,
18 -                                  packages=list(packages_query))))
19 +                                  packages=list(packages_query),
20 +                                  flashes=flashes,
21 +                                  )))
22 + 
23 +     flask.session.pop('_flashes', [])
24 +     app.save_session(flask.session, response)
25 +     return response
26   
27   @coprs_ns.route("/<username>/<coprname>/package/<package_name>/")
28   @coprs_ns.route("/g/<group_name>/<coprname>/package/<package_name>/")