From d99c0ae782d4a743005f2724a24e7d01586b5756 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 10 Oct 2024 17:11:33 +0200 Subject: [PATCH 1/3] :children_crossing: [#3705] Stop displaying timestamps in SubmissionStep.__str__ When displaying timestamps, we need to make sure to convert to them local time and then localize the values for display. However, we can also just decide *not* to display these timestamps since they don't add much value in the string representation of a submission step. Instead, we can include the created_on/modified timestamps directly in the admin inline, and while we're at it, we can declutter the admin interface by changing to TabularInline instead of StackedInline. The _data JSONField is no longer displayed - it has since long been deprecated and replaced with the variables and will be removed entirely. Since this JSONField is no longer needed, we can fully benefit from the tabular inlines instead. --- src/openforms/submissions/admin.py | 9 +++------ src/openforms/submissions/models/submission_step.py | 3 --- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/openforms/submissions/admin.py b/src/openforms/submissions/admin.py index 28916eacb6..2bd53fbbfe 100644 --- a/src/openforms/submissions/admin.py +++ b/src/openforms/submissions/admin.py @@ -101,15 +101,12 @@ def queryset(self, request, queryset): return queryset.filter(last_register_date__gt=yesterday) -class SubmissionStepInline(admin.StackedInline): +class SubmissionStepInline(admin.TabularInline): model = SubmissionStep extra = 0 - fields = ( - "uuid", - "form_step", - "_data", - ) + fields = ("uuid", "form_step", "created_on", "modified") raw_id_fields = ("form_step",) + readonly_fields = ("created_on", "modified") class SubmissionPaymentInline(admin.StackedInline): diff --git a/src/openforms/submissions/models/submission_step.py b/src/openforms/submissions/models/submission_step.py index bd97525fdf..dd676d5df6 100644 --- a/src/openforms/submissions/models/submission_step.py +++ b/src/openforms/submissions/models/submission_step.py @@ -154,9 +154,6 @@ def __init__(self, *args, **kwargs): if not self.form_step_id: self.form_step = self._load_form_step_from_history() - def __str__(self): - return f"SubmissionStep {self.pk}: Submission {self.submission_id} submitted on {self.created_on}" - def _load_form_step_from_history(self): history = deepcopy(self.form_step_history) From a646c1c7f339c7abf6cc3fe37f3284ec8f37a88b Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 10 Oct 2024 17:14:31 +0200 Subject: [PATCH 2/3] :boom: Delete obsolete SubmissionStep._data field It was obsoleted and deprecated two years ago, and now that we're no longer displaying it in the admin anymore we can delete it, especially considering the next release is Open Forms 3.0 which can do breaking changes. --- .../0011_remove_submissionstep__data.py | 17 +++++++++++++++++ .../submissions/models/submission_step.py | 3 --- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/openforms/submissions/migrations/0011_remove_submissionstep__data.py diff --git a/src/openforms/submissions/migrations/0011_remove_submissionstep__data.py b/src/openforms/submissions/migrations/0011_remove_submissionstep__data.py new file mode 100644 index 0000000000..1ead4576cb --- /dev/null +++ b/src/openforms/submissions/migrations/0011_remove_submissionstep__data.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.16 on 2024-10-10 15:12 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("submissions", "0010_emailverification"), + ] + + operations = [ + migrations.RemoveField( + model_name="submissionstep", + name="_data", + ), + ] diff --git a/src/openforms/submissions/models/submission_step.py b/src/openforms/submissions/models/submission_step.py index dd676d5df6..d954512f5b 100644 --- a/src/openforms/submissions/models/submission_step.py +++ b/src/openforms/submissions/models/submission_step.py @@ -99,9 +99,6 @@ class SubmissionStep(models.Model): null=True, blank=True, ) - _data = models.JSONField(_("data"), blank=True, null=True) - # _data is deprecated and replaced with variables. This is still kept around to be - # able to automatically migrate in case there were earlier migration bugs. created_on = models.DateTimeField(_("created on"), auto_now_add=True) modified = models.DateTimeField(_("modified on"), auto_now=True) From 3e1e31851cdd0f33297d761f506b1fe5fb29ebfb Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 10 Oct 2024 17:22:51 +0200 Subject: [PATCH 3/3] :children_crossing: [#3705] Update some more timestamps in str representations Updated a couple more places where timestamps are displayed in the model string representation to make sure they're consistently displayed in the same time zone and properly localized. --- src/openforms/forms/models/form.py | 4 +++- src/openforms/forms/models/form_statistics.py | 4 +++- src/openforms/forms/models/form_version.py | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/openforms/forms/models/form.py b/src/openforms/forms/models/form.py index cf707cc81c..cdce7cd23a 100644 --- a/src/openforms/forms/models/form.py +++ b/src/openforms/forms/models/form.py @@ -10,6 +10,8 @@ from django.db import models, transaction from django.db.models import F, Window from django.db.models.functions import RowNumber +from django.utils.formats import localize +from django.utils.timezone import localtime from django.utils.translation import gettext_lazy as _, override from autoslug import AutoSlugField @@ -686,5 +688,5 @@ class Meta: def __str__(self): return _("Bulk export requested by %(username)s on %(datetime)s") % { "username": self.user.username, - "datetime": self.datetime_requested, + "datetime": localize(localtime(self.datetime_requested)), } diff --git a/src/openforms/forms/models/form_statistics.py b/src/openforms/forms/models/form_statistics.py index 5fda838a05..cfd523c397 100644 --- a/src/openforms/forms/models/form_statistics.py +++ b/src/openforms/forms/models/form_statistics.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.formats import localize +from django.utils.timezone import localtime from django.utils.translation import gettext_lazy as _ @@ -39,5 +40,6 @@ class Meta: def __str__(self): return _("{form_name} last submitted on {last_submitted}").format( - form_name=self.form_name, last_submitted=localize(self.last_submission) + form_name=self.form_name, + last_submitted=localize(localtime(self.last_submission)), ) diff --git a/src/openforms/forms/models/form_version.py b/src/openforms/forms/models/form_version.py index 9481496a45..dada25cf16 100644 --- a/src/openforms/forms/models/form_version.py +++ b/src/openforms/forms/models/form_version.py @@ -4,6 +4,8 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import AbstractBaseUser from django.db import models +from django.utils.formats import localize +from django.utils.timezone import localtime from django.utils.translation import gettext_lazy as _ from .form import Form @@ -91,4 +93,5 @@ class Meta: verbose_name_plural = _("form versions") def __str__(self): - return f"{self.form.admin_name} ({self.created})" + timestamp = localize(localtime(self.created)) + return f"{self.form.admin_name} ({timestamp})"