Program pages are beginning to look like something

This commit is contained in:
Víðir Valberg Guðmundsson 2016-08-04 23:03:39 +02:00 committed by Víðir Valberg Guðmundsson
parent 7a78c4f9d6
commit e8476bea51
13 changed files with 208 additions and 31 deletions

View file

@ -113,3 +113,10 @@ footer {
.nav li a {
padding: 30px 7px;
}
.event {
width: 100px;
display: inline-block;
margin: 0 5px;
padding: 5px;
}

View file

@ -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'},
),
]

View file

@ -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
]

View file

@ -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,
),
]

View file

@ -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),
),
]

View file

@ -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',
),
]

View file

@ -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):

View file

@ -1,18 +0,0 @@
{% extends 'base.html' %}
{% block content %}
{% for day, events in days.items %}
<div class="row">
{{ day }} <br />
{% for event in events %}
<div class="btn btn-default">
{{ event }}
</div>
{% endfor %}
<hr />
</div>
{% endfor %}
{% endblock %}

View file

@ -0,0 +1,23 @@
{% extends 'base.html' %}
{% block content %}
<a href="{% url 'program:index' %}" class="btn btn-default" style="display: inline-block; padding: 5px;">
Overview
</a>
{% for day in days %}
{% with day.date|date:"m" as month_padded %}
{% with day.date|date:"d" as day_padded %}
<a href="{% url 'program:day' year=day.date.year month=month_padded day=day_padded %}" class="btn btn-default" style="display: inline-block; padding: 5px;">
{{ day.date|date:"l" }}
</a>
{% endwith %}
{% endwith %}
{% endfor %}
<hr />
{% block program_content %}
{% endblock %}
{% endblock %}

View file

@ -0,0 +1,9 @@
{% extends 'program_base.html' %}
{% block program_content %}
{% for event in events %}
{{ event }}
{% endfor %}
{% endblock %}

View file

@ -0,0 +1,30 @@
{% extends 'program_base.html' %}
{% block program_content %}
<a href="{% url 'program:index' %}" style="background-color: black; border: 0; color: white; display: inline-block; padding: 5px;">
All
</a>
{% for event_type in event_types %}
<a href="{% url 'program:index' %}?type={{ event_type.slug }}" style="background-color: {{ event_type.color }}; border: 0; {% if event_type.light_text %}color: white;{% endif %}; display: inline-block; padding: 5px;">
{{ event_type.name }}
</a>
{% endfor %}
<hr />
{% for day, events in day_events.items %}
{{ day.date|date:"D d/m" }} <br />
<div style="display: flex; flex-wrap: wrap;">
{% for event in events %}
<div class="event"
style="background-color: {{ event.event_type.color }}; border: 0; {% if event.event_type.light_text %}color: white;{% endif %};">
<small>{{ event.start|date:"H:i" }} - {{ event.end|date:"H:i" }}</small>
{{ event }}
</div>
{% endfor %}
</div>
<hr />
{% endfor %}
{% endblock %}

View file

@ -2,5 +2,6 @@ from django.conf.urls import url
from views import *
urlpatterns = [
url(r'^$', ProgramView.as_view(), name='index')
url(r'^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$', ProgramDayView.as_view(), name='day'),
url(r'^$', ProgramOverviewView.as_view(), name='index'),
]

View file

@ -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