Added highlighting of days with events

This commit is contained in:
2022-11-07 15:16:02 +03:00
parent eeef11bfa5
commit 81f5f37363
4 changed files with 73 additions and 30 deletions
+38 -12
View File
@@ -93,19 +93,45 @@ def year_page(request, year: int, root: str = None):
params = {'type': 'error', 'error_type': 'year'}
if not params:
month_data = MonthData.objects.all().order_by('number')
calendar_data = CalendarData.objects.first()
events = Event.objects.all()
try:
month_data = MonthData.objects.all().order_by('number')
calendar_data = CalendarData.objects.first()
params = {
'type': 'year',
'root': root,
'calendar_data': calendar_data,
'year_data': year_data,
'month_data': month_data,
'month_days': tuple(i+1 for i in range(30)),
'events': events,
}
months = []
for month in month_data:
is_oneday_month = getattr(month, 'is_oneday')
is_leap_month = getattr(month, 'is_leap_month')
is_leap_year = getattr(year_data, 'is_leap')
if is_leap_month and not is_leap_year:
continue
m = {
'id': getattr(month, 'id'),
'number': getattr(month, 'number'),
'name': getattr(month, 'name'),
'folkname': getattr(month, 'folkname'),
'is_oneday': getattr(month, 'is_oneday'),
'days': []
}
for i in range(0, 1 if is_oneday_month else 30):
day = {
'number': i+1,
'event_counts': Event.objects.filter(year=year_data.id, month=month.id, day=i+1,
is_suggested=False, is_only_for_gm=False).count()
}
m['days'].append(day)
months.append(m)
params = {
'type': 'year',
'root': root,
'calendar_data': calendar_data,
'year_data': year_data,
'months': months,
}
except AttributeError:
params = {'type': 'error', 'error_type': 'unknown'}
return render(request, 'faerun_calendar/index.html', params)