fixed URLs and views to use section slug correctly

This commit is contained in:
Brian Rosner 2012-09-19 20:03:30 -06:00
parent e3c18a4554
commit 1b2cdeffb0
6 changed files with 27 additions and 24 deletions

View file

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

View file

@ -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<slot_pk>\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"),
)

View file

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

View file

@ -12,9 +12,9 @@
<td class="slot slot-{{ slot.kind.label }}" colspan="{{ slot.colspan }}" rowspan="{{ slow.rowspan }}">
{% if slot.kind.label == "talk" %}
{% if not slot.content %}
<a class="btn btn-mini edit-slot" data-action="{% url schedule_slot_edit slot.pk %}" href="#">+</a>
<a class="btn btn-mini edit-slot" data-action="{% url schedule_slot_edit schedule.section.slug slot.pk %}" href="#">+</a>
{% else %}
<div class="title"><a class="edit-slot" data-action="{% url schedule_slot_edit slot.pk %}" href="#">{{ slot.content.title }}</a></div>
<div class="title"><a class="edit-slot" data-action="{% url schedule_slot_edit schedule.section.slug slot.pk %}" href="#">{{ slot.content.title }}</a></div>
<div class="speaker">{{ slot.content.speaker }}</div>
{% endif %}
{% else %}

View file

@ -1,5 +1,5 @@
{% load i18n bootstrap_tags %}
<form id="slotEditForm" class="modal-form" method="POST" action="{% url schedule_slot_edit slot.pk %}">
<form id="slotEditForm" class="modal-form" method="POST" action="{% url schedule_slot_edit slug slot.pk %}">
<div class="modal-header">
<a class="close" data-dismiss="modal">&times;</a>
<h3>{% trans "Edit Slot" %}</h3>

View file

@ -43,7 +43,6 @@
{% for timetable in days %}
<h2>{{ timetable.day.date }}</h2>
{% include "schedule/_grid.html" %}
{% endfor %}
</div>