diff --git a/core/views/calendar.py b/core/views/calendar.py index 446d41d..8de3a61 100644 --- a/core/views/calendar.py +++ b/core/views/calendar.py @@ -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() - diff --git a/core/views/mixins.py b/core/views/mixins.py index 89e4c84..366d751 100644 --- a/core/views/mixins.py +++ b/core/views/mixins.py @@ -59,3 +59,12 @@ class ChatMixin(MixinBase): ('core/templates/_chat_demo.html', 'html', 'htmldjango'), ) +class CalendarMixin(MixinBase): + files = ( + ('core/views/calendar.py', 'python', 'python3'), +# ('core/reflexes/calendar_reflex.py', 'python', 'python3'), +# ('core/javascript/controllers/calendar_controller.js', 'javascript', 'javascript'), + ('core/templates/_calendar.html', 'html', 'htmldjango'), + ('core/templates/_td_calendar.html', 'html', 'htmldjango'), + + ) diff --git a/fabfile.py b/fabfile.py index d477598..e0d6fec 100644 --- a/fabfile.py +++ b/fabfile.py @@ -12,6 +12,7 @@ def deploy(ctx): local("python manage.py collectstatic --noinput --clear", echo=True) rsync(ctx, "static/", "apps/django-sockpuppet-expo/static/", exclude=exclude_dirs) + rsync(ctx, "webpack-stats.json", "apps/django-sockpuppet-expo/") with ctx.cd("~/apps/django-sockpuppet-expo"): ctx.run('git pull') with ctx.prefix("source .env/bin/activate"):