From 1b2cdeffb0e9961727aa65fadc6f2444b9a94cee Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Wed, 19 Sep 2012 20:03:30 -0600 Subject: [PATCH] fixed URLs and views to use section slug correctly --- symposion/schedule/models.py | 1 - symposion/schedule/urls.py | 9 ++--- symposion/schedule/views.py | 34 +++++++++++-------- symposion/templates/schedule/_grid.html | 4 +-- symposion/templates/schedule/_slot_edit.html | 2 +- .../templates/schedule/schedule_edit.html | 1 - 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/symposion/schedule/models.py b/symposion/schedule/models.py index 9aac2b30..8c6add5a 100644 --- a/symposion/schedule/models.py +++ b/symposion/schedule/models.py @@ -11,7 +11,6 @@ from symposion.conference.models import Section class Schedule(models.Model): section = models.OneToOneField(Section) - slug = models.SlugField(unique=True) class Day(models.Model): diff --git a/symposion/schedule/urls.py b/symposion/schedule/urls.py index d259a016..dddbcdb6 100644 --- a/symposion/schedule/urls.py +++ b/symposion/schedule/urls.py @@ -2,10 +2,11 @@ from django.conf.urls.defaults import url, patterns urlpatterns = patterns("symposion.schedule.views", - url(r"^$", "schedule_detail", name="schedule_detail_singleton"), - url(r"^edit/$", "schedule_edit", name="schedule_edit_singleton"), + url(r"^$", "schedule_detail", name="schedule_detail_slugless"), + url(r"^edit/$", "schedule_edit", name="schedule_edit_slugless"), url(r"^(\w+)/edit/$", "schedule_detail", name="schedule_detail"), url(r"^(\w+)/edit/$", "schedule_edit", name="schedule_edit"), - url(r"^edit/slot/(?P\d+)/", "schedule_slot_edit", name="schedule_slot_edit"), - url(r"^list/$", "schedule_list", name="schedule_list"), + url(r"^(\w+)/edit/slot/(\d+)/", "schedule_slot_edit", name="schedule_slot_edit"), + url(r"^list/$", "schedule_list", name="schedule_list_slugless"), + url(r"^(\w+)/list/$", "schedule_list", name="schedule_list"), ) diff --git a/symposion/schedule/views.py b/symposion/schedule/views.py index 0ef080ea..3e98f767 100644 --- a/symposion/schedule/views.py +++ b/symposion/schedule/views.py @@ -9,7 +9,7 @@ from symposion.schedule.models import Schedule, Day, Slot, Presentation from symposion.schedule.timetable import TimeTable -def schedule_detail(request, slug=None): +def fetch_schedule(slug): qs = Schedule.objects.all() if slug is None: @@ -17,7 +17,13 @@ def schedule_detail(request, slug=None): if schedule is None: raise Http404() else: - schedule = get_object_or_404(qs, slug=slug) + schedule = get_object_or_404(qs, section__slug=slug) + + return schedule + + +def schedule_detail(request, slug=None): + schedule = fetch_schedule(slug) ctx = { "schedule": schedule, @@ -25,8 +31,12 @@ def schedule_detail(request, slug=None): return render(request, "schedule/schedule_detail.html", ctx) -def schedule_list(request): - presentations = Presentation.objects.exclude(cancelled=True).order_by("id") +def schedule_list(request, slug=None): + schedule = fetch_schedule(slug) + + presentations = Presentation.objects.filter(section=schedule.section) + presentations = presentations.exclude(cancelled=True).order_by("id") + ctx = { "presentations": presentations, } @@ -39,14 +49,7 @@ def schedule_edit(request, slug=None): if not request.user.is_staff: raise Http404() - qs = Schedule.objects.all() - - if slug is None: - schedule = next(iter(qs), None) - if schedule is None: - raise Http404() - else: - schedule = get_object_or_404(qs, slug=slug) + schedule = fetch_schedule(slug) days_qs = Day.objects.filter(schedule=schedule) days = [TimeTable(day) for day in days_qs] @@ -58,12 +61,12 @@ def schedule_edit(request, slug=None): @login_required -def schedule_slot_edit(request, slot_pk): +def schedule_slot_edit(request, slug, slot_pk): if not request.user.is_staff: raise Http404() - slot = get_object_or_404(Slot, pk=slot_pk) + slot = get_object_or_404(Slot, day__schedule__section__slug=slug, pk=slot_pk) # slot content try: @@ -79,10 +82,11 @@ def schedule_slot_edit(request, slot_pk): slot.unassign() else: slot.assign(presentation) - return redirect("schedule_edit_singleton") + return redirect("schedule_edit_slugless") else: form = SlotEditForm(content=content) ctx = { + "slug": slug, "form": form, "slot": slot, } diff --git a/symposion/templates/schedule/_grid.html b/symposion/templates/schedule/_grid.html index 87cc1c5e..cb4ffe1a 100644 --- a/symposion/templates/schedule/_grid.html +++ b/symposion/templates/schedule/_grid.html @@ -12,9 +12,9 @@ {% if slot.kind.label == "talk" %} {% if not slot.content %} - + + + {% else %} - +
{{ slot.content.speaker }}
{% endif %} {% else %} diff --git a/symposion/templates/schedule/_slot_edit.html b/symposion/templates/schedule/_slot_edit.html index 442012f7..d8b5ae9e 100644 --- a/symposion/templates/schedule/_slot_edit.html +++ b/symposion/templates/schedule/_slot_edit.html @@ -1,5 +1,5 @@ {% load i18n bootstrap_tags %} -