essensplan/cal/views.py

29 lines
865 B
Python
Raw Normal View History

2018-07-25 06:10:26 +00:00
from datetime import datetime
2018-07-02 06:06:17 +00:00
from django.shortcuts import render
from django.http import HttpResponse
2018-07-25 06:10:26 +00:00
from django.views import generic
from django.utils.safestring import mark_safe
2018-07-02 06:06:17 +00:00
2018-07-25 06:10:26 +00:00
from .models import *
from .utils import Calendar
2018-07-02 06:06:17 +00:00
def index(request):
return HttpResponse('hello')
2018-07-25 06:10:26 +00:00
class CalendarView(generic.ListView):
model = Event
template_name = 'cal/calendar.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
d = get_date(self.request.GET.get('day', None))
cal = Calendar(d.year, d.month)
html_cal = cal.formatmonth(withyear=True)
context['calendar'] = mark_safe(html_cal)
return context
def get_date(req_day):
if req_day:
year, month = (int(x) for x in req_day.split('-'))
return date(year, month, day=1)
return datetime.today()