Load events for the month view

This commit is contained in:
Gergely Polonkai 2018-06-29 16:14:35 +02:00
parent bac17faed2
commit a25e869eca
2 changed files with 19 additions and 3 deletions

View File

@ -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

View File

@ -70,11 +70,11 @@
{%- endif %}
<td class="{% if day.month != calendar.timestamp.month %} other-month{% endif %}{% if day.date() == calendar.timestamp.date() %} today{% endif %}">
<span class="day-num">{{ day.day }}</span>
{% if day.date() == calendar.timestamp.date() %}
{% for event in calendar.day_events(day, user=current_user) %}
<div class="event">
This is a task
{{ event.title }}
</div>
{% endif %}
{% endfor %}
</td>
{% endfor %}
</tr>