Skip to content

Commit

Permalink
calendar WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zodman committed Dec 2, 2020
1 parent ba1cb97 commit 3426f23
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
51 changes: 47 additions & 4 deletions core/views/calendar.py
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()


9 changes: 9 additions & 0 deletions core/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

)
1 change: 1 addition & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 3426f23

Please sign in to comment.