Skip to content
Snippets Groups Projects

fix artifacts vs cache

Merged Antoine Gaudron-Desjardins requested to merge update_ci into main
Files
23
+ 40
25
@@ -214,7 +214,7 @@ def delete_comment(id: int, db: Session):
# Define CRUD operation for the news
def get_news(place: str, db: Session):
def get_news(place: str, admin: bool, db: Session):
""" Get the news for the given place """
current_date = datetime.now(tz=pytz.timezone("Europe/Paris"))
news = db.query(
@@ -222,37 +222,50 @@ def get_news(place: str, db: Session):
models.News.place == place,
models.News.end_date >= current_date).order_by(
models.News.published_at.desc()).all()
if admin:
return news
opening_hours = db.query(
models.OpeningHours.open_time,
models.OpeningHours.close_time).filter(
models.OpeningHours.close_time,
models.OpeningHours.day).filter(
models.OpeningHours.place == place,
models.OpeningHours.day == current_date.weekday()).order_by(
models.OpeningHours.day >= current_date.weekday()).order_by(
models.OpeningHours.day,
models.OpeningHours.open_time).all()
next_timetable = None
for time_slot in opening_hours:
if current_date.time() < time_slot.open_time:
next_timetable = time_slot.open_time
if not opening_hours:
opening_hours = db.query(
models.OpeningHours.open_time,
models.OpeningHours.close_time,
models.OpeningHours.day).filter(
models.OpeningHours.place == place).order_by(
models.OpeningHours.day,
models.OpeningHours.open_time).all()
next_time_slot = None
for open_time, close_time, day in opening_hours:
next_date = current_date + timedelta(days=day - current_date.weekday())
if day < current_date.weekday():
next_date = next_date + timedelta(days=7)
next_time_slot = datetime.combine(next_date.date(), open_time)
break
if not next_timetable:
closure = db.query(
models.Closure).filter(
models.Closure.place == place,
models.Closure.beginning_date <= current_date,
models.Closure.end_date >= current_date).first()
else:
if current_date < pytz.timezone("Europe/Paris").localize(datetime.combine(next_date.date(), close_time)):
next_time_slot = datetime.combine(next_date.date(), open_time)
break
if next_time_slot:
closure = db.query(
models.Closure).filter(
models.Closure.place == place,
models.Closure.beginning_date <= datetime.combine(current_date.date(), next_timetable),
models.Closure.end_date >= datetime.combine(current_date.date(), next_timetable)).first()
if closure:
closure_news = schemas.News(
title="Fermeture exceptionnelle",
content=f"{place} est exceptionnellement hors service jusqu'au {closure.end_date.strftime('%d/%m/%y à %Hh%M')}",
end_date=closure.end_date,
place=place,
published_at=closure.beginning_date)
news.append(closure_news)
models.Closure.beginning_date <= next_time_slot,
models.Closure.end_date > next_time_slot).first()
if closure:
closure_news = schemas.News(
title="Fermeture exceptionnelle",
content=f"{place} est exceptionnellement hors service jusqu'au {closure.end_date.strftime('%d/%m/%y à %Hh%M')}",
end_date=closure.end_date,
place=place,
published_at=current_date)
news.append(closure_news)
return news
@@ -382,6 +395,7 @@ def update_user(user: schemas.User, user_info: dict, db: Session):
if existing_user:
existing_user.cookie = user.cookie
existing_user.expiration_date = expiration_date
existing_user.admin = "admin eatfast" in user_info["roles"]
db.delete(user)
db.add(existing_user)
db.commit()
@@ -390,6 +404,7 @@ def update_user(user: schemas.User, user_info: dict, db: Session):
else:
user.username = full_name
user.expiration_date = expiration_date
user.admin = "admin eatfast" in user_info["roles"]
db.add(user)
db.commit()
db.refresh(user)
@@ -531,7 +546,7 @@ def create_closure(closure: schemas.Closure, db: Session):
db.add(db_closure)
db.commit()
db.refresh(db_closure)
return schemas.Closure(**closure.dict())
return schemas.Closure(**db_closure.__dict__)
def delete_closure(id: int, db: Session):
Loading