Added error descriptions
This commit is contained in:
@@ -84,3 +84,12 @@ p.event-description {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
p.calendar-error {
|
||||
color: Crimson;
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
p.calendar-info {
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
{% elif type == 'day' %}
|
||||
<h1 class="title">Календарь — События</h1>
|
||||
<h2 class="year">Год {{year_data.number}}, {{month_data.name}}, день {{day}}-й</h2>
|
||||
{% elif type == 'error' %}
|
||||
<h1 class="title">Календарь — Ошибка</h1>
|
||||
{% endif %}
|
||||
|
||||
<div class="calendar">
|
||||
@@ -29,7 +31,7 @@
|
||||
{% endfor %}
|
||||
{% elif type == 'day' %}
|
||||
{% if events.count == 0 %}
|
||||
<p>Событий нет</p>
|
||||
<p class="calendar-info">Событий нет</p>
|
||||
{% else %}
|
||||
{% for event in events %}
|
||||
<div class="event">
|
||||
@@ -39,6 +41,14 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% 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 %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+58
-27
@@ -9,38 +9,69 @@ from .models import Event
|
||||
|
||||
|
||||
def day_page(request, year: int, month: int, day: int):
|
||||
try:
|
||||
year_data = YearData.objects.get(number=year)
|
||||
except YearData.DoesNotExist:
|
||||
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||
params = None
|
||||
|
||||
try:
|
||||
year_id = getattr(year_data, 'id')
|
||||
except AttributeError:
|
||||
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||
if not params:
|
||||
try:
|
||||
year_data = YearData.objects.get(number=year)
|
||||
except YearData.DoesNotExist:
|
||||
params = {'type': 'error', 'error_type': 'year'}
|
||||
|
||||
try:
|
||||
month_data = MonthData.objects.get(number=month)
|
||||
except MonthData.DoesNotExist:
|
||||
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||
if not params:
|
||||
try:
|
||||
year_id = getattr(year_data, 'id')
|
||||
except AttributeError:
|
||||
params = {'type': 'error', 'error_type': 'year'}
|
||||
|
||||
try:
|
||||
month_id = getattr(month_data, 'id')
|
||||
except AttributeError:
|
||||
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||
if not params:
|
||||
try:
|
||||
month_data = MonthData.objects.get(number=month)
|
||||
except MonthData.DoesNotExist:
|
||||
params = {'type': 'error', 'error_type': 'month'}
|
||||
|
||||
try:
|
||||
events = Event.objects.filter(year=year_id, month=month_id, day=day)
|
||||
except Event.DoesNotExist:
|
||||
return HttpResponseNotFound(f'<h1>404 Not Found</h1>')
|
||||
if not params:
|
||||
try:
|
||||
month_id = getattr(month_data, 'id')
|
||||
except AttributeError:
|
||||
params = {'type': 'error', 'error_type': 'month'}
|
||||
|
||||
params = {
|
||||
'type': 'day',
|
||||
'year_data': year_data,
|
||||
'month_data': month_data,
|
||||
'day': day,
|
||||
'events': events,
|
||||
}
|
||||
if not params:
|
||||
try:
|
||||
events = Event.objects.filter(year=year_id, month=month_id, day=day)
|
||||
except Event.DoesNotExist:
|
||||
params = {'type': 'error', 'error_type': '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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user