diff --git a/confarchive/model.py b/confarchive/model.py index 2471eb3..b05531c 100644 --- a/confarchive/model.py +++ b/confarchive/model.py @@ -41,6 +41,7 @@ class Conference(TimeStampedModel): url = Column(String) schedule_xml_url = Column(String) short_name = Column(String, unique=True) + venue_id = Column(Integer, ForeignKey("venue.id")) people_detail = relationship( "ConferencePerson", lazy="dynamic", back_populates="conference" @@ -54,6 +55,46 @@ class Conference(TimeStampedModel): 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): __tablename__ = "conference_person" diff --git a/main.py b/main.py index 798636a..27ce2f3 100755 --- a/main.py +++ b/main.py @@ -101,7 +101,7 @@ def top_events() -> sqlalchemy.orm.query.Query: database.session.query(model.Event.title, func.count()) .group_by(model.Event.title) .order_by(func.count().desc()) - .having(func.count() > 5) + .having(func.count() > 3) ) return q @@ -235,6 +235,29 @@ def top_speakers_page() -> str: 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//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") def link_to_wikidata() -> str: items = [] diff --git a/templates/add_venue.html b/templates/add_venue.html new file mode 100644 index 0000000..9175418 --- /dev/null +++ b/templates/add_venue.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} + +{% block title %}New venue{% endblock %} + + {% block content %} +
+
+

Conference archive

+

home

+ +

New venue

+ +

City: {{ city.name }}, {{ city.country.name }}

+ +
+
+ + +
+
+ + +
+ +
+ + +
+
+{% endblock %} diff --git a/templates/country_list.html b/templates/country_list.html new file mode 100644 index 0000000..374ce8b --- /dev/null +++ b/templates/country_list.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} + +{% block title %}Countries{% endblock %} + + {% block content %} +
+
+

Conference archive

+

home

+ +

Countries

+ + {% for item in items %} +
+

{{ item.name }}

+

Wikidata: {{ item.wikidata_qid }}

+
+
    + {% for city in item.cities %} +
  • + {{ city.name }} + ({{ item.wikidata_qid }}) + — + {% if city.venues %} + {% for venue in city.venues %} + {{ venue.name }} + {% endfor %} + {% endif %} + add venue in city +
  • + {% endfor %} +
+
+
+ {% endfor %} + +
+
+{% endblock %}