Add country, city and venue.

This commit is contained in:
Edward Betts 2023-09-17 09:46:33 +05:30
parent a0df624f16
commit 301c389ba9
4 changed files with 134 additions and 1 deletions

View file

@ -41,6 +41,7 @@ class Conference(TimeStampedModel):
url = Column(String) url = Column(String)
schedule_xml_url = Column(String) schedule_xml_url = Column(String)
short_name = Column(String, unique=True) short_name = Column(String, unique=True)
venue_id = Column(Integer, ForeignKey("venue.id"))
people_detail = relationship( people_detail = relationship(
"ConferencePerson", lazy="dynamic", back_populates="conference" "ConferencePerson", lazy="dynamic", back_populates="conference"
@ -54,6 +55,46 @@ class Conference(TimeStampedModel):
lazy="dynamic", lazy="dynamic",
) )
venue = relationship("Venue", back_populates="conferences")
class City(TimeStampedModel):
"""City."""
__tablename__ = "city"
id = Column(Integer, primary_key=True)
slug = Column(String, nullable=False, unique=True)
name = Column(String, nullable=False)
country_code = Column(String, ForeignKey("country.alpha2"), nullable=False)
wikidata_qid = Column(String, nullable=False)
venues = relationship("Venue", back_populates="city")
country = relationship("Country", back_populates="cities")
class Venue(TimeStampedModel):
"""Venue."""
__tablename__ = "venue"
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
city_id = Column(Integer, ForeignKey("city.id"))
wikidata_qid = Column(String, nullable=False)
conferences = relationship("Conference", back_populates="venue")
city = relationship("City", back_populates="venues")
class Country(TimeStampedModel):
"""Country."""
__tablename__ = "country"
alpha2 = Column(String, primary_key=True)
name = Column(String)
wikidata_qid = Column(String, nullable=False)
cities = relationship("City", back_populates="country")
class ConferencePerson(Base): class ConferencePerson(Base):
__tablename__ = "conference_person" __tablename__ = "conference_person"

25
main.py
View file

@ -101,7 +101,7 @@ def top_events() -> sqlalchemy.orm.query.Query:
database.session.query(model.Event.title, func.count()) database.session.query(model.Event.title, func.count())
.group_by(model.Event.title) .group_by(model.Event.title)
.order_by(func.count().desc()) .order_by(func.count().desc())
.having(func.count() > 5) .having(func.count() > 3)
) )
return q return q
@ -235,6 +235,29 @@ def top_speakers_page() -> str:
return flask.render_template("top_speakers.html", top_speakers=top_speakers()) return flask.render_template("top_speakers.html", top_speakers=top_speakers())
@app.route("/country")
def country_list() -> str:
"""Country list."""
return flask.render_template("country_list.html", items=model.Country.query)
@app.route("/city/<int:city_id>/venue/new", methods=["GET", "POST"])
def add_venue(city_id: int) -> str | Response:
"""Add new venue."""
city = model.City.query.get(city_id)
if flask.request.method != "POST":
return flask.render_template("add_venue.html", city=city)
name = flask.request.form["name"]
wikidata_qid = flask.request.form["wikidata_qid"]
venue = model.Venue(name=name, city=city, wikidata_qid=wikidata_qid)
database.session.add(venue)
database.session.commit()
endpoint = flask.endpoint
return flask.redirect(flask.url_for(endpoint))
@app.route("/wikidata") @app.route("/wikidata")
def link_to_wikidata() -> str: def link_to_wikidata() -> str:
items = [] items = []

30
templates/add_venue.html Normal file
View file

@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block title %}New venue{% endblock %}
{% block content %}
<div class="container">
<div class="row">
<h1>Conference archive</h1>
<p><a href="{{ url_for("index") }}">home</a></p>
<h2>New venue</h2>
<p>City: {{ city.name }}, {{ city.country.name }}</p>
<form>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="mb-3">
<label for="wikidata_qid" class="form-label">Wikidata QID</label>
<input type="text" class="form-control" id="wikidata_qid" name="wikidata_qid">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,39 @@
{% extends "base.html" %}
{% block title %}Countries{% endblock %}
{% block content %}
<div class="container">
<div class="row">
<h1>Conference archive</h1>
<p><a href="{{ url_for("index") }}">home</a></p>
<h2>Countries</h2>
{% for item in items %}
<div>
<h4>{{ item.name }}</h4>
<p><a href="https://www.wikidata.org/wiki/{{ item.wikidata_qid }}">Wikidata: {{ item.wikidata_qid }}</a></p>
<div>
<ul>
{% for city in item.cities %}
<li>
{{ city.name }}
(<a href="https://www.wikidata.org/wiki/{{ item.wikidata_qid }}">{{ item.wikidata_qid }}</a>)
&mdash;
{% if city.venues %}
{% for venue in city.venues %}
{{ venue.name }}
{% endfor %}
{% endif %}
<a href="{{ url_for("add_venue", city_id=city.id) }}">add venue in city</a>
</li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}