Compare commits

..

No commits in common. "08a4ffa89f2b144c8c12a46fd61f1083fd9977a5" and "0ccaebe4181724e183f440a0a54fc272fde9513b" have entirely different histories.

4 changed files with 5 additions and 72 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"]) @app.route("/person/<int:person_id>", methods=["GET", "POST"])
def person(person_id: int) -> str | Response: def person(person_id: int) -> str | Response:
item = model.Person.query.get(person_id) item = model.Person.query.get(person_id)
if flask.request.method == "POST" and check_admin_mode(): if flask.request.method == "POST":
qid = flask.request.form["wikidata_qid"] or None qid = flask.request.form["wikidata_qid"] or None
item.name = flask.request.form["name"] item.name = flask.request.form["name"]
@ -115,7 +115,6 @@ def person(person_id: int) -> str | Response:
Event=model.Event, Event=model.Event,
plural=plural, plural=plural,
wikidata_hits=wikidata_hits, wikidata_hits=wikidata_hits,
is_admin=check_admin_mode,
) )
@ -125,27 +124,13 @@ def event_page(event_id: int) -> str:
return flask.render_template("event.html", item=item) return flask.render_template("event.html", item=item)
@app.route("/conference/<short_name>", methods=["GET", "POST"]) @app.route("/conference/<short_name>")
def conference_page(short_name: str) -> str | Response: def conference_page(short_name: str) -> str:
item = model.Conference.query.filter_by(short_name=short_name).one_or_none() item = model.Conference.query.filter_by(short_name=short_name).one_or_none()
if item is None: if item is None:
flask.abort(404) 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( return flask.render_template(
"conference.html", "conference.html", item=item, person_image_filename=person_image_filename
item=item,
person_image_filename=person_image_filename,
is_admin=check_admin_mode,
) )
@ -420,25 +405,6 @@ def person_image_filename(person_id: int) -> str:
return os.path.join("wikidata_photo", "thumb", person.wikidata_photo[0]) 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") @app.route("/github_wikidata")
def github_wikidata() -> str: def github_wikidata() -> str:
"""Look for speakers on Wikidata based on the GitHub property.""" """Look for speakers on Wikidata based on the GitHub property."""
@ -450,8 +416,6 @@ def github_wikidata() -> str:
continue continue
items.append((person, qid, wd_name, photo)) items.append((person, qid, wd_name, photo))
items.sort(key=lambda i: len(i[0].name))
return flask.render_template("github.html", items=items) return flask.render_template("github.html", items=items)

View file

@ -86,21 +86,6 @@
</div> </div>
</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> <h3>Talks</h3>
<p>{{ item.events.count() }} talks</p> <p>{{ item.events.count() }} talks</p>

View file

@ -1,16 +0,0 @@
{% 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 %} {% endif %}
</p> </p>
{% if is_admin() %} {% if config.ADMIN_MODE %}
{% set search_for = item.name + ' ' + " haswbstatement:P31=Q5" %} {% 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> <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>