-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,54 @@ | ||
from django.views.generic.base import TemplateView | ||
from .mixins import ExampleMixin | ||
from django.template.loader import render_to_string | ||
import calendar as calendarmod | ||
from datetime import date | ||
import datetime | ||
from .mixins import CalendarMixin | ||
|
||
class CalendarView(ExampleMixin, TemplateView): | ||
|
||
|
||
class CustomCalendar(calendarmod.HTMLCalendar): | ||
def formatmonth(self, year, month, withyear=True, events=[]): | ||
self.year = year | ||
self.month = month | ||
self.events = events | ||
return super().formatmonth(year, month, withyear) | ||
|
||
def formatday(self, day, weekday): | ||
context = { | ||
'day': day, | ||
'date': date(self.year, self.month, day) if day > 0 else None, | ||
'css_class': self.cssclass_noday if day == 0 else self.cssclasses[weekday], | ||
'calendar_events': self.events, | ||
'now': date.today() | ||
} | ||
return render_to_string('_td_calendar.html', context) | ||
|
||
|
||
class CalendarView(CalendarMixin, TemplateView): | ||
demo_template = '_calendar.html' | ||
subtitle = 'Calendar' | ||
|
||
calendar = CalendarView.as_view() | ||
def get_context_data(self,**kwargs): | ||
context = super().get_context_data(**kwargs) | ||
date_str = self.request.GET.get("date", "") | ||
if date_str: | ||
today = datetime.datetime.fromisoformat(date_str).date() | ||
else: | ||
today = date.today() | ||
events = [ | ||
{'date': today, 'description': 'lorem ipsum'}, | ||
{'date': date(2020,12,9), 'description': 'lorem ipsum'}, | ||
{'date': date(2020,12,9), 'description': 'lorem ipsum'}, | ||
{'date': date(2020,12,13), 'description': 'lorem ipsum'}, | ||
{'date': date(2020,12,15), 'description': 'lorem ipsum'}, | ||
{'date': date(2020,12,15), 'description': 'lorem ipsum'}, | ||
{'date': date(2020,12,15), 'description': 'lorem ipsum'} | ||
] | ||
context["calendar"] = CustomCalendar().formatmonth(today.year,today.month, events=events) | ||
context["next_month_date"] = today + datetime.timedelta(days=30) | ||
context["prev_month_date"] = today + datetime.timedelta(days=-30) | ||
return context | ||
|
||
calendar = CalendarView.as_view() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters