fixed URLs and views to use section slug correctly
This commit is contained in:
parent
e3c18a4554
commit
1b2cdeffb0
6 changed files with 27 additions and 24 deletions
|
@ -11,7 +11,6 @@ from symposion.conference.models import Section
|
||||||
class Schedule(models.Model):
|
class Schedule(models.Model):
|
||||||
|
|
||||||
section = models.OneToOneField(Section)
|
section = models.OneToOneField(Section)
|
||||||
slug = models.SlugField(unique=True)
|
|
||||||
|
|
||||||
|
|
||||||
class Day(models.Model):
|
class Day(models.Model):
|
||||||
|
|
|
@ -2,10 +2,11 @@ from django.conf.urls.defaults import url, patterns
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns("symposion.schedule.views",
|
urlpatterns = patterns("symposion.schedule.views",
|
||||||
url(r"^$", "schedule_detail", name="schedule_detail_singleton"),
|
url(r"^$", "schedule_detail", name="schedule_detail_slugless"),
|
||||||
url(r"^edit/$", "schedule_edit", name="schedule_edit_singleton"),
|
url(r"^edit/$", "schedule_edit", name="schedule_edit_slugless"),
|
||||||
url(r"^(\w+)/edit/$", "schedule_detail", name="schedule_detail"),
|
url(r"^(\w+)/edit/$", "schedule_detail", name="schedule_detail"),
|
||||||
url(r"^(\w+)/edit/$", "schedule_edit", name="schedule_edit"),
|
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"^(\w+)/edit/slot/(\d+)/", "schedule_slot_edit", name="schedule_slot_edit"),
|
||||||
url(r"^list/$", "schedule_list", name="schedule_list"),
|
url(r"^list/$", "schedule_list", name="schedule_list_slugless"),
|
||||||
|
url(r"^(\w+)/list/$", "schedule_list", name="schedule_list"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from symposion.schedule.models import Schedule, Day, Slot, Presentation
|
||||||
from symposion.schedule.timetable import TimeTable
|
from symposion.schedule.timetable import TimeTable
|
||||||
|
|
||||||
|
|
||||||
def schedule_detail(request, slug=None):
|
def fetch_schedule(slug):
|
||||||
qs = Schedule.objects.all()
|
qs = Schedule.objects.all()
|
||||||
|
|
||||||
if slug is None:
|
if slug is None:
|
||||||
|
@ -17,7 +17,13 @@ def schedule_detail(request, slug=None):
|
||||||
if schedule is None:
|
if schedule is None:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
else:
|
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 = {
|
ctx = {
|
||||||
"schedule": schedule,
|
"schedule": schedule,
|
||||||
|
@ -25,8 +31,12 @@ def schedule_detail(request, slug=None):
|
||||||
return render(request, "schedule/schedule_detail.html", ctx)
|
return render(request, "schedule/schedule_detail.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
def schedule_list(request):
|
def schedule_list(request, slug=None):
|
||||||
presentations = Presentation.objects.exclude(cancelled=True).order_by("id")
|
schedule = fetch_schedule(slug)
|
||||||
|
|
||||||
|
presentations = Presentation.objects.filter(section=schedule.section)
|
||||||
|
presentations = presentations.exclude(cancelled=True).order_by("id")
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"presentations": presentations,
|
"presentations": presentations,
|
||||||
}
|
}
|
||||||
|
@ -39,14 +49,7 @@ def schedule_edit(request, slug=None):
|
||||||
if not request.user.is_staff:
|
if not request.user.is_staff:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
qs = Schedule.objects.all()
|
schedule = fetch_schedule(slug)
|
||||||
|
|
||||||
if slug is None:
|
|
||||||
schedule = next(iter(qs), None)
|
|
||||||
if schedule is None:
|
|
||||||
raise Http404()
|
|
||||||
else:
|
|
||||||
schedule = get_object_or_404(qs, slug=slug)
|
|
||||||
|
|
||||||
days_qs = Day.objects.filter(schedule=schedule)
|
days_qs = Day.objects.filter(schedule=schedule)
|
||||||
days = [TimeTable(day) for day in days_qs]
|
days = [TimeTable(day) for day in days_qs]
|
||||||
|
@ -58,12 +61,12 @@ def schedule_edit(request, slug=None):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def schedule_slot_edit(request, slot_pk):
|
def schedule_slot_edit(request, slug, slot_pk):
|
||||||
|
|
||||||
if not request.user.is_staff:
|
if not request.user.is_staff:
|
||||||
raise Http404()
|
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
|
# slot content
|
||||||
try:
|
try:
|
||||||
|
@ -79,10 +82,11 @@ def schedule_slot_edit(request, slot_pk):
|
||||||
slot.unassign()
|
slot.unassign()
|
||||||
else:
|
else:
|
||||||
slot.assign(presentation)
|
slot.assign(presentation)
|
||||||
return redirect("schedule_edit_singleton")
|
return redirect("schedule_edit_slugless")
|
||||||
else:
|
else:
|
||||||
form = SlotEditForm(content=content)
|
form = SlotEditForm(content=content)
|
||||||
ctx = {
|
ctx = {
|
||||||
|
"slug": slug,
|
||||||
"form": form,
|
"form": form,
|
||||||
"slot": slot,
|
"slot": slot,
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
<td class="slot slot-{{ slot.kind.label }}" colspan="{{ slot.colspan }}" rowspan="{{ slow.rowspan }}">
|
<td class="slot slot-{{ slot.kind.label }}" colspan="{{ slot.colspan }}" rowspan="{{ slow.rowspan }}">
|
||||||
{% if slot.kind.label == "talk" %}
|
{% if slot.kind.label == "talk" %}
|
||||||
{% if not slot.content %}
|
{% 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 %}
|
{% 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>
|
<div class="speaker">{{ slot.content.speaker }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% load i18n bootstrap_tags %}
|
{% 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">
|
<div class="modal-header">
|
||||||
<a class="close" data-dismiss="modal">×</a>
|
<a class="close" data-dismiss="modal">×</a>
|
||||||
<h3>{% trans "Edit Slot" %}</h3>
|
<h3>{% trans "Edit Slot" %}</h3>
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
|
|
||||||
{% for timetable in days %}
|
{% for timetable in days %}
|
||||||
<h2>{{ timetable.day.date }}</h2>
|
<h2>{{ timetable.day.date }}</h2>
|
||||||
|
|
||||||
{% include "schedule/_grid.html" %}
|
{% include "schedule/_grid.html" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue