Added events on day page
This commit is contained in:
@@ -52,7 +52,7 @@ class CalendarData(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
day = models.SmallIntegerField('Number', unique=True, validators=[
|
day = models.SmallIntegerField('Number', validators=[
|
||||||
MinValueValidator(1),
|
MinValueValidator(1),
|
||||||
MaxValueValidator(30),
|
MaxValueValidator(30),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -53,3 +53,34 @@ table.month {
|
|||||||
width: 350px;
|
width: 350px;
|
||||||
max-width: 350px;
|
max-width: 350px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.event {
|
||||||
|
border: 1px solid black;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.event-time {
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 3px 5px;
|
||||||
|
margin-right: 15px;
|
||||||
|
float: left;
|
||||||
|
font-weight: bold;
|
||||||
|
background: DeepSkyBlue;
|
||||||
|
font-size: 150%;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.event-title {
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: underline;
|
||||||
|
font-size: 200%;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.event-description {
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,15 +12,34 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="calendarpage">
|
<div class="calendarpage">
|
||||||
<h1 class="title">Календарь</h1>
|
{% if type == 'year' %}
|
||||||
|
<h1 class="title">Календарь</h1>
|
||||||
|
<h2 class="year">{{year_data.number}}</h2>
|
||||||
|
{% elif type == 'day' %}
|
||||||
|
<h1 class="title">Календарь — События</h1>
|
||||||
|
<h2 class="year">Год {{year_data.number}}, {{month_data.name}}, день {{day}}-й</h2>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<h2 class="year">{{year_data.number}}</h2>
|
|
||||||
<div class="calendar">
|
<div class="calendar">
|
||||||
{% for month in month_data %}
|
{% if type == 'year' %}
|
||||||
{% if not month.is_leap_month or year_data.is_leap %}
|
{% for month in month_data %}
|
||||||
{% include 'faerun_calendar/month.html' with month=month calendar_data=calendar_data month_days=month_days events=events %}
|
{% if not month.is_leap_month or year_data.is_leap %}
|
||||||
|
{% include 'faerun_calendar/month.html' with month=month calendar_data=calendar_data month_days=month_days events=events %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% elif type == 'day' %}
|
||||||
|
{% if events.count == 0 %}
|
||||||
|
<p>Событий нет</p>
|
||||||
|
{% else %}
|
||||||
|
{% for event in events %}
|
||||||
|
<div class="event">
|
||||||
|
<div class="event-time">{{event.time}}</div>
|
||||||
|
<div class="event-title">{{event.title}}</div>
|
||||||
|
<p class="event-description">{{event.description}}</p>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -9,7 +9,40 @@ from .models import Event
|
|||||||
|
|
||||||
|
|
||||||
def day_page(request, year: int, month: int, day: int):
|
def day_page(request, year: int, month: int, day: int):
|
||||||
return HttpResponse(f'{year}.{month}.{day}')
|
try:
|
||||||
|
year_data = YearData.objects.get(number=year)
|
||||||
|
except YearData.DoesNotExist:
|
||||||
|
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||||
|
|
||||||
|
try:
|
||||||
|
year_id = getattr(year_data, 'id')
|
||||||
|
except AttributeError:
|
||||||
|
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||||
|
|
||||||
|
try:
|
||||||
|
month_data = MonthData.objects.get(number=month)
|
||||||
|
except MonthData.DoesNotExist:
|
||||||
|
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||||
|
|
||||||
|
try:
|
||||||
|
month_id = getattr(month_data, 'id')
|
||||||
|
except AttributeError:
|
||||||
|
return HttpResponseNotFound('<h1>404 Not Found</h1>')
|
||||||
|
|
||||||
|
try:
|
||||||
|
events = Event.objects.filter(year=year_id, month=month_id, day=day)
|
||||||
|
except Event.DoesNotExist:
|
||||||
|
return HttpResponseNotFound(f'<h1>404 Not Found</h1>')
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'type': 'day',
|
||||||
|
'year_data': year_data,
|
||||||
|
'month_data': month_data,
|
||||||
|
'day': day,
|
||||||
|
'events': events,
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, 'faerun_calendar/index.html', params)
|
||||||
|
|
||||||
|
|
||||||
def year_page(request, year: int):
|
def year_page(request, year: int):
|
||||||
@@ -23,6 +56,7 @@ def year_page(request, year: int):
|
|||||||
events = Event.objects.all()
|
events = Event.objects.all()
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
'type': 'year',
|
||||||
'calendar_data': calendar_data,
|
'calendar_data': calendar_data,
|
||||||
'year_data': year_data,
|
'year_data': year_data,
|
||||||
'month_data': month_data,
|
'month_data': month_data,
|
||||||
@@ -34,8 +68,6 @@ def year_page(request, year: int):
|
|||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
calendar_data = CalendarData.objects.first()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_year = getattr(getattr(CalendarData.objects.first(), 'current_year'), 'number')
|
current_year = getattr(getattr(CalendarData.objects.first(), 'current_year'), 'number')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|||||||
Reference in New Issue
Block a user