symposion_app/symposion/schedule/forms.py

43 lines
1.5 KiB
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
from markitup.widgets import MarkItUpWidget
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):
2014-07-30 18:19:26 +00:00
def __init__(self, *args, **kwargs):
2012-10-26 21:32:03 +00:00
self.slot = kwargs.pop("slot")
super(SlotEditForm, self).__init__(*args, **kwargs)
# @@@ TODO - Make this configurable
if self.slot.kind.label in ["talk", "tutorial", "keynote"]:
2012-10-26 21:32:03 +00:00
self.fields["presentation"] = self.build_presentation_field()
else:
self.fields["content_override"] = self.build_content_override_field()
2014-07-30 18:19:26 +00:00
2012-10-26 21:32:03 +00:00
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)
2012-10-26 21:32:03 +00:00
kwargs["required"] = True
kwargs["queryset"] = queryset
return forms.ModelChoiceField(**kwargs)
2014-07-30 18:19:26 +00:00
2012-10-26 21:32:03 +00:00
def build_content_override_field(self):
kwargs = {
"label": "Content",
"widget": MarkItUpWidget(),
2012-10-26 21:32:03 +00:00
"required": False,
"initial": self.slot.content_override,
}
return forms.CharField(**kwargs)