Web UI to edit conference title

Resolves: #3
This commit is contained in:
Edward Betts 2023-09-25 13:05:12 +01:00
parent b36ff3a9c1
commit 08a4ffa89f
2 changed files with 32 additions and 3 deletions

20
main.py
View file

@ -125,13 +125,27 @@ 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>") @app.route("/conference/<short_name>", methods=["GET", "POST"])
def conference_page(short_name: str) -> str: def conference_page(short_name: str) -> str | Response:
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", item=item, person_image_filename=person_image_filename "conference.html",
item=item,
person_image_filename=person_image_filename,
is_admin=check_admin_mode,
) )

View file

@ -86,6 +86,21 @@
</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>