+ contact = NotImplemented
+
+ def __init__(self, data=None, files=None, *args, **kwargs):
+ self.instance = kwargs.pop('instance', None)
+ if self.instance and (data is not None or files is not None):
+ for attachment in self.instance.attachment_set.all():
+ if attachment.tag not in files:
+ files[attachment.tag] = attachment.file
+ super(ContactForm, self).__init__(data, files, *args, **kwargs)
+ if not self.is_bound and self.instance:
+ self.fields['contact'].initial = self.instance.contact
+ self.fields['contact'].widget = forms.HiddenInput()
+ body = self.instance.body
+ for field, value in body.iteritems():
+ if field in self.fields:
+ self.fields[field].initial = value
+ for attachment in self.instance.attachment_set.all():
+ self.fields[attachment.tag].initial = attachment
+
+ def get_dictionary(self, contact):
+ site = Site.objects.get_current()
+ return {
+ 'form_tag': self.form_tag,
+ 'site_name': getattr(self, 'site_name', site.name),
+ 'site_domain': getattr(self, 'site_domain', site.domain),
+ 'contact': contact,
+ }
+
+ @classmethod
+ def is_disabled(cls):
+ # end_time = localtime_to_utc(datetime(*cls.ends_on)) if cls.ends_on else None
+ # expired = end_time and end_time < timezone.now()
+ return cls.disabled # or expired
+
+ def formset_initial(self, prefix):
+ if not self.instance:
+ return None
+ return self.instance.body.get(prefix)