symposion_app/symposion/schedule/forms.py

24 lines
889 B
Python
Raw Normal View History

2012-08-31 03:24:08 +00:00
from django import forms
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())
def __init__(self, *args, **kwargs):
content = kwargs.pop("content", None)
if content:
kwargs.setdefault("initial", {})["presentation"] = content
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
else:
queryset = queryset.filter(slot=None)
self.fields["presentation"].required = True
self.fields["presentation"].queryset = queryset