Compare commits

...

3 commits

Author SHA1 Message Date
Edward Betts 08a4ffa89f Web UI to edit conference title
Resolves: #3
2023-09-25 13:05:12 +01:00
Edward Betts b36ff3a9c1 Reorder people on Github Wikidata report. 2023-09-25 12:58:28 +01:00
Edward Betts cc32b0459d Add admin mode 2023-09-24 22:19:09 +01:00
4 changed files with 72 additions and 5 deletions

44
main.py
View file

@ -59,7 +59,7 @@ def drop_start(s: str, start: str) -> str:
@app.route("/person/<int:person_id>", methods=["GET", "POST"])
def person(person_id: int) -> str | Response:
item = model.Person.query.get(person_id)
if flask.request.method == "POST":
if flask.request.method == "POST" and check_admin_mode():
qid = flask.request.form["wikidata_qid"] or None
item.name = flask.request.form["name"]
@ -115,6 +115,7 @@ def person(person_id: int) -> str | Response:
Event=model.Event,
plural=plural,
wikidata_hits=wikidata_hits,
is_admin=check_admin_mode,
)
@ -124,13 +125,27 @@ def event_page(event_id: int) -> str:
return flask.render_template("event.html", item=item)
@app.route("/conference/<short_name>")
def conference_page(short_name: str) -> str:
@app.route("/conference/<short_name>", methods=["GET", "POST"])
def conference_page(short_name: str) -> str | Response:
item = model.Conference.query.filter_by(short_name=short_name).one_or_none()
if item is None:
flask.abort(404)
if flask.request.method == "POST" and check_admin_mode():
item.short_name = flask.request.form["short_name"]
item.title = flask.request.form["title"]
database.session.commit()
assert flask.request.endpoint
return flask.redirect(
flask.url_for(flask.request.endpoint, short_name=item.short_name)
)
return flask.render_template(
"conference.html", item=item, person_image_filename=person_image_filename
"conference.html",
item=item,
person_image_filename=person_image_filename,
is_admin=check_admin_mode,
)
@ -405,6 +420,25 @@ def person_image_filename(person_id: int) -> str:
return os.path.join("wikidata_photo", "thumb", person.wikidata_photo[0])
@app.route("/login", methods=["GET", "POST"])
def login() -> str | Response:
"""Login page."""
if flask.request.method == "GET":
return flask.render_template("login.html")
password = flask.request.form["password"]
if password != app.config["ADMIN_PASSWORD"]:
endpoint = flask.endpoint
return flask.redirect(endpoint)
flask.session["admin_password"] = password
return flask.redirect(flask.url_for("index"))
def check_admin_mode() -> bool:
"""User is an admin."""
return bool(flask.session.get("admin_password") == app.config["ADMIN_PASSWORD"])
@app.route("/github_wikidata")
def github_wikidata() -> str:
"""Look for speakers on Wikidata based on the GitHub property."""
@ -416,6 +450,8 @@ def github_wikidata() -> str:
continue
items.append((person, qid, wd_name, photo))
items.sort(key=lambda i: len(i[0].name))
return flask.render_template("github.html", items=items)

View file

@ -86,6 +86,21 @@
</div>
</div>
{% if is_admin() %}
<form method="POST">
<div>
<label for="title">title</label>
<input type="text" name="title" id="title" value="{{ item.title }}">
</div>
<div>
<label for="short_name">short name</label>
<input type="text" name="short_name" id="short_name" value="{{ item.short_name }}">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
{% endif %}
<h3>Talks</h3>
<p>{{ item.events.count() }} talks</p>

16
templates/login.html Normal file
View file

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Conference archive{% endblock %}
{% block content %}
<h1>Conference archive</h1>
<div>Admin login.</div>
<form method="POST">
<label for="password">Password:</label>
<input type="password" id="password" name="password"/>
<button>login</button>
</form>
{% endblock %}

View file

@ -45,7 +45,7 @@
{% endif %}
</p>
{% if config.ADMIN_MODE %}
{% if is_admin() %}
{% set search_for = item.name + ' ' + " haswbstatement:P31=Q5" %}
<p><a href="https://www.wikidata.org/w/index.php?search={{ search_for | urlencode }}&title=Special%3ASearch&ns0=1&ns120=1">Search for {{ item.name }} on Wikidata</a></p>