Add a very basic calendar view #10

Merged
gergely merged 1 commits from calendar-view into master 2018-06-30 04:04:43 +00:00
2 changed files with 19 additions and 3 deletions
Showing only changes of commit a25e869eca - Show all commits

View File

@ -46,3 +46,19 @@ class GregorianCalendar(CalendarSystem):
day_list.append(current_day) day_list.append(current_day)
return day_list 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 %} {%- endif %}
<td class="{% if day.month != calendar.timestamp.month %} other-month{% endif %}{% if day.date() == calendar.timestamp.date() %} today{% 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> <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"> <div class="event">
This is a task {{ event.title }}
</div> </div>
{% endif %} {% endfor %}
</td> </td>
{% endfor %} {% endfor %}
</tr> </tr>