added ability to edit non-talk slots

This commit is contained in:
Brian Rosner 2012-10-26 15:32:03 -06:00
parent c38eb7de96
commit 19d826ad00
3 changed files with 42 additions and 24 deletions

View file

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

View file

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

View file

@ -23,6 +23,7 @@
{% else %}
{{ slot.kind.label }}
{% endif %}
&mdash; <a class="edit-slot" data-action="{% url schedule_slot_edit schedule.section.slug slot.pk %}" href="#">edit</a>
{% endif %}
</td>
{% endfor %}