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
This commit is contained in:
parent
34d1ee3b30
commit
ef624f83dd
|
@ -6,8 +6,11 @@ from datetime import date, datetime
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from . import utils
|
||||||
from .event import Event
|
from .event import Event
|
||||||
|
|
||||||
|
MAX_CONF_DAYS = 20
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Conference:
|
class Conference:
|
||||||
|
@ -55,6 +58,9 @@ def get_list(filepath: str) -> list[Event]:
|
||||||
"""Read conferences from a YAML file and return a list of Event objects."""
|
"""Read conferences from a YAML file and return a list of Event objects."""
|
||||||
events: list[Event] = []
|
events: list[Event] = []
|
||||||
for conf in (Conference(**conf) for conf in yaml.safe_load(open(filepath, "r"))):
|
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(
|
event = Event(
|
||||||
name="conference",
|
name="conference",
|
||||||
date=conf.start,
|
date=conf.start,
|
||||||
|
|
Loading…
Reference in a new issue