Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def clean(self):
- act_date = start_date
- exp_date = end_date
- act_date = self.cleaned_data.get('activated')
- exp_date = self.cleaned_data.get('expiry')
- if act_date and exp_date:
- if act_date >= exp_date:
- raise forms.ValidationError("Activation date could not be on or after Expiry date ")
- if exp_date < datetime.today().date():
- raise forms.ValidationError("Expiry date must be a future date")
- """
- CREATING A SET OF DATE OBJECTS WITH THE NEW TIME SLOT
- """
- set_current = set([act_date + timedelta(days=day) for day in range((exp_date-act_date).days)])
- filter_conditions = Q(expiry__gt=act_date) & Q(governing_body=self.formkwargs.get('pk'))
- if self.instance:
- filter_conditions &= ~Q(id=self.instance.id)
- """
- SUBSCRIPTION PLAN MODEL CONTAINS OBJECTS WITH START_DATE as `activated` AND END_DATE as `expiry` SLOT.
- """
- for plan in SubscriptionPlan.objects.filter(filter_conditions):
- temp_date = set([plan.activated + timedelta(days=day)
- for day in range((plan.expiry-plan.activated).days)])
- if set_current.intersection(temp_date):
- raise forms.ValidationError("You have another plan active within this time slot. "
- "[ %s to %s ]" % (plan.activated, plan.expiry))
- return super(SubscriptionForm, self).clean()
Add Comment
Please, Sign In to add comment