From 502ce785d4b6131dfa95a6581a034c6b3c748968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 7 Aug 2016 15:49:30 +0200 Subject: [PATCH] Adding event detail page --- bornhack/static_src/css/bornhack.css | 6 +++++ program/migrations/0005_auto_20160807_1312.py | 26 +++++++++++++++++++ program/migrations/0006_auto_20160807_1320.py | 20 ++++++++++++++ program/migrations/0007_auto_20160807_1333.py | 20 ++++++++++++++ program/models.py | 10 ++++++- program/templates/program_day.html | 5 ++-- program/templates/program_event_detail.html | 10 +++++++ program/templates/program_overview.html | 7 ++--- program/urls.py | 7 ++--- program/views.py | 12 ++++++++- 10 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 program/migrations/0005_auto_20160807_1312.py create mode 100644 program/migrations/0006_auto_20160807_1320.py create mode 100644 program/migrations/0007_auto_20160807_1333.py create mode 100644 program/templates/program_event_detail.html diff --git a/bornhack/static_src/css/bornhack.css b/bornhack/static_src/css/bornhack.css index b9660a9d..62674b9b 100644 --- a/bornhack/static_src/css/bornhack.css +++ b/bornhack/static_src/css/bornhack.css @@ -122,3 +122,9 @@ footer { padding: 5px; flex: 1 1 auto; } + +.event:hover { + background-color: black !important; + color: white !important; + text-decoration: none; +} diff --git a/program/migrations/0005_auto_20160807_1312.py b/program/migrations/0005_auto_20160807_1312.py new file mode 100644 index 00000000..ffe56c25 --- /dev/null +++ b/program/migrations/0005_auto_20160807_1312.py @@ -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'), + ), + ] diff --git a/program/migrations/0006_auto_20160807_1320.py b/program/migrations/0006_auto_20160807_1320.py new file mode 100644 index 00000000..e26841e8 --- /dev/null +++ b/program/migrations/0006_auto_20160807_1320.py @@ -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), + ), + ] diff --git a/program/migrations/0007_auto_20160807_1333.py b/program/migrations/0007_auto_20160807_1333.py new file mode 100644 index 00000000..fe9ba2a2 --- /dev/null +++ b/program/migrations/0007_auto_20160807_1333.py @@ -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', + ), + ] diff --git a/program/models.py b/program/models.py index 6568acc8..a1b5ba29 100644 --- a/program/models.py +++ b/program/models.py @@ -1,6 +1,8 @@ from __future__ import unicode_literals from django.db import models +from django.utils.text import slugify + from utils.models import CreatedUpdatedModel @@ -18,7 +20,8 @@ class EventType(CreatedUpdatedModel): class Event(CreatedUpdatedModel): """ Something that is on the program. """ 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) days = models.ManyToManyField('camps.Day') start = models.TimeField() @@ -27,6 +30,11 @@ class Event(CreatedUpdatedModel): def __str__(self): return self.title + def save(self, **kwargs): + if not self.slug: + self.slug = slugify(self.title) + super(Event, self).save(**kwargs) + class Speaker(CreatedUpdatedModel): """ Person anchoring an event. """ diff --git a/program/templates/program_day.html b/program/templates/program_day.html index bbd2eece..fab9de23 100644 --- a/program/templates/program_day.html +++ b/program/templates/program_day.html @@ -9,12 +9,13 @@
{% endifchanged %} -
{{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }}
{{ event }} -
+ {% endfor %} diff --git a/program/templates/program_event_detail.html b/program/templates/program_event_detail.html new file mode 100644 index 00000000..de155ea5 --- /dev/null +++ b/program/templates/program_event_detail.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/program/templates/program_overview.html b/program/templates/program_overview.html index 59bd9dd6..d48630c8 100644 --- a/program/templates/program_overview.html +++ b/program/templates/program_overview.html @@ -17,12 +17,13 @@ {{ day.date|date:"D d/m" }}
{% for event in events %} - + {% endfor %}

diff --git a/program/urls.py b/program/urls.py index 964bc4e3..2871b5a2 100644 --- a/program/urls.py +++ b/program/urls.py @@ -1,7 +1,8 @@ from django.conf.urls import url -from views import * +from . import views urlpatterns = [ - url(r'^(?P\d{4})-(?P\d{2})-(?P\d{2})$', ProgramDayView.as_view(), name='day'), - url(r'^$', ProgramOverviewView.as_view(), name='index'), + url(r'^(?P[-_\w+]+)/$', views.EventDetailView.as_view(), name='event'), + url(r'^(?P\d{4})-(?P\d{2})-(?P\d{2})$', views.ProgramDayView.as_view(), name='day'), + url(r'^$', views.ProgramOverviewView.as_view(), name='index'), ] diff --git a/program/views.py b/program/views.py index c5972b50..3cdba13e 100644 --- a/program/views.py +++ b/program/views.py @@ -1,7 +1,7 @@ from collections import OrderedDict import datetime -from django.views.generic import ListView, TemplateView +from django.views.generic import ListView, TemplateView, DetailView from camps.models import Day from . import models @@ -57,3 +57,13 @@ class ProgramDayView(TemplateView): context['days'] = Day.objects.filter(date__year=year) 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