diff --git a/symposion/schedule/forms.py b/symposion/schedule/forms.py index e7e524c9..4e6dfed8 100644 --- a/symposion/schedule/forms.py +++ b/symposion/schedule/forms.py @@ -6,18 +6,34 @@ from symposion.schedule.models import Presentation class SlotEditForm(forms.Form): - presentation = forms.ModelChoiceField(queryset=Presentation.objects.none()) - def __init__(self, *args, **kwargs): - content = kwargs.pop("content", None) - if content: - kwargs.setdefault("initial", {})["presentation"] = content + self.slot = kwargs.pop("slot") super(SlotEditForm, self).__init__(*args, **kwargs) - queryset = Presentation.objects.exclude(cancelled=True).order_by("proposal_base__pk") - if content: - queryset = queryset.filter(Q(slot=None) | Q(pk=content.pk)) - self.fields["presentation"].required = False + if self.slot.kind.label == "talk": + self.fields["presentation"] = self.build_presentation_field() + else: + self.fields["content_override"] = self.build_content_override_field() + + def build_presentation_field(self): + kwargs = {} + queryset = Presentation.objects.all() + queryset = queryset.exclude(cancelled=True) + queryset = queryset.order_by("proposal_base__pk") + if self.slot.content: + queryset = queryset.filter(Q(slot=None) | Q(pk=self.slot.content.pk)) + kwargs["required"] = False + kwargs["initial"] = self.slot.content else: queryset = queryset.filter(slot=None) - self.fields["presentation"].required = True - self.fields["presentation"].queryset = queryset + kwargs["required"] = True + kwargs["queryset"] = queryset + return forms.ModelChoiceField(**kwargs) + + def build_content_override_field(self): + kwargs = { + "label": "Content", + "widget": forms.Textarea(attrs={"class": "span6"}), + "required": False, + "initial": self.slot.content_override, + } + return forms.CharField(**kwargs) diff --git a/symposion/schedule/views.py b/symposion/schedule/views.py index 99cad340..347b6ce2 100644 --- a/symposion/schedule/views.py +++ b/symposion/schedule/views.py @@ -96,23 +96,24 @@ def schedule_slot_edit(request, slug, slot_pk): slot = get_object_or_404(Slot, day__schedule__section__slug=slug, pk=slot_pk) - # slot content - try: - content = slot.content - except ObjectDoesNotExist: - content = None - if request.method == "POST": - form = SlotEditForm(request.POST, content=content) + form = SlotEditForm(request.POST, slot=slot) if form.is_valid(): - presentation = form.cleaned_data["presentation"] - if presentation is None: - slot.unassign() - else: - slot.assign(presentation) + save = False + if "content_override" in form.cleaned_data: + slot.content_override = form.cleaned_data["content_override"] + save = True + if "presentation" in form.cleaned_data: + presentation = form.cleaned_data["presentation"] + if presentation is None: + slot.unassign() + else: + slot.assign(presentation) + if save: + slot.save() return redirect("schedule_edit") else: - form = SlotEditForm(content=content) + form = SlotEditForm(slot=slot) ctx = { "slug": slug, "form": form, diff --git a/symposion/templates/schedule/_edit_grid.html b/symposion/templates/schedule/_edit_grid.html index ecb66757..eb39ec7d 100644 --- a/symposion/templates/schedule/_edit_grid.html +++ b/symposion/templates/schedule/_edit_grid.html @@ -23,6 +23,7 @@ {% else %} {{ slot.kind.label }} {% endif %} + — edit {% endif %} {% endfor %}