Added error descriptions

This commit is contained in:
2022-11-01 18:10:53 +03:00
parent ad1f99e8c9
commit f066d10d93
3 changed files with 78 additions and 28 deletions
@@ -84,3 +84,12 @@ p.event-description {
margin: 0px; margin: 0px;
padding: 0px; padding: 0px;
} }
p.calendar-error {
color: Crimson;
font-size: 200%;
}
p.calendar-info {
font-size: 200%;
}
@@ -18,6 +18,8 @@
{% elif type == 'day' %} {% elif type == 'day' %}
<h1 class="title">Календарь — События</h1> <h1 class="title">Календарь — События</h1>
<h2 class="year">Год {{year_data.number}}, {{month_data.name}}, день {{day}}-й</h2> <h2 class="year">Год {{year_data.number}}, {{month_data.name}}, день {{day}}-й</h2>
{% elif type == 'error' %}
<h1 class="title">Календарь — Ошибка</h1>
{% endif %} {% endif %}
<div class="calendar"> <div class="calendar">
@@ -29,7 +31,7 @@
{% endfor %} {% endfor %}
{% elif type == 'day' %} {% elif type == 'day' %}
{% if events.count == 0 %} {% if events.count == 0 %}
<p>Событий нет</p> <p class="calendar-info">Событий нет</p>
{% else %} {% else %}
{% for event in events %} {% for event in events %}
<div class="event"> <div class="event">
@@ -39,6 +41,14 @@
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% elif type == 'error' %}
{% if error_type == 'year' %}
<p class="calendar-error">Неверный год</p>
{% elif error_type == 'month' %}
<p class="calendar-error">Неверный месяц</p>
{% elif error_type == 'day' %}
<p class="calendar-error">Неверный день</p>
{% endif %}
{% endif %} {% endif %}
</div> </div>
</div> </div>
+58 -27
View File
@@ -9,38 +9,69 @@ from .models import Event
def day_page(request, year: int, month: int, day: int): def day_page(request, year: int, month: int, day: int):
try: params = None
year_data = YearData.objects.get(number=year)
except YearData.DoesNotExist:
return HttpResponseNotFound('<h1>404 Not Found</h1>')
try: if not params:
year_id = getattr(year_data, 'id') try:
except AttributeError: year_data = YearData.objects.get(number=year)
return HttpResponseNotFound('<h1>404 Not Found</h1>') except YearData.DoesNotExist:
params = {'type': 'error', 'error_type': 'year'}
try: if not params:
month_data = MonthData.objects.get(number=month) try:
except MonthData.DoesNotExist: year_id = getattr(year_data, 'id')
return HttpResponseNotFound('<h1>404 Not Found</h1>') except AttributeError:
params = {'type': 'error', 'error_type': 'year'}
try: if not params:
month_id = getattr(month_data, 'id') try:
except AttributeError: month_data = MonthData.objects.get(number=month)
return HttpResponseNotFound('<h1>404 Not Found</h1>') except MonthData.DoesNotExist:
params = {'type': 'error', 'error_type': 'month'}
try: if not params:
events = Event.objects.filter(year=year_id, month=month_id, day=day) try:
except Event.DoesNotExist: month_id = getattr(month_data, 'id')
return HttpResponseNotFound(f'<h1>404 Not Found</h1>') except AttributeError:
params = {'type': 'error', 'error_type': 'month'}
params = { if not params:
'type': 'day', try:
'year_data': year_data, events = Event.objects.filter(year=year_id, month=month_id, day=day)
'month_data': month_data, except Event.DoesNotExist:
'day': day, params = {'type': 'error', 'error_type': 'events'}
'events': events,
} if not params:
try:
is_leap = getattr(year_data, 'is_leap')
except AttributeError:
params = {'type': 'error', 'error_type': 'year'}
else:
try:
is_leap_month = getattr(month_data, 'is_leap_month')
except AttributeError:
params = {'type': 'error', 'error_type': 'month'}
else:
if not is_leap and is_leap_month:
params = {'type': 'error', 'error_type': 'month'}
if not params:
try:
is_oneday = getattr(month_data, 'is_oneday')
except AttributeError:
params = {'type': 'error', 'error_type': 'month'}
else:
if is_oneday and day != 1 or not 1 <= day <= 30:
params = {'type': 'error', 'error_type': 'day'}
if not params:
params = {
'type': 'day',
'year_data': year_data,
'month_data': month_data,
'day': day,
'events': events,
}
return render(request, 'faerun_calendar/index.html', params) return render(request, 'faerun_calendar/index.html', params)