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-10-26 22:01:01 +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
|
|
|
|
2012-09-14 05:17:32 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2012-10-26 21:32:03 +00:00
|
|
|
self.slot = kwargs.pop("slot")
|
2012-09-14 05:17:32 +00:00
|
|
|
super(SlotEditForm, self).__init__(*args, **kwargs)
|
2013-02-01 05:50:42 +00:00
|
|
|
# @@@ 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
|
2012-09-14 05:17:32 +00:00
|
|
|
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",
|
2012-10-26 22:01:01 +00:00
|
|
|
"widget": MarkItUpWidget(),
|
2012-10-26 21:32:03 +00:00
|
|
|
"required": False,
|
|
|
|
"initial": self.slot.content_override,
|
|
|
|
}
|
|
|
|
return forms.CharField(**kwargs)
|