Added day switching buttons
This commit is contained in:
@@ -5,6 +5,10 @@ div.calendarpage {
|
|||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.calendarpage h2 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
div.current-year {
|
div.current-year {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|||||||
@@ -41,8 +41,24 @@
|
|||||||
{% elif type == 'day' %}
|
{% elif type == 'day' %}
|
||||||
<h1 class="title">Календарь — События</h1>
|
<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>
|
<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">
|
<div class="calendar-events">
|
||||||
{% if events.count == 0 %}
|
{% if events.count == 0 %}
|
||||||
<p class="calendar-info">Событий нет</p>
|
<p class="calendar-info">Событий нет</p>
|
||||||
@@ -66,6 +82,8 @@
|
|||||||
{% elif type == 'error' %}
|
{% elif type == 'error' %}
|
||||||
<h1 class="title">Календарь — Ошибка</h1>
|
<h1 class="title">Календарь — Ошибка</h1>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<div class="calendar-error">
|
<div class="calendar-error">
|
||||||
{% if error_type == 'year' %}
|
{% if error_type == 'year' %}
|
||||||
<p class="calendar-error">Неверный год</p>
|
<p class="calendar-error">Неверный год</p>
|
||||||
|
|||||||
@@ -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:
|
if is_oneday and day != 1 or not 1 <= day <= 30:
|
||||||
params = {'type': 'error', 'error_type': 'day'}
|
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:
|
if not params:
|
||||||
params = {
|
params = {
|
||||||
'type': 'day',
|
'type': 'day',
|
||||||
'root': '',
|
'root': '../../../',
|
||||||
'year_data': year_data,
|
'year_data': year_data,
|
||||||
'month_data': month_data,
|
'month_data': month_data,
|
||||||
'day': day,
|
'day': day,
|
||||||
'events': events,
|
'events': events,
|
||||||
|
'previous_day': previous_day,
|
||||||
|
'next_day': next_day,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'faerun_calendar/index.html', params)
|
return render(request, 'faerun_calendar/index.html', params)
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ body > div > * {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.arrow[disabled] {
|
.arrow[disabled] {
|
||||||
|
margin: 3px 0px;
|
||||||
color: #dcdcdc;
|
color: #dcdcdc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user