Mercurial > wikked
changeset 424:1066d0986082
web: Add button to force refresh a cached page list.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 24 Mar 2017 16:46:37 -0700 |
parents | d2e5228194f0 |
children | e28f2c76691c |
files | wikked/assets/css/wikked/main.less wikked/templates/special-pagelist.html wikked/views/__init__.py wikked/views/special.py |
diffstat | 4 files changed, 57 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/wikked/assets/css/wikked/main.less Thu Mar 23 22:02:44 2017 -0700 +++ b/wikked/assets/css/wikked/main.less Fri Mar 24 16:46:37 2017 -0700 @@ -72,6 +72,10 @@ border-top: 1px solid @color-gray-medium; } +.pure-button-warning { + background: rgb(223, 117, 20); +} + @media (min-width: 48em) { // Place right-aligned menu items to, well, to the right. .pure-menu .pure-menu-horizontal-right { @@ -125,3 +129,6 @@ font-weight: bolder; } +.wiki-pagelist-refresh { + margin-top: 1em; +}
--- a/wikked/templates/special-pagelist.html Thu Mar 23 22:02:44 2017 -0700 +++ b/wikked/templates/special-pagelist.html Fri Mar 24 16:46:37 2017 -0700 @@ -16,6 +16,15 @@ {%else%} {%block empty%}{%endblock%} {%endif%} + {% if refresh %} + <div class="wiki-pagelist-refresh"> + <form action="{{refresh.url}}" method="POST" class="pure-form"> + <input type="hidden" name="list_name" value="{{refresh.list_name}}" /> + <input type="hidden" name="postback" value="{{refresh.postback}}" /> + <button name="do-refresh" type="submit" class="pure-button pure-button-warning"><span class="fa fa-refresh"></span> Force Refresh</button> + </form> + </div> + {% endif %} </section> </article> {% endblock %}
--- a/wikked/views/__init__.py Thu Mar 23 22:02:44 2017 -0700 +++ b/wikked/views/__init__.py Fri Mar 24 16:46:37 2017 -0700 @@ -44,14 +44,21 @@ return decorator +def requires_auth(group): + def decorator(f): + @functools.wraps(f) + def wrapper(*args, **kwargs): + wiki = get_wiki() + if not wiki.auth.hasPermission(group, current_user.get_id()): + return show_unauthorized_error() + return f(*args, **kwargs) + return wrapper + return decorator + + def requires_reader_auth(f): - @functools.wraps(f) - def wrapper(*args, **kwargs): - wiki = get_wiki() - if not wiki.auth.hasPermission('readers', current_user.get_id()): - return show_unauthorized_error() - return f(*args, **kwargs) - return wrapper + decorator = requires_auth('readers') + return decorator(f) def add_auth_data(data):
--- a/wikked/views/special.py Thu Mar 23 22:02:44 2017 -0700 +++ b/wikked/views/special.py Fri Mar 24 16:46:37 2017 -0700 @@ -1,7 +1,7 @@ -from flask import url_for, render_template +from flask import request, redirect, url_for, render_template, abort from flask.ext.login import current_user from wikked.views import ( - requires_reader_auth, + requires_auth, requires_reader_auth, add_auth_data, add_navigation_data) from wikked.web import app, get_wiki from wikked.webimpl.special import ( @@ -107,6 +107,11 @@ add_navigation_data(None, data, raw_url=raw_url) data['title'] = info['title'] data['is_special_page'] = True + data['refresh'] = { + 'url': url_for('special_list_refresh'), + 'list_name': page_name.replace('-', '_'), + 'postback': page_name + } return render_template(info['template'], **data) @@ -136,3 +141,23 @@ def special_list_dead_ends(): return call_api('dead-ends', get_dead_ends, raw_url='/api/dead-ends') + + +@app.route('/special/list-refresh', methods=['POST']) +@requires_auth('administrators') +def special_list_refresh(): + list_name = request.form.get('list_name') + postback_name = request.form.get('postback') + if not list_name: + abort(400) + + info = special_pages.get(postback_name) + if not info: + abort(400) + + postback_url = url_for(info['view']) + + wiki = get_wiki() + wiki.db.removePageList(list_name) + + return redirect(postback_url)