From a25e869eca4226919004f10a4016fda6c2fcfea6 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 29 Jun 2018 16:14:35 +0200 Subject: [PATCH] Load events for the month view --- app/calendar_system/gregorian.py | 16 ++++++++++++++++ app/templates/month-view.html | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/calendar_system/gregorian.py b/app/calendar_system/gregorian.py index 3dc5b2d..162bfd6 100644 --- a/app/calendar_system/gregorian.py +++ b/app/calendar_system/gregorian.py @@ -46,3 +46,19 @@ class GregorianCalendar(CalendarSystem): day_list.append(current_day) return day_list + + def day_events(self, date, user=None): + from app.models import Event + + events = Event.query + + if user: + events = events.filter(Event.user == user) + + start_timestamp = date.replace(hour=0, minute=0, second=0, microsecond=0) + end_timestamp = start_timestamp + timedelta(days=1) + + events = events.filter(((Event.start_time >= start_timestamp) & (Event.start_time < end_timestamp)) | + ((Event.end_time >= start_timestamp) & (Event.end_time < end_timestamp))) + + return events diff --git a/app/templates/month-view.html b/app/templates/month-view.html index 792d06c..f5df1db 100644 --- a/app/templates/month-view.html +++ b/app/templates/month-view.html @@ -70,11 +70,11 @@ {%- endif %} {{ day.day }} - {% if day.date() == calendar.timestamp.date() %} + {% for event in calendar.day_events(day, user=current_user) %}
- This is a task + {{ event.title }}
- {% endif %} + {% endfor %} {% endfor %}