Skip to content

Commit

Permalink
created method for retrieving schedule data with room as a dict for r…
Browse files Browse the repository at this point in the history
…endering in email template
  • Loading branch information
anishTP committed Jan 11, 2024
1 parent 2d07512 commit 66c3ec7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
28 changes: 28 additions & 0 deletions funnel/templates/notifications/update_new_email.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@
{% trans update_body=view.update.body %}{{ update_body }}{% endtrans %}
</td>
</tr>
<tr>
{% for day, rooms in schedule.items() %}
<div class="schedule">
<h3 class="schedule__date collapsible__header mui--clearfix schedule__date--upcoming">
<span class="mui--pull-left">{{ day }}</span>
</h3>
{% for room, slots in rooms.items() %}
<table class="bg-accent schedule__table collapsible__body">
<tr class="schedule__row schedule__row--sticky">
<th class="schedule__row__column schedule__row__column--time schedule__row__column--time--header" style="minWidth: '100px'">Time</th>
<th class="schedule__row__column schedule__row__column--header" style="width: 'calc(100% - '100px)'">{{ room }}</th>
</tr>
{% for slot, sessions in slots.itens() %}
{% for session in sessions %}
<tr>
<td class="mui--text-body2 schedule__row__column__content__title__duration">{{ session.startTime }}–{{ session.endTime }}</td>
<td class="schedule__row__column__content__title">
{% if room.talk.title %}<p class="mui--text-body2 schedule__row__column__content__title__heading">{{ session.title }}</p>{% endif %}
{% if room.talk.speaker %}<p class="mui--text-caption mui--text-light schedule__row__column__content__title__speaker">{{ session.speaker }}</p>{% endif %}
</td>
</tr>
{% endfor %}
{% endfor %}
</table>
{% endfor %}
</div>
{% endfor %}
</tr>
<br/>

{# Button : BEGIN #}
Expand Down
11 changes: 3 additions & 8 deletions funnel/views/notifications/update_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion funnel/views/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 66c3ec7

Please sign in to comment.