2012-08-31 03:24:08 +00:00
|
|
|
from django import forms
|
2012-09-14 05:17:32 +00:00
|
|
|
from django.db.models import Q
|
2012-08-31 03:24:08 +00:00
|
|
|
|
2012-08-31 05:12:15 +00:00
|
|
|
from symposion.schedule.models import Presentation
|
2012-08-31 03:24:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SlotEditForm(forms.Form):
|
|
|
|
|
2012-09-20 01:18:09 +00:00
|
|
|
presentation = forms.ModelChoiceField(queryset=Presentation.objects.none())
|
2012-09-14 05:17:32 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2012-09-20 01:15:32 +00:00
|
|
|
content = kwargs.pop("content", None)
|
|
|
|
if content:
|
|
|
|
kwargs.setdefault("initial", {})["presentation"] = content
|
2012-09-14 05:17:32 +00:00
|
|
|
super(SlotEditForm, self).__init__(*args, **kwargs)
|
2012-09-20 01:18:09 +00:00
|
|
|
queryset = Presentation.objects.order_by("proposal_base__pk")
|
2012-09-20 01:15:32 +00:00
|
|
|
if content:
|
|
|
|
queryset = queryset.filter(Q(slot=None) | Q(pk=content.pk))
|
|
|
|
self.fields["presentation"].required = False
|
2012-09-14 05:17:32 +00:00
|
|
|
else:
|
|
|
|
queryset = queryset.filter(slot=None)
|
2012-09-20 01:15:32 +00:00
|
|
|
self.fields["presentation"].required = True
|
2012-09-14 05:17:32 +00:00
|
|
|
self.fields["presentation"].queryset = queryset
|