2017-08-20 00:39:19 +02:00
|
|
|
from datetime import timedelta, date
|
2017-08-19 01:32:26 +02:00
|
|
|
from django import template
|
|
|
|
from django.conf import settings
|
2017-08-20 00:39:19 +02:00
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from ..models import COFActuEventPage
|
2017-08-19 01:32:26 +02:00
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
|
|
@register.filter()
|
|
|
|
def obfuscate_mail(value):
|
|
|
|
val = value.replace('', '/').replace('@', 'arbse').replace('.', 'pnt')
|
|
|
|
return val
|
2017-08-20 00:39:19 +02:00
|
|
|
|
|
|
|
@register.inclusion_tag("cofcms/calendar.html")
|
|
|
|
def calendar():
|
|
|
|
now = timezone.now()
|
|
|
|
month_start = date(now.year, now.month, 1)
|
|
|
|
next_month = month_start + timedelta(days=32)
|
|
|
|
next_month = date(next_month.year, next_month.month, 1)
|
|
|
|
month_prestart = month_start - timedelta(days=(month_start.weekday()+7)%7)
|
|
|
|
month_postend = next_month + timedelta(days=(next_month.weekday()+6)%7)
|
|
|
|
events = COFActuEventPage.objects.live()\
|
|
|
|
.filter(date_start__range=[month_prestart,
|
|
|
|
month_postend])\
|
|
|
|
.order_by('-date_start')
|
|
|
|
events = list(events)
|
|
|
|
weeks = []
|
|
|
|
curday = month_prestart
|
|
|
|
deltaday = timedelta(days=1)
|
|
|
|
while curday < next_month and len(weeks)<10:
|
|
|
|
week = []
|
|
|
|
for k in range(7):
|
|
|
|
curevents = []
|
|
|
|
for k in range(len(events)-1, -1, -1):
|
|
|
|
e = events[k]
|
|
|
|
if e.date_start.date() > curday: break
|
|
|
|
if (e.date_start if e.date_end is None else e.date_end).date() < curday:
|
|
|
|
del events[k]
|
|
|
|
else:
|
|
|
|
curevents.append(e)
|
|
|
|
print(curevents)
|
|
|
|
day = {'day': curday.day,
|
|
|
|
'class': (('today ' if (curday.day == now.day
|
|
|
|
and curday.month == now.month) else '')
|
|
|
|
+ ('in' if curday.month == now.month else 'out')),
|
|
|
|
'events': curevents}
|
|
|
|
week.append(day)
|
|
|
|
curday += deltaday
|
|
|
|
weeks.append(week)
|
|
|
|
return {"events": events, "weeks": weeks}
|