+ @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)
+
+ def get_formsets(self, request=None):
+ request_data = {'data': request.POST, 'files': request.FILES} if request else {}
+ kwargs_instance = dict(request_data)
+ kwargs_instance['instance'] = self.instance
+ formsets = {}
+ for prefix, formset_class in self.form_formsets.iteritems():
+ if getattr(formset_class, 'takes_instance', False):
+ kwargs = kwargs_instance
+ else:
+ kwargs = request_data
+ formsets[prefix] = formset_class(
+ prefix=prefix, initial=self.formset_initial(prefix), **kwargs)
+ return formsets
+