Adding event detail page

This commit is contained in:
Víðir Valberg Guðmundsson 2016-08-07 15:49:30 +02:00
parent 06fda68795
commit 502ce785d4
10 changed files with 113 additions and 10 deletions

View file

@ -122,3 +122,9 @@ footer {
padding: 5px; padding: 5px;
flex: 1 1 auto; flex: 1 1 auto;
} }
.event:hover {
background-color: black !important;
color: white !important;
text-decoration: none;
}

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-07 13:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('program', '0004_auto_20160804_1712'),
]
operations = [
migrations.AddField(
model_name='event',
name='slug',
field=models.SlugField(default='', blank=True),
preserve_default=False,
),
migrations.AlterField(
model_name='speaker',
name='events',
field=models.ManyToManyField(blank=True, related_name='speakers', related_query_name='speaker', to='program.Event'),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-07 13:20
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('program', '0005_auto_20160807_1312'),
]
operations = [
migrations.AlterField(
model_name='event',
name='slug',
field=models.SlugField(blank=True, max_length=255),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-07 13:33
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('program', '0006_auto_20160807_1320'),
]
operations = [
migrations.RenameField(
model_name='event',
old_name='description',
new_name='abstract',
),
]

View file

@ -1,6 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models from django.db import models
from django.utils.text import slugify
from utils.models import CreatedUpdatedModel from utils.models import CreatedUpdatedModel
@ -18,7 +20,8 @@ class EventType(CreatedUpdatedModel):
class Event(CreatedUpdatedModel): class Event(CreatedUpdatedModel):
""" Something that is on the program. """ """ Something that is on the program. """
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
description = models.TextField() slug = models.SlugField(blank=True, max_length=255)
abstract = models.TextField()
event_type = models.ForeignKey(EventType) event_type = models.ForeignKey(EventType)
days = models.ManyToManyField('camps.Day') days = models.ManyToManyField('camps.Day')
start = models.TimeField() start = models.TimeField()
@ -27,6 +30,11 @@ class Event(CreatedUpdatedModel):
def __str__(self): def __str__(self):
return self.title return self.title
def save(self, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Event, self).save(**kwargs)
class Speaker(CreatedUpdatedModel): class Speaker(CreatedUpdatedModel):
""" Person anchoring an event. """ """ Person anchoring an event. """

View file

@ -9,12 +9,13 @@
<div style="display: flex; flex-wrap: wrap;"> <div style="display: flex; flex-wrap: wrap;">
{% endifchanged %} {% endifchanged %}
<div class="event" <a class="event"
href="{% url 'program:event' slug=event.slug %}"
style="background-color: {{ event.event_type.color }}; border: 0; color: {% if event.event_type.light_text %}white{% else %}black{% endif %};"> style="background-color: {{ event.event_type.color }}; border: 0; color: {% if event.event_type.light_text %}white{% else %}black{% endif %};">
<small>{{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }}</small> <small>{{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }}</small>
<br /> <br />
{{ event }} {{ event }}
</div> </a>
{% endfor %} {% endfor %}

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View file

@ -17,12 +17,13 @@
{{ day.date|date:"D d/m" }} <br /> {{ day.date|date:"D d/m" }} <br />
<div style="display: flex; flex-wrap: wrap;"> <div style="display: flex; flex-wrap: wrap;">
{% for event in events %} {% for event in events %}
<div class="event" <a class="event"
style="background-color: {{ event.event_type.color }}; border: 0; color: {% if event.event_type.light_text %}white{% else %}black{% endif %};"> href="{% url 'program:event' slug=event.slug %}"
style="background-color: {{ event.event_type.color }}; border: 0; color: {% if event.event_type.light_text %}white{% else %}black{% endif %};">
<small>{{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }}</small> <small>{{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }}</small>
<br /> <br />
{{ event }} {{ event }}
</div> </a>
{% endfor %} {% endfor %}
</div> </div>
<hr /> <hr />

View file

@ -1,7 +1,8 @@
from django.conf.urls import url from django.conf.urls import url
from views import * from . import views
urlpatterns = [ urlpatterns = [
url(r'^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$', ProgramDayView.as_view(), name='day'), url(r'^(?P<slug>[-_\w+]+)/$', views.EventDetailView.as_view(), name='event'),
url(r'^$', ProgramOverviewView.as_view(), name='index'), url(r'^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$', views.ProgramDayView.as_view(), name='day'),
url(r'^$', views.ProgramOverviewView.as_view(), name='index'),
] ]

View file

@ -1,7 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
import datetime import datetime
from django.views.generic import ListView, TemplateView from django.views.generic import ListView, TemplateView, DetailView
from camps.models import Day from camps.models import Day
from . import models from . import models
@ -57,3 +57,13 @@ class ProgramDayView(TemplateView):
context['days'] = Day.objects.filter(date__year=year) context['days'] = Day.objects.filter(date__year=year)
return context return context
class EventDetailView(DetailView):
model = models.Event
template_name = 'program_event_detail.html'
def get_context_data(self, **kwargs):
context = super(EventDetailView, self).get_context_data(**kwargs)
# TODO: date__year is hardcoded here - need fix for 2017 :P
context['days'] = Day.objects.filter(date__year=2016)
return context