Code for importing data from pretalx
This commit is contained in:
parent
1001c51bc1
commit
e48acab387
5 changed files with 392 additions and 5 deletions
|
|
@ -19,6 +19,12 @@ from .database import session
|
|||
Base: sqlalchemy.orm.decl_api.DeclarativeMeta = declarative_base()
|
||||
Base.query = session.query_property()
|
||||
|
||||
content_type_to_extension = {
|
||||
"image/jpeg": "jpg",
|
||||
"image/png": "png",
|
||||
"image/gif": "gif",
|
||||
}
|
||||
|
||||
|
||||
class TimeStampedModel(Base):
|
||||
"""Time stamped model."""
|
||||
|
|
@ -140,6 +146,7 @@ class ConferencePerson(Base):
|
|||
url = Column(String)
|
||||
affiliation = Column(String)
|
||||
photo_url = Column(String)
|
||||
photo_url_content_type = Column(String)
|
||||
|
||||
person = relationship("Person", back_populates="conferences_association")
|
||||
conference = relationship("Conference", back_populates="people_detail")
|
||||
|
|
@ -181,7 +188,6 @@ class Event(TimeStampedModel):
|
|||
people_detail = relationship(
|
||||
"EventPerson",
|
||||
order_by="EventPerson.position",
|
||||
lazy="dynamic",
|
||||
back_populates="event",
|
||||
collection_class=ordering_list("position"),
|
||||
)
|
||||
|
|
@ -273,15 +279,21 @@ class Person(TimeStampedModel):
|
|||
return typing.cast(ConferencePerson, best)
|
||||
|
||||
def photo_filename(self) -> str | None:
|
||||
"""Speaker photo filename."""
|
||||
if self.wikidata_photo:
|
||||
assert isinstance(self.wikidata_photo[0], str)
|
||||
return os.path.join("wikidata_photo", "thumb", self.wikidata_photo[0])
|
||||
|
||||
q = self.conferences_association.filter(ConferencePerson.photo_url.isnot(None))
|
||||
q = self.conferences_association.filter(
|
||||
ConferencePerson.photo_url.isnot(None),
|
||||
ConferencePerson.photo_url_content_type.isnot(None),
|
||||
)
|
||||
if q.count() == 0:
|
||||
return None
|
||||
|
||||
best = max(q, key=lambda cp: cp.conference.start)
|
||||
ext = best.photo_url.rpartition(".")[-1]
|
||||
ext = content_type_to_extension[best.photo_url_content_type]
|
||||
|
||||
filename = f"{best.conference_id}_{self.id}.{ext}"
|
||||
return os.path.join("conference_photo", filename)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue