From 66c3ec7cff203b61f7091667edb64cb53bb24990 Mon Sep 17 00:00:00 2001 From: anishTP Date: Thu, 11 Jan 2024 21:24:54 +0530 Subject: [PATCH] created method for retrieving schedule data with room as a dict for rendering in email template --- .../update_new_email.html.jinja2 | 28 +++++++++++++++++++ .../notifications/update_notification.py | 11 ++------ funnel/views/schedule.py | 16 ++++++++++- sample.env | 4 +-- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/funnel/templates/notifications/update_new_email.html.jinja2 b/funnel/templates/notifications/update_new_email.html.jinja2 index b33cd1e91..4f8fd16b4 100644 --- a/funnel/templates/notifications/update_new_email.html.jinja2 +++ b/funnel/templates/notifications/update_new_email.html.jinja2 @@ -17,6 +17,34 @@ {% trans update_body=view.update.body %}{{ update_body }}{% endtrans %} + + {% for day, rooms in schedule.items() %} +
+

+ {{ day }} +

+ {% for room, slots in rooms.items() %} + + + + + + {% for slot, sessions in slots.itens() %} + {% for session in sessions %} + + + + + {% endfor %} + {% endfor %} +
Time{{ room }}
{{ session.startTime }}–{{ session.endTime }} + {% if room.talk.title %}

{{ session.title }}

{% endif %} + {% if room.talk.speaker %}

{{ session.speaker }}

{% endif %} +
+ {% endfor %} +
+ {% endfor %} +
{# Button : BEGIN #} diff --git a/funnel/views/notifications/update_notification.py b/funnel/views/notifications/update_notification.py index 3629c85d2..66a4f69cf 100644 --- a/funnel/views/notifications/update_notification.py +++ b/funnel/views/notifications/update_notification.py @@ -11,7 +11,7 @@ from ..helpers import shortlink from ..notification import RenderNotification from .mixins import TemplateVarMixin -from ..schedule import session_list_data, schedule_data +from ..schedule import upcoming_schedule_data_with_room class UpdateTemplate(TemplateVarMixin, SmsTemplate): @@ -64,19 +64,14 @@ def email_subject(self) -> str: ) def email_content(self) -> str: - scheduled_sessions_list = session_list_data( - self.project.scheduled_sessions, with_modal_url='view' - ) project = self.project.current_access(datasets=('primary', 'related')) venues = [ venue.current_access(datasets=('without_parent', 'related')) for venue in self.project.venues ] - schedule = schedule_data( - self.project, with_slots=False, scheduled_sessions=scheduled_sessions_list - ) + schedules = upcoming_schedule_data_with_room(self.project) return render_template('notifications/update_new_email.html.jinja2', view=self, project=project, - venues=venues, schedule=schedule) + venues=venues, schedules=schedules) def sms(self) -> UpdateTemplate: return UpdateTemplate( diff --git a/funnel/views/schedule.py b/funnel/views/schedule.py index cc3058801..2d3242bda 100644 --- a/funnel/views/schedule.py +++ b/funnel/views/schedule.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections import defaultdict -from datetime import timedelta +from datetime import datetime, timedelta from types import SimpleNamespace from typing import TYPE_CHECKING, Any, cast @@ -114,6 +114,20 @@ def schedule_data( schedule.append(daydata) return schedule +def upcoming_schedule_data_with_room(project: Project) -> list[dict]: + schedule = schedule_data(project) + schedule_with_room = [] + for key, day in schedule: + if datetime.strptime(key,'%y-%m-%d') >= datetime.today(): + daydata_with_room: dict[str, dict[str, Any]] = defaultdict(lambda: + defaultdict(Any)) + for slots in schedule[day]: + roomdata: dict[str, Any] = defaultdict(Any) + roomdata[slots.sessions.room_scoped_name].append(slots) + daydata_with_room[day]['room'].append(roomdata) + schedule_with_room.append(daydata_with_room) + return schedule_with_room + def schedule_ical( project: Project, rsvp: Rsvp | None = None, future_only: bool = False diff --git a/sample.env b/sample.env index 159905cbc..08c528399 100644 --- a/sample.env +++ b/sample.env @@ -107,9 +107,9 @@ FLASK_CACHE_REDIS_URL=redis://${REDIS_HOST}:6379/0 # --- Database configuration DB_HOST=localhost # Main app database -FLASK_SQLALCHEMY_DATABASE_URI='postgresql+psycopg:///funnel' +FLASK_SQLALCHEMY_DATABASE_URI='postgresql+psycopg:///funnel_test' # Geoname database (the use of `__` creates a dict and sets a key in the dict) -FLASK_SQLALCHEMY_BINDS__geoname='postgresql+psycopg:///geoname' +FLASK_SQLALCHEMY_BINDS__geoname='postgresql+psycopg:///geoname_testing' # --- Email configuration # SMTP mail server ('localhost' if Postfix is configured as a relay email server)