fixed a few larger bugs with schedule edit
This commit is contained in:
parent
8bab8b486f
commit
7c102aefa3
6 changed files with 78 additions and 29 deletions
|
@ -1,4 +1,5 @@
|
|||
from django import forms
|
||||
from django.db.models import Q
|
||||
|
||||
from symposion.schedule.models import Presentation
|
||||
|
||||
|
@ -6,6 +7,16 @@ from symposion.schedule.models import Presentation
|
|||
class SlotEditForm(forms.Form):
|
||||
|
||||
presentation = forms.ModelChoiceField(
|
||||
queryset=Presentation.objects.filter(slot__isnull=True),
|
||||
queryset=Presentation.objects.all(),
|
||||
required=True,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
presentation = kwargs.get("initial", {}).get("presentation")
|
||||
super(SlotEditForm, self).__init__(*args, **kwargs)
|
||||
queryset = self.fields["presentation"].queryset
|
||||
if presentation:
|
||||
queryset = queryset.filter(Q(slot=None) | Q(pk=presentation.pk))
|
||||
else:
|
||||
queryset = queryset.filter(slot=None)
|
||||
self.fields["presentation"].queryset = queryset
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db import models
|
||||
|
||||
from markitup.fields import MarkupField
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
||||
from symposion.proposals.models import ProposalBase
|
||||
from symposion.conference.models import Section
|
||||
|
@ -44,6 +46,28 @@ class Slot(models.Model):
|
|||
kind = models.ForeignKey(SlotKind)
|
||||
start = models.TimeField()
|
||||
end = models.TimeField()
|
||||
|
||||
def assign(self, content):
|
||||
"""
|
||||
Assign the given content to this slot and if a previous slot content
|
||||
was given we need to unlink it to avoid integrity errors.
|
||||
"""
|
||||
if self.content and self.content.slot_id:
|
||||
self.content.slot = None
|
||||
self.content.save()
|
||||
content.slot = self
|
||||
content.save()
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
"""
|
||||
Return the content this slot represents.
|
||||
@@@ hard-coded for presentation for now
|
||||
"""
|
||||
try:
|
||||
return self.content_ptr
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class SlotRoom(models.Model):
|
||||
|
@ -60,7 +84,7 @@ class SlotRoom(models.Model):
|
|||
|
||||
class Presentation(models.Model):
|
||||
|
||||
slot = models.OneToOneField(Slot, null=True, blank=True, related_name="presentation")
|
||||
slot = models.OneToOneField(Slot, null=True, blank=True, related_name="content_ptr")
|
||||
title = models.CharField(max_length=100)
|
||||
description = MarkupField()
|
||||
abstract = MarkupField()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import Http404
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
|
||||
|
@ -65,10 +66,22 @@ def schedule_slot_edit(request, slot_pk):
|
|||
raise Http404()
|
||||
|
||||
slot = get_object_or_404(Slot, pk=slot_pk)
|
||||
form = SlotEditForm(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
presentation = form.cleaned_data["presentation"]
|
||||
presentation.slot = slot
|
||||
presentation.save()
|
||||
return redirect("schedule_edit_singleton")
|
||||
if request.method == "POST":
|
||||
form = SlotEditForm(request.POST)
|
||||
if form.is_valid():
|
||||
presentation = form.cleaned_data["presentation"]
|
||||
slot.assign(presentation)
|
||||
return redirect("schedule_edit_singleton")
|
||||
else:
|
||||
initial = {}
|
||||
try:
|
||||
initial["presentation"] = slot.content
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
form = SlotEditForm(initial=initial)
|
||||
ctx = {
|
||||
"form": form,
|
||||
"slot": slot,
|
||||
}
|
||||
return render(request, "schedule/_slot_edit.html", ctx)
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
{% for slot in row.slots %}
|
||||
<td class="slot slot-{{ slot.kind.label }}" colspan="{{ slot.colspan }}" rowspan="{{ slow.rowspan }}">
|
||||
{% if slot.kind.label == "talk" %}
|
||||
{% if not slot.presentation %}
|
||||
{% if not slot.content %}
|
||||
<a class="btn btn-mini edit-slot" data-action="{% url schedule_slot_edit slot.pk %}" href="#">+</a>
|
||||
{% else %}
|
||||
<div class="title">{{ slot.presentation.title }}</div>
|
||||
<div class="speaker">{{ slot.presentation.speaker }}</div>
|
||||
<div class="title">{{ slot.content.title }}</div>
|
||||
<div class="speaker">{{ slot.content.speaker }}</div>
|
||||
|
||||
<span class="schedule-controls">
|
||||
<a class="btn btn-mini edit-slot" data-action="{% url schedule_slot_edit slot.pk %}" href="#">Edit</a>
|
||||
|
|
14
symposion/templates/schedule/_slot_edit.html
Normal file
14
symposion/templates/schedule/_slot_edit.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% load i18n bootstrap_tags %}
|
||||
<form id="slotEditForm" class="modal-form" method="POST" action="{% url schedule_slot_edit slot.pk %}">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3>{% trans "Edit Slot" %}</h3>
|
||||
</div>
|
||||
<div class="modal-body" style="height:350px">
|
||||
{% csrf_token %}
|
||||
{{ form|as_bootstrap }}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
|
@ -62,21 +62,7 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="modal fade hide in" id="slotEditModal">
|
||||
<form id="slotEditForm" class="modal-form" method="POST">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3>{% trans "Edit Slot" %}</h3>
|
||||
</div>
|
||||
<div class="modal-body" style="height:350px">
|
||||
{% csrf_token %}
|
||||
{{ form|as_bootstrap }}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal fade hide in" id="slotEditModal"></div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -85,10 +71,11 @@
|
|||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("a.edit-slot").click(function() {
|
||||
$("#slotEditForm").get(0).setAttribute("action", $(this).data("action"));
|
||||
$("#slotEditModal").modal("show");
|
||||
$("#slotEditModal").load($(this).data("action"), function() {
|
||||
$("#id_presentation").chosen();
|
||||
$("#slotEditModal").modal("show");
|
||||
});
|
||||
});
|
||||
$("#id_presentation").chosen();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue