added ability to edit non-talk slots
This commit is contained in:
parent
c38eb7de96
commit
19d826ad00
3 changed files with 42 additions and 24 deletions
|
@ -6,18 +6,34 @@ from symposion.schedule.models import Presentation
|
||||||
|
|
||||||
class SlotEditForm(forms.Form):
|
class SlotEditForm(forms.Form):
|
||||||
|
|
||||||
presentation = forms.ModelChoiceField(queryset=Presentation.objects.none())
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
content = kwargs.pop("content", None)
|
self.slot = kwargs.pop("slot")
|
||||||
if content:
|
|
||||||
kwargs.setdefault("initial", {})["presentation"] = content
|
|
||||||
super(SlotEditForm, self).__init__(*args, **kwargs)
|
super(SlotEditForm, self).__init__(*args, **kwargs)
|
||||||
queryset = Presentation.objects.exclude(cancelled=True).order_by("proposal_base__pk")
|
if self.slot.kind.label == "talk":
|
||||||
if content:
|
self.fields["presentation"] = self.build_presentation_field()
|
||||||
queryset = queryset.filter(Q(slot=None) | Q(pk=content.pk))
|
else:
|
||||||
self.fields["presentation"].required = False
|
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:
|
else:
|
||||||
queryset = queryset.filter(slot=None)
|
queryset = queryset.filter(slot=None)
|
||||||
self.fields["presentation"].required = True
|
kwargs["required"] = True
|
||||||
self.fields["presentation"].queryset = queryset
|
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)
|
||||||
|
|
|
@ -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 = 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":
|
if request.method == "POST":
|
||||||
form = SlotEditForm(request.POST, content=content)
|
form = SlotEditForm(request.POST, slot=slot)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
presentation = form.cleaned_data["presentation"]
|
save = False
|
||||||
if presentation is None:
|
if "content_override" in form.cleaned_data:
|
||||||
slot.unassign()
|
slot.content_override = form.cleaned_data["content_override"]
|
||||||
else:
|
save = True
|
||||||
slot.assign(presentation)
|
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")
|
return redirect("schedule_edit")
|
||||||
else:
|
else:
|
||||||
form = SlotEditForm(content=content)
|
form = SlotEditForm(slot=slot)
|
||||||
ctx = {
|
ctx = {
|
||||||
"slug": slug,
|
"slug": slug,
|
||||||
"form": form,
|
"form": form,
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ slot.kind.label }}
|
{{ slot.kind.label }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
— <a class="edit-slot" data-action="{% url schedule_slot_edit schedule.section.slug slot.pk %}" href="#">edit</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue