mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 23:55:46 +02:00
Adding new deadlines
This commit is contained in:
parent
107e4fb580
commit
e2959c27ad
6 changed files with 73 additions and 10 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from typing import Optional
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from dateutil.parser import parse
|
||||
|
|
@ -5,7 +6,7 @@ from sqlalchemy import select
|
|||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from database.schemas.relational import Deadline
|
||||
from database.schemas.relational import Deadline, UforaCourse
|
||||
|
||||
__all__ = ["add_deadline", "get_deadlines"]
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ async def add_deadline(session: AsyncSession, course_id: int, name: str, date_st
|
|||
"""Add a new deadline"""
|
||||
date_dt = parse(date_str).replace(tzinfo=ZoneInfo("Europe/Brussels"))
|
||||
|
||||
# If we only have a day, assume it's the end of the day
|
||||
if date_dt.hour == date_dt.minute == date_dt.second == 0:
|
||||
date_dt.replace(hour=23, minute=59, second=59)
|
||||
|
||||
|
|
@ -22,10 +24,15 @@ async def add_deadline(session: AsyncSession, course_id: int, name: str, date_st
|
|||
await session.commit()
|
||||
|
||||
|
||||
async def get_deadlines(session: AsyncSession) -> list[Deadline]:
|
||||
async def get_deadlines(session: AsyncSession, *, course: Optional[UforaCourse] = None) -> list[Deadline]:
|
||||
"""Get a list of all deadlines that are currently known
|
||||
|
||||
This includes deadlines that have passed already
|
||||
"""
|
||||
statement = select(Deadline).options(selectinload(Deadline.course))
|
||||
statement = select(Deadline)
|
||||
|
||||
if course is not None:
|
||||
statement = statement.where(Deadline.course_id == course.course_id)
|
||||
|
||||
statement = statement.options(selectinload(Deadline.course))
|
||||
return (await session.execute(statement)).scalars().all()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue