From 99f79e0ca2f040f8e1fe3a9032bbf73db7bf8a88 Mon Sep 17 00:00:00 2001 From: Ronni Elken Lindsgaard Date: Wed, 13 Jul 2016 19:13:47 +0200 Subject: [PATCH 1/8] WIP program app --- program/__init__.py | 0 program/admin.py | 6 +++ program/apps.py | 7 ++++ program/migrations/0001_initial.py | 63 ++++++++++++++++++++++++++++++ program/migrations/__init__.py | 0 program/models.py | 29 ++++++++++++++ program/tests.py | 3 ++ program/urls.py | 6 +++ program/views.py | 3 ++ 9 files changed, 117 insertions(+) create mode 100644 program/__init__.py create mode 100644 program/admin.py create mode 100644 program/apps.py create mode 100644 program/migrations/0001_initial.py create mode 100644 program/migrations/__init__.py create mode 100644 program/models.py create mode 100644 program/tests.py create mode 100644 program/urls.py create mode 100644 program/views.py diff --git a/program/__init__.py b/program/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/program/admin.py b/program/admin.py new file mode 100644 index 00000000..abaaceda --- /dev/null +++ b/program/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from .models import Event, Speaker + +admin.site.register(Event) +admin.site.register(Speaker) diff --git a/program/apps.py b/program/apps.py new file mode 100644 index 00000000..42b3e8ae --- /dev/null +++ b/program/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class ProgramConfig(AppConfig): + name = 'program' diff --git a/program/migrations/0001_initial.py b/program/migrations/0001_initial.py new file mode 100644 index 00000000..9aefd2fd --- /dev/null +++ b/program/migrations/0001_initial.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-07-03 17:17 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Event', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('title', models.CharField(max_length=255)), + ('description', models.TextField()), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='EventType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=100)), + ('slug', models.SlugField()), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Speaker', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=150)), + ('biography', models.TextField()), + ('picture', models.ImageField(upload_to=b'')), + ('events', models.ManyToManyField(related_name='speakers', related_query_name='speaker', to='program.Event')), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='event', + name='event_type', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='program.EventType'), + ), + ] diff --git a/program/migrations/__init__.py b/program/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/program/models.py b/program/models.py new file mode 100644 index 00000000..09f765fc --- /dev/null +++ b/program/models.py @@ -0,0 +1,29 @@ +"""Model definitions for the program app.""" +from __future__ import unicode_literals + +from django.db import models +from utils.models import CreatedUpdatedModel + + +class EventType(CreatedUpdatedModel): + '''Every event needs to have a type.''' + name = models.CharField(max_length=100) + slug = models.SlugField() + + +class Event(CreatedUpdatedModel): + '''Something that is on the program.''' + title = models.CharField(max_length=255) + description = models.TextField() + event_type = models.ForeignKey( + EventType) + +class Speaker(CreatedUpdatedModel): + '''Person anchoring an event.''' + name = models.CharField(max_length=150) + biography = models.TextField() + picture = models.ImageField() + events = models.ManyToManyField( + Event, + related_name='speakers', + related_query_name='speaker') diff --git a/program/tests.py b/program/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/program/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/program/urls.py b/program/urls.py new file mode 100644 index 00000000..a185476a --- /dev/null +++ b/program/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from views import * + +urlpatterns = [ + url(r'^$', ProgramIndexView.as_view(), name='index') +] diff --git a/program/views.py b/program/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/program/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 5c00934027c7fdab99d04a943a1f021e31765167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Wed, 13 Jul 2016 21:44:09 +0200 Subject: [PATCH 2/8] Resolve merge conflict. --- bornhack/settings/base.py | 1 + camps/models.py | 6 ++++++ program/admin.py | 20 +++++++++++++++++--- program/migrations/0001_initial.py | 8 ++++++-- program/models.py | 20 ++++++++++++-------- program/views.py | 1 - 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/bornhack/settings/base.py b/bornhack/settings/base.py index 269257f9..3505ecfc 100644 --- a/bornhack/settings/base.py +++ b/bornhack/settings/base.py @@ -30,6 +30,7 @@ INSTALLED_APPS = [ 'news', 'utils', 'villages', + 'program', 'allauth', 'allauth.account', diff --git a/camps/models.py b/camps/models.py index 881d225f..ea38b8c2 100644 --- a/camps/models.py +++ b/camps/models.py @@ -73,6 +73,12 @@ class Day(CreatedUpdatedModel, UUIDModel): help_text=_('What date?') ) + def __str__(self): + return '{} {}'.format( + self.date, + self.camp + ) + class Expense(CreatedUpdatedModel, UUIDModel): class Meta: diff --git a/program/admin.py b/program/admin.py index abaaceda..16c4604d 100644 --- a/program/admin.py +++ b/program/admin.py @@ -1,6 +1,20 @@ from django.contrib import admin -from .models import Event, Speaker +from .models import Event, Speaker, EventType + + +@admin.register(EventType) +class EventTypeAdmin(admin.ModelAdmin): + pass + + +@admin.register(Event) +class EventAdmin(admin.ModelAdmin): + pass + + +@admin.register(Speaker) +class SpeakerAdmin(admin.ModelAdmin): + pass + -admin.site.register(Event) -admin.site.register(Speaker) diff --git a/program/migrations/0001_initial.py b/program/migrations/0001_initial.py index 9aefd2fd..ade6047f 100644 --- a/program/migrations/0001_initial.py +++ b/program/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.7 on 2016-07-03 17:17 +# Generated by Django 1.9.6 on 2016-07-13 19:38 from __future__ import unicode_literals from django.db import migrations, models @@ -11,6 +11,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ('camps', '0005_auto_20160510_2011'), ] operations = [ @@ -22,6 +23,9 @@ class Migration(migrations.Migration): ('updated', models.DateTimeField(auto_now=True)), ('title', models.CharField(max_length=255)), ('description', models.TextField()), + ('start', models.TimeField()), + ('end', models.TimeField()), + ('days', models.ManyToManyField(to='camps.Day')), ], options={ 'abstract': False, @@ -48,7 +52,7 @@ class Migration(migrations.Migration): ('updated', models.DateTimeField(auto_now=True)), ('name', models.CharField(max_length=150)), ('biography', models.TextField()), - ('picture', models.ImageField(upload_to=b'')), + ('picture', models.ImageField(blank=True, null=True, upload_to=b'')), ('events', models.ManyToManyField(related_name='speakers', related_query_name='speaker', to='program.Event')), ], options={ diff --git a/program/models.py b/program/models.py index 09f765fc..6a9acbe6 100644 --- a/program/models.py +++ b/program/models.py @@ -1,29 +1,33 @@ -"""Model definitions for the program app.""" from __future__ import unicode_literals from django.db import models +from django.contrib.postgres.fields import DateTimeRangeField from utils.models import CreatedUpdatedModel class EventType(CreatedUpdatedModel): - '''Every event needs to have a type.''' + """ Every event needs to have a type. """ name = models.CharField(max_length=100) slug = models.SlugField() class Event(CreatedUpdatedModel): - '''Something that is on the program.''' + """ Something that is on the program. """ title = models.CharField(max_length=255) description = models.TextField() - event_type = models.ForeignKey( - EventType) + event_type = models.ForeignKey(EventType) + days = models.ManyToManyField('camps.Day') + start = models.TimeField() + end = models.TimeField() + class Speaker(CreatedUpdatedModel): - '''Person anchoring an event.''' + """ Person anchoring an event. """ name = models.CharField(max_length=150) biography = models.TextField() - picture = models.ImageField() + picture = models.ImageField(null=True, blank=True) events = models.ManyToManyField( Event, related_name='speakers', - related_query_name='speaker') + related_query_name='speaker' + ) diff --git a/program/views.py b/program/views.py index 91ea44a2..28002783 100644 --- a/program/views.py +++ b/program/views.py @@ -1,3 +1,2 @@ from django.shortcuts import render -# Create your views here. From 3cf837e8e93f95177d65dee3a2a12a141656679d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Wed, 13 Jul 2016 22:37:20 +0200 Subject: [PATCH 3/8] Getting first view up and running. --- bornhack/urls.py | 4 ++++ camps/models.py | 7 ++++--- program/admin.py | 14 +++++++++++++- program/models.py | 10 +++++++++- program/templates/program.html | 10 ++++++++++ program/urls.py | 2 +- program/views.py | 26 +++++++++++++++++++++++++- 7 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 program/templates/program.html diff --git a/bornhack/urls.py b/bornhack/urls.py index 5cdd323b..433c95eb 100644 --- a/bornhack/urls.py +++ b/bornhack/urls.py @@ -78,6 +78,10 @@ urlpatterns = [ r'^villages/', include('villages.urls', namespace='villages') ), + url( + r'^program/', + include('program.urls', namespace='program') + ), url(r'^accounts/', include('allauth.urls')), url(r'^admin/', include(admin.site.urls)), ] diff --git a/camps/models.py b/camps/models.py index ea38b8c2..bcbeb731 100644 --- a/camps/models.py +++ b/camps/models.py @@ -60,6 +60,7 @@ class Day(CreatedUpdatedModel, UUIDModel): class Meta: verbose_name = _('Day') verbose_name_plural = _('Days') + ordering = ['date'] camp = models.ForeignKey( 'camps.Camp', @@ -74,9 +75,9 @@ class Day(CreatedUpdatedModel, UUIDModel): ) def __str__(self): - return '{} {}'.format( - self.date, - self.camp + return '{} ({})'.format( + self.date.strftime('%A'), + self.date ) diff --git a/program/admin.py b/program/admin.py index 16c4604d..f85fec27 100644 --- a/program/admin.py +++ b/program/admin.py @@ -10,7 +10,19 @@ class EventTypeAdmin(admin.ModelAdmin): @admin.register(Event) class EventAdmin(admin.ModelAdmin): - pass + list_display = [ + 'title', + 'event_type', + 'get_days', + 'start', + 'end' + ] + + def get_days(self, obj): + return ', '.join([ + str(day.date.strftime('%a')) + for day in obj.days.all() + ]) @admin.register(Speaker) diff --git a/program/models.py b/program/models.py index 6a9acbe6..d0d379b6 100644 --- a/program/models.py +++ b/program/models.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals from django.db import models -from django.contrib.postgres.fields import DateTimeRangeField from utils.models import CreatedUpdatedModel @@ -10,6 +9,9 @@ class EventType(CreatedUpdatedModel): name = models.CharField(max_length=100) slug = models.SlugField() + def __str__(self): + return self.name + class Event(CreatedUpdatedModel): """ Something that is on the program. """ @@ -20,6 +22,9 @@ class Event(CreatedUpdatedModel): start = models.TimeField() end = models.TimeField() + def __str__(self): + return self.title + class Speaker(CreatedUpdatedModel): """ Person anchoring an event. """ @@ -31,3 +36,6 @@ class Speaker(CreatedUpdatedModel): related_name='speakers', related_query_name='speaker' ) + + def __str__(self): + return self.name diff --git a/program/templates/program.html b/program/templates/program.html new file mode 100644 index 00000000..de155ea5 --- /dev/null +++ b/program/templates/program.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/program/urls.py b/program/urls.py index a185476a..be495518 100644 --- a/program/urls.py +++ b/program/urls.py @@ -2,5 +2,5 @@ from django.conf.urls import url from views import * urlpatterns = [ - url(r'^$', ProgramIndexView.as_view(), name='index') + url(r'^$', ProgramView.as_view(), name='index') ] diff --git a/program/views.py b/program/views.py index 28002783..cf759bf9 100644 --- a/program/views.py +++ b/program/views.py @@ -1,2 +1,26 @@ -from django.shortcuts import render +from collections import OrderedDict + +from django.views.generic import ListView + +from camps.models import Day +from . import models + + +class ProgramView(ListView): + model = models.Event + template_name = 'program.html' + + def get_context_data(self, **kwargs): + context = super( + ProgramView, self + ).get_context_data(**kwargs) + + days = Day.objects.all() + + context['days'] = OrderedDict([ + (day, self.get_queryset().filter(days__in=[day])) + for day in days + ]) + + return context From 7a78c4f9d62ba1242b59009e9da44824528913e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 14 Jul 2016 08:53:09 +0200 Subject: [PATCH 4/8] Fixing template. --- program/templates/program.html | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/program/templates/program.html b/program/templates/program.html index de155ea5..0f0890cd 100644 --- a/program/templates/program.html +++ b/program/templates/program.html @@ -1,10 +1,18 @@ - - - - - Title - - +{% extends 'base.html' %} - - \ No newline at end of file +{% block content %} + + {% for day, events in days.items %} +
+ {{ day }}
+ {% for event in events %} +
+ {{ event }} +
+ {% endfor %} +
+
+ {% endfor %} + + +{% endblock %} From e8476bea51c7bb4367513b6199d33e1cf7787eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 4 Aug 2016 23:03:39 +0200 Subject: [PATCH 5/8] Program pages are beginning to look like something --- bornhack/static_src/css/bornhack.css | 7 +++ camps/migrations/0006_auto_20160804_1705.py | 19 ++++++++ program/admin.py | 19 +++++--- program/migrations/0002_eventtype_color.py | 21 +++++++++ .../0003_eventtype_light_writing.py | 20 +++++++++ program/migrations/0004_auto_20160804_1712.py | 20 +++++++++ program/models.py | 5 ++- program/templates/program.html | 18 -------- program/templates/program_base.html | 23 ++++++++++ program/templates/program_day.html | 9 ++++ program/templates/program_overview.html | 30 +++++++++++++ program/urls.py | 3 +- program/views.py | 45 ++++++++++++++++--- 13 files changed, 208 insertions(+), 31 deletions(-) create mode 100644 camps/migrations/0006_auto_20160804_1705.py create mode 100644 program/migrations/0002_eventtype_color.py create mode 100644 program/migrations/0003_eventtype_light_writing.py create mode 100644 program/migrations/0004_auto_20160804_1712.py delete mode 100644 program/templates/program.html create mode 100644 program/templates/program_base.html create mode 100644 program/templates/program_day.html create mode 100644 program/templates/program_overview.html diff --git a/bornhack/static_src/css/bornhack.css b/bornhack/static_src/css/bornhack.css index 4653efef..d26e0f8b 100644 --- a/bornhack/static_src/css/bornhack.css +++ b/bornhack/static_src/css/bornhack.css @@ -113,3 +113,10 @@ footer { .nav li a { padding: 30px 7px; } + +.event { + width: 100px; + display: inline-block; + margin: 0 5px; + padding: 5px; +} diff --git a/camps/migrations/0006_auto_20160804_1705.py b/camps/migrations/0006_auto_20160804_1705.py new file mode 100644 index 00000000..8ae75891 --- /dev/null +++ b/camps/migrations/0006_auto_20160804_1705.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-08-04 17:05 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('camps', '0005_auto_20160510_2011'), + ] + + operations = [ + migrations.AlterModelOptions( + name='day', + options={'ordering': ['date'], 'verbose_name': 'Day', 'verbose_name_plural': 'Days'}, + ), + ] diff --git a/program/admin.py b/program/admin.py index f85fec27..5256637a 100644 --- a/program/admin.py +++ b/program/admin.py @@ -8,6 +8,15 @@ class EventTypeAdmin(admin.ModelAdmin): pass +@admin.register(Speaker) +class SpeakerAdmin(admin.ModelAdmin): + pass + + +class SpeakerInline(admin.StackedInline): + model = Speaker.events.through + + @admin.register(Event) class EventAdmin(admin.ModelAdmin): list_display = [ @@ -15,7 +24,7 @@ class EventAdmin(admin.ModelAdmin): 'event_type', 'get_days', 'start', - 'end' + 'end', ] def get_days(self, obj): @@ -24,9 +33,9 @@ class EventAdmin(admin.ModelAdmin): for day in obj.days.all() ]) - -@admin.register(Speaker) -class SpeakerAdmin(admin.ModelAdmin): - pass + inlines = [ + SpeakerInline + ] + diff --git a/program/migrations/0002_eventtype_color.py b/program/migrations/0002_eventtype_color.py new file mode 100644 index 00000000..b7f91fc3 --- /dev/null +++ b/program/migrations/0002_eventtype_color.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-08-04 17:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('program', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='eventtype', + name='color', + field=models.CharField(default='#ff0000', max_length=50), + preserve_default=False, + ), + ] diff --git a/program/migrations/0003_eventtype_light_writing.py b/program/migrations/0003_eventtype_light_writing.py new file mode 100644 index 00000000..7d4dac56 --- /dev/null +++ b/program/migrations/0003_eventtype_light_writing.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-08-04 17:11 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('program', '0002_eventtype_color'), + ] + + operations = [ + migrations.AddField( + model_name='eventtype', + name='light_writing', + field=models.BooleanField(default=False), + ), + ] diff --git a/program/migrations/0004_auto_20160804_1712.py b/program/migrations/0004_auto_20160804_1712.py new file mode 100644 index 00000000..e93a05c1 --- /dev/null +++ b/program/migrations/0004_auto_20160804_1712.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-08-04 17:12 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('program', '0003_eventtype_light_writing'), + ] + + operations = [ + migrations.RenameField( + model_name='eventtype', + old_name='light_writing', + new_name='light_text', + ), + ] diff --git a/program/models.py b/program/models.py index d0d379b6..6568acc8 100644 --- a/program/models.py +++ b/program/models.py @@ -8,6 +8,8 @@ class EventType(CreatedUpdatedModel): """ Every event needs to have a type. """ name = models.CharField(max_length=100) slug = models.SlugField() + color = models.CharField(max_length=50) + light_text = models.BooleanField(default=False) def __str__(self): return self.name @@ -34,7 +36,8 @@ class Speaker(CreatedUpdatedModel): events = models.ManyToManyField( Event, related_name='speakers', - related_query_name='speaker' + related_query_name='speaker', + blank=True, ) def __str__(self): diff --git a/program/templates/program.html b/program/templates/program.html deleted file mode 100644 index 0f0890cd..00000000 --- a/program/templates/program.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - - {% for day, events in days.items %} -
- {{ day }}
- {% for event in events %} -
- {{ event }} -
- {% endfor %} -
-
- {% endfor %} - - -{% endblock %} diff --git a/program/templates/program_base.html b/program/templates/program_base.html new file mode 100644 index 00000000..40987e9f --- /dev/null +++ b/program/templates/program_base.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} + +{% block content %} + + + Overview + +{% for day in days %} +{% with day.date|date:"m" as month_padded %} +{% with day.date|date:"d" as day_padded %} + + {{ day.date|date:"l" }} + +{% endwith %} +{% endwith %} +{% endfor %} + +
+ +{% block program_content %} +{% endblock %} + +{% endblock %} diff --git a/program/templates/program_day.html b/program/templates/program_day.html new file mode 100644 index 00000000..4f41278b --- /dev/null +++ b/program/templates/program_day.html @@ -0,0 +1,9 @@ +{% extends 'program_base.html' %} + +{% block program_content %} + +{% for event in events %} + {{ event }} +{% endfor %} + +{% endblock %} diff --git a/program/templates/program_overview.html b/program/templates/program_overview.html new file mode 100644 index 00000000..8e46e415 --- /dev/null +++ b/program/templates/program_overview.html @@ -0,0 +1,30 @@ +{% extends 'program_base.html' %} + +{% block program_content %} + + + All + +{% for event_type in event_types %} + + {{ event_type.name }} + +{% endfor %} + +
+ +{% for day, events in day_events.items %} + {{ day.date|date:"D d/m" }}
+
+ {% for event in events %} +
+ {{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }} + {{ event }} +
+ {% endfor %} +
+
+{% endfor %} + +{% endblock %} diff --git a/program/urls.py b/program/urls.py index be495518..964bc4e3 100644 --- a/program/urls.py +++ b/program/urls.py @@ -2,5 +2,6 @@ from django.conf.urls import url from views import * urlpatterns = [ - url(r'^$', ProgramView.as_view(), name='index') + url(r'^(?P\d{4})-(?P\d{2})-(?P\d{2})$', ProgramDayView.as_view(), name='day'), + url(r'^$', ProgramOverviewView.as_view(), name='index'), ] diff --git a/program/views.py b/program/views.py index cf759bf9..590aff58 100644 --- a/program/views.py +++ b/program/views.py @@ -1,26 +1,59 @@ from collections import OrderedDict -from django.views.generic import ListView +import datetime +from django.views.generic import ListView, TemplateView from camps.models import Day from . import models -class ProgramView(ListView): +class ProgramOverviewView(ListView): model = models.Event - template_name = 'program.html' + template_name = 'program_overview.html' def get_context_data(self, **kwargs): context = super( - ProgramView, self + ProgramOverviewView, self ).get_context_data(**kwargs) days = Day.objects.all() + context['days'] = days - context['days'] = OrderedDict([ - (day, self.get_queryset().filter(days__in=[day])) + filter = {} + if 'type' in self.request.GET: + event_type = self.request.GET['type'] + filter["event_type__slug"] = event_type + + context['day_events'] = OrderedDict([ + ( + day, + self.get_queryset().filter( + days__in=[day], + **filter + ).order_by( + 'start' + ) + ) for day in days ]) + context['event_types'] = models.EventType.objects.all() + + return context + + +class ProgramDayView(TemplateView): + template_name = 'program_day.html' + + def get_context_data(self, **kwargs): + context = super(ProgramDayView, self).get_context_data(**kwargs) + year = int(kwargs['year']) + month = int(kwargs['month']) + day = int(kwargs['day']) + date = datetime.date(year=year, month=month, day=day) + day = Day.objects.filter(date=date) + context['events'] = models.Event.objects.filter(days=day) + context['event_types'] = models.EventType.objects.all() + context['days'] = Day.objects.filter(date__year=year) return context From 06fda687959d2c698aa668e80ce1a11eb56629af 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 14:36:43 +0200 Subject: [PATCH 6/8] More program stuff. --- bornhack/static_src/css/bornhack.css | 6 ++++-- program/templates/program_day.html | 14 +++++++++++++- program/templates/program_overview.html | 5 +++-- program/views.py | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bornhack/static_src/css/bornhack.css b/bornhack/static_src/css/bornhack.css index d26e0f8b..b9660a9d 100644 --- a/bornhack/static_src/css/bornhack.css +++ b/bornhack/static_src/css/bornhack.css @@ -115,8 +115,10 @@ footer { } .event { - width: 100px; + max-width: 200px; + height: 100px; display: inline-block; - margin: 0 5px; + margin: 5px 5px; padding: 5px; + flex: 1 1 auto; } diff --git a/program/templates/program_day.html b/program/templates/program_day.html index 4f41278b..bbd2eece 100644 --- a/program/templates/program_day.html +++ b/program/templates/program_day.html @@ -3,7 +3,19 @@ {% block program_content %} {% for event in events %} - {{ event }} + {% ifchanged event.event_type %} + {% if not forloop.first %}{% endif %} +

{{ event.event_type }}

+
+ {% endifchanged %} + +
+ {{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }} +
+ {{ event }} +
+ {% endfor %} {% endblock %} diff --git a/program/templates/program_overview.html b/program/templates/program_overview.html index 8e46e415..59bd9dd6 100644 --- a/program/templates/program_overview.html +++ b/program/templates/program_overview.html @@ -6,7 +6,7 @@ All {% for event_type in event_types %} - + {{ event_type.name }} {% endfor %} @@ -18,8 +18,9 @@
{% for event in events %}
+ style="background-color: {{ event.event_type.color }}; border: 0; color: {% if event.event_type.light_text %}white{% else %}black{% endif %};"> {{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }} +
{{ event }}
{% endfor %} diff --git a/program/views.py b/program/views.py index 590aff58..c5972b50 100644 --- a/program/views.py +++ b/program/views.py @@ -52,7 +52,7 @@ class ProgramDayView(TemplateView): day = int(kwargs['day']) date = datetime.date(year=year, month=month, day=day) day = Day.objects.filter(date=date) - context['events'] = models.Event.objects.filter(days=day) + context['events'] = models.Event.objects.filter(days=day).order_by('start', 'event_type') context['event_types'] = models.EventType.objects.all() context['days'] = Day.objects.filter(date__year=year) return context 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 7/8] 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" }}

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 From ae72167c89f290a5d6c661b5755034536f9fd614 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:50:37 +0200 Subject: [PATCH 8/8] Whoops forgot the template --- program/templates/program_event_detail.html | 40 ++++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/program/templates/program_event_detail.html b/program/templates/program_event_detail.html index de155ea5..91e955fa 100644 --- a/program/templates/program_event_detail.html +++ b/program/templates/program_event_detail.html @@ -1,10 +1,32 @@ - - - - - Title - - +{% extends 'program_base.html' %} +{% load commonmark %} - - \ No newline at end of file +{% block program_content %} + +

+ + {{ event.event_type.name }} + + {{ event.title }} +

+ +

+ {{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }} at + {% for day in event.days.all %}{{ day.date|date:"l" }}{% if not forloop.last %}, {% endif %}{% endfor %}
+

+ +{{ event.abstract|commonmark }} + +
+ +{% if event.speakers.exists %} +{% for speaker in event.speakers.all %} + +

{{ speaker }}

+ {{ speaker.biography|commonmark }} + +{% endfor %} + +{% endif %} + +{% endblock %}