diff --git a/dojo/db_migrations/0248_alter_general_survey_expiration.py b/dojo/db_migrations/0248_alter_general_survey_expiration.py new file mode 100644 index 00000000000..9ebe7e37ac4 --- /dev/null +++ b/dojo/db_migrations/0248_alter_general_survey_expiration.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.14 on 2025-11-17 20:31 + +import dojo.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dojo', '0247_remove_finding_insert_insert_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='general_survey', + name='expiration', + field=models.DateTimeField(default=dojo.models.default_expiration), + ), + ] diff --git a/dojo/forms.py b/dojo/forms.py index 77bbcc57266..636ce1be9c4 100644 --- a/dojo/forms.py +++ b/dojo/forms.py @@ -3632,13 +3632,14 @@ def clean_expiration(self): if expiration < today: msg = "The expiration cannot be in the past" raise forms.ValidationError(msg) - if expiration.day == today.day: + if expiration == today: msg = "The expiration cannot be today" raise forms.ValidationError(msg) - else: - msg = "An expiration for the survey must be supplied" - raise forms.ValidationError(msg) - return expiration + return timezone.make_aware( + datetime.combine(expiration, datetime.min.time()), + ) + msg = "An expiration for the survey must be supplied" + raise forms.ValidationError(msg) class Delete_Questionnaire_Form(forms.ModelForm): diff --git a/dojo/models.py b/dojo/models.py index 24875b400f1..282a8c4d667 100644 --- a/dojo/models.py +++ b/dojo/models.py @@ -4692,11 +4692,15 @@ def __str__(self): return self.survey.name +def default_expiration(): + return timezone.now() + timedelta(days=7) + + class General_Survey(models.Model): survey = models.ForeignKey(Engagement_Survey, on_delete=models.CASCADE) num_responses = models.IntegerField(default=0) generated = models.DateTimeField(auto_now_add=True, null=True) - expiration = models.DateTimeField(null=False, blank=False) + expiration = models.DateTimeField(default=default_expiration) class Meta: verbose_name = _("General Engagement Survey") @@ -4705,6 +4709,10 @@ class Meta: def __str__(self): return self.survey.name + def clean(self): + if self.expiration and timezone.is_naive(self.expiration): + self.expiration = timezone.make_aware(self.expiration) + with warnings.catch_warnings(action="ignore", category=ManagerInheritanceWarning): class Answer(PolymorphicModel, TimeStampedModel):