agenda/agenda/conference.py
Edward Betts ef624f83dd Enhance conference validation and add MAX_CONF_DAYS
- Add checks for conference start and end dates.
- Set maximum conference duration to 20 days.

Closes: #182
2024-10-21 10:39:49 +01:00

84 lines
2.2 KiB
Python

"""Conferences."""
import dataclasses
import decimal
from datetime import date, datetime
import yaml
from . import utils
from .event import Event
MAX_CONF_DAYS = 20
@dataclasses.dataclass
class Conference:
"""Conference."""
name: str
topic: str
location: str
start: date | datetime
end: date | datetime
trip: date | None = None
country: str | None = None
venue: str | None = None
address: str | None = None
url: str | None = None
accommodation_booked: bool = False
transport_booked: bool = False
going: bool = False
registered: bool = False
speaking: bool = False
online: bool = False
price: decimal.Decimal | None = None
currency: str | None = None
latitude: float | None = None
longitude: float | None = None
cfp_end: date | None = None
cfp_url: str | None = None
free: bool | None = None
hackathon: bool | None = None
ticket_type: str | None = None
attendees: int | None = None
hashtag: str | None = None
@property
def display_name(self) -> str:
"""Add location if not already in conference name."""
return (
self.name
if self.location in self.name
else f"{self.name} ({self.location})"
)
def get_list(filepath: str) -> list[Event]:
"""Read conferences from a YAML file and return a list of Event objects."""
events: list[Event] = []
for conf in (Conference(**conf) for conf in yaml.safe_load(open(filepath, "r"))):
assert conf.start <= conf.end
duration = (utils.as_date(conf.end) - utils.as_date(conf.start)).days
assert duration < MAX_CONF_DAYS
event = Event(
name="conference",
date=conf.start,
end_date=conf.end,
title=conf.display_name,
url=conf.url,
going=conf.going,
)
events.append(event)
if not conf.cfp_end:
continue
cfp_end_event = Event(
name="cfp_end",
date=conf.cfp_end,
title="CFP end: " + conf.display_name,
url=conf.cfp_url or conf.url,
)
events.append(cfp_end_event)
return events