Added day switching buttons

This commit is contained in:
2022-11-11 12:49:09 +03:00
parent dc3b7b109a
commit 6a0193c698
4 changed files with 74 additions and 1 deletions
@@ -5,6 +5,10 @@ div.calendarpage {
border-radius: 20px;
}
div.calendarpage h2 {
text-align: center;
}
div.current-year {
display: flex;
justify-content: space-between;
@@ -41,8 +41,24 @@
{% elif type == 'day' %}
<h1 class="title">Календарь — События</h1>
<div class="current-year">
{% if previous_day %}
<a draggable="false" class="arrow left" href="{{root}}{{previous_day.year}}/{{previous_day.month}}/{{previous_day.day}}"></a>
{% else %}
<a draggable="false" class="arrow left" disabled></a>
{% endif %}
<h2 class="year">Год {{year_data.number}}-й, {{month_data.name}}{% if not month_data.is_oneday %}, день {{day}}-й{% endif %}</h2>
{% if next_day %}
<a draggable="false" class="arrow right" href="{{root}}{{next_day.year}}/{{next_day.month}}/{{next_day.day}}"></a>
{% else %}
<a draggable="false" class="arrow right" disabled></a>
{% endif %}
</div>
<hr>
<div class="calendar-events">
{% if events.count == 0 %}
<p class="calendar-info">Событий нет</p>
@@ -66,6 +82,8 @@
{% elif type == 'error' %}
<h1 class="title">Календарь — Ошибка</h1>
<hr>
<div class="calendar-error">
{% if error_type == 'year' %}
<p class="calendar-error">Неверный год</p>
+51 -1
View File
@@ -68,14 +68,64 @@ def day_page(request, year: int, month: int, day: int):
if is_oneday and day != 1 or not 1 <= day <= 30:
params = {'type': 'error', 'error_type': 'day'}
if not params:
try:
previous_day = {'year': year, 'month': month, 'day': day-1}
if previous_day['day'] <= 0:
previous_day['month'] -= 1
if previous_day['month'] <= 0:
try:
previous_day['year'] = getattr(getattr(year_data, 'previous_year'), 'number')
except (AttributeError, YearData.DoesNotExist):
previous_day['year'] = None
if not previous_day['year']:
previous_day = None
else:
previous_month = MonthData.objects.last()
previous_day['month'] = getattr(previous_month, 'number')
previous_day['day'] = 1 if getattr(previous_month, 'is_oneday') else 30
else:
previous_month = MonthData.objects.get(number=previous_day['month'])
previous_day['day'] = 1 if getattr(previous_month, 'is_oneday') else 30
next_day = {'year': year, 'month': month, 'day': day + 1}
if next_day['day'] > (1 if is_oneday else 30):
next_day['day'] = 1
next_day['month'] += 1
try:
is_month_exist = MonthData.objects.get(number=next_day['month'])
except MonthData.DoesNotExist:
is_month_exist = False
if not is_month_exist:
next_day['month'] = 1
try:
next_day['year'] = getattr(getattr(year_data, 'next_year'), 'number')
except (AttributeError, YearData.DoesNotExist):
next_day['year'] = None
if not next_day['year']:
next_day = None
except AttributeError:
params = {'type': 'error', 'error_type': 'month'}
print(6)
if not params:
params = {
'type': 'day',
'root': '',
'root': '../../../',
'year_data': year_data,
'month_data': month_data,
'day': day,
'events': events,
'previous_day': previous_day,
'next_day': next_day,
}
return render(request, 'faerun_calendar/index.html', params)