Skip to content

Commit

Permalink
Show the schedule (pybay#109)
Browse files Browse the repository at this point in the history
* Show the schedule

* add a fixture for schedule slots
  • Loading branch information
epsy authored and ccsv committed Feb 22, 2018
1 parent e8d9613 commit ef41ecd
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 2 deletions.
1 change: 1 addition & 0 deletions fixtures/schedule_slots.json

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions pybay/templates/frontend/schedule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

{% extends 'frontend/base.html' %}
{% load static %}
{% load thumbnail %}
{% load value_from_list_or_default %}

{% block content %}
<section class="code_of_conduct">
<div class="container schedule-page">
<div class="row">
<div>
<div class="blue-header">
<h1><strong>Schedule</strong></h1>
</div>
</div>
</div>

{% for schedule_days in schedules %}
<div class="sch-schedule">
<div class="sch-filters">
<span>Filter:</span>
<ul class="sch-filter-list">
<li data-filter="">All Talks</li>
{% for filter, name in filters %}
<li data-filter="{{ filter }}">{{ name }}</li>
{% endfor %}
</ul>
</div>

{% for day, slot_groups in schedule_days %}
<div class="sch-day">
<h2 class="sch-day-title">{{ day.date }}</h2>
<div class="sch-timeslots">
{% for time, slots, kind in slot_groups %}
<div class="sch-timeslot {% if kind %}sch-timeslot-special sch-timeslot-special-{{ kind }}{% endif %}">
<h3 class="sch-timeslot-time">{{ time }}</h3>
<div class="sch-timeslot-slots">
{% for slot in slots %}
{% if slot.content_override %}
<div class="sch-timeslot-slot sch-timeslot-kind-{{ slot.kind.label }} sch-timeslot-custom">
{{ slot.content_override }}
</div>
{% elif slot.content_ptr %}
{% with talk=slot.content_ptr %}
<div class="sch-timeslot-slot sch-timeslot-kind-{{ slot.kind.label }} sch-talk-level-{{ talk.proposal.audience_level }} sch-talk-{% value_from_list_or_default talk.proposal.category|cut:" " allowed_categories "other" %}">
{% if talk.speaker.photo %}<p class="sch-speaker-photo"><img src="{% thumbnail talk.speaker.photo '50x50' %}" alt="{{ talk.speaker.name }}" /></p>{% endif %}
<h4>{{ talk.title }}</h4>
<p class="sch-speaker">{{ talk.speaker.name }}</p>
{% if talk.speaker.photo %}<p class="sch-speaker-photo"><img src="{% thumbnail talk.speaker.photo '50x50' %}" alt="{{ talk.speaker.name }}" /></p>{% endif %}
<p class="sch-description">{{ talk.description }}</p>
<p class="sch-room">{{ slot.rooms|join:', ' }}</p>
<p class="sch-duration">{{ slot.length_in_minutes }} mins</p>
</div>
{% endwith %}
{% else %}
<div class="sch-timeslot-slot sch-timeslot-kind-{{ slot.kind.label }}">
<p>{{ slot.kind.label.title }}</p>
</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>

{% endfor %}
</div><!--container -->
</section>
{% endblock content %}

{% block scripts %}
<script src="{% static 'new/js/schedule-filters.js' %}" async></script>
<style type="text/css">
{% for slug, _ in filters %}
.sch-schedule-filter-{{ slug }} .sch-filter-list > li[data-filter="{{ slug }}"]{% if not forloop.last %},{% endif %}{% endfor %} {
background: #428bca;
color: white;
}

{% for slug, _ in filters %}
.sch-schedule-filter-{{ slug }} .sch-timeslot-kind-talk:not(.sch-talk-{{ slug }}){% if not forloop.last %},{% endif %} {% endfor %}{
opacity: .3;
}

@media(max-width: 450px) {
{% for slug, _ in filters %}
.sch-schedule-filter-{{ slug }} .sch-timeslot-kind-talk:not(.sch-talk-{{ slug }}){% if not forloop.last %},{% endif %} {% endfor %} {
display: none;
}
}

</style>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>Conference Schedule</h1>
{% cache 600 "schedule-table" section.schedule.section %}
{% for timetable in section.days %}
<h3>{{ section.schedule.section.name }} — {{ timetable.day.date }}</h3>
{% include "schedule/_grid.html" %}
{% include "symposion/schedule/_grid.html" %}
{% endfor %}
{% endcache %}
{% endfor %}
Expand Down
9 changes: 9 additions & 0 deletions pybay/templatetags/value_from_list_or_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.template import Library


register = Library()


@register.simple_tag
def value_from_list_or_default(val, allowed_values, default):
return val if val in allowed_values else default
3 changes: 2 additions & 1 deletion pybay/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
url(r"^reviews/", include("symposion.reviews.urls")),
url(r"^boxes/", include("pinax.boxes.urls")),

# url(r"^schedule/", include("symposion.schedule.urls")),
url(r"^schedule/", views.pybay_schedule),
url(r"^schedule-sym/", include("symposion.schedule.urls")),
# url(r"^account/signup/$", SignupView.as_view(), name="account_signup"),
# url(r"^account/login/$", symposion.views.LoginView.as_view(), name="account_login"),
# url(r"^teams/", include(teams_urls)),
Expand Down
46 changes: 46 additions & 0 deletions pybay/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import json
import itertools

from django.shortcuts import render
from django.http import (HttpResponse, HttpResponseForbidden,
HttpResponseNotFound)
from django.views.generic import TemplateView
from django.db.models import Prefetch

from .forms import CallForProposalForm
from pybay.faqs.models import Faq, Category
from symposion.sponsorship.models import Sponsor
from pybay.proposals.models import TalkProposal, Proposal
from pybay.utils import get_accepted_speaker_by_slug
from symposion.speakers.models import Speaker
from symposion.schedule.models import Schedule

from collections import defaultdict
from django.conf import settings
Expand Down Expand Up @@ -158,3 +161,46 @@ def proposal_detail(request, proposal_id):
return HttpResponse(
json.dumps({'data': result}), content_type="application/json"
)


def _day_slots(day):
groupby = itertools.groupby(day.slot_set.all(), lambda slot: slot.start)
for time, grouper in groupby:
slots = list(grouper)
kind = slots[0].kind if len(slots) == 1 and slots[0].content_override else ''
yield time, slots, kind


FILTER_CATEGORIES = [
"All things Web",
"DevOps",
]


def pybay_schedule(request):
if request.user.is_staff:
schedules = Schedule.objects.filter(hidden=False)
else:
schedules = Schedule.objects.filter(published=True, hidden=False)

schedules.prefetch_related(
Prefetch('day_set__slot_set__presentation_set__proposal_base'),
)

schedules = [
[(day, _day_slots(day)) for day in schedule.day_set.all()]
for schedule in schedules
]

filters = [
(name.lower().replace(' ', ''), name)
for name in FILTER_CATEGORIES
]

ctx = {
'schedules': schedules,
'filters' : filters + [('other', 'Other'), ('level-1', 'Beginner-friendly')],
'allowed_categories': [slug for slug, _ in filters]
}

return render(request, "frontend/schedule.html", ctx)
Loading

0 comments on commit ef41ecd

Please sign in to comment.