Skip to content

Commit 268f813

Browse files
committed
🐛 fix create questionnaire with empty survey
1 parent 8a7ff18 commit 268f813

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 5.1.14 on 2025-11-17 19:46
2+
3+
import datetime
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('dojo', '0247_remove_finding_insert_insert_and_more'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='general_survey',
16+
name='expiration',
17+
field=models.DateTimeField(default=datetime.datetime(2025, 11, 24, 19, 46, 23, 24749, tzinfo=datetime.timezone.utc)),
18+
),
19+
]

dojo/forms.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,13 +3632,14 @@ def clean_expiration(self):
36323632
if expiration < today:
36333633
msg = "The expiration cannot be in the past"
36343634
raise forms.ValidationError(msg)
3635-
if expiration.day == today.day:
3635+
if expiration == today:
36363636
msg = "The expiration cannot be today"
36373637
raise forms.ValidationError(msg)
3638-
else:
3639-
msg = "An expiration for the survey must be supplied"
3640-
raise forms.ValidationError(msg)
3641-
return expiration
3638+
return timezone.make_aware(
3639+
datetime.combine(expiration, datetime.min.time()),
3640+
)
3641+
msg = "An expiration for the survey must be supplied"
3642+
raise forms.ValidationError(msg)
36423643

36433644

36443645
class Delete_Questionnaire_Form(forms.ModelForm):

dojo/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4696,7 +4696,7 @@ class General_Survey(models.Model):
46964696
survey = models.ForeignKey(Engagement_Survey, on_delete=models.CASCADE)
46974697
num_responses = models.IntegerField(default=0)
46984698
generated = models.DateTimeField(auto_now_add=True, null=True)
4699-
expiration = models.DateTimeField(null=False, blank=False)
4699+
expiration = models.DateTimeField(default=timezone.now() + timedelta(days=7))
47004700

47014701
class Meta:
47024702
verbose_name = _("General Engagement Survey")
@@ -4705,6 +4705,10 @@ class Meta:
47054705
def __str__(self):
47064706
return self.survey.name
47074707

4708+
def clean(self):
4709+
if self.expiration and timezone.is_naive(self.expiration):
4710+
self.expiration = timezone.make_aware(self.expiration)
4711+
47084712

47094713
with warnings.catch_warnings(action="ignore", category=ManagerInheritanceWarning):
47104714
class Answer(PolymorphicModel, TimeStampedModel):

0 commit comments

Comments
 (0)