Coverage for website/promotion/forms.py: 40.00%
16 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1from django import forms
2from django.utils import timezone
4from promotion.models import PromotionRequest
7class PromotionRequestForm(forms.ModelForm):
8 class Meta:
9 model = PromotionRequest
10 fields = [
11 "event",
12 "publish_date",
13 "channel",
14 "assigned_to",
15 "status",
16 "drive_folder",
17 "remarks",
18 ]
20 def clean(self):
21 cleaned_data = super().clean()
22 if "publish_date" in self.changed_data and "channel" in self.cleaned_data:
23 publish_date = cleaned_data.get("publish_date")
24 minimum_delta = cleaned_data.get("channel").publish_deadline
25 create_time_minimum = publish_date - minimum_delta
26 if timezone.localdate() > create_time_minimum:
27 raise forms.ValidationError(
28 f"Publish date cannot be within {minimum_delta.days} days from now for this channel."
29 )
30 return cleaned_data