Skip to content

Commit

Permalink
Merge pull request #4749 from open-formulieren/issue/3705-timestamps-…
Browse files Browse the repository at this point in the history
…in-str-representation

Make timestamp representation consistent in model string representation.
  • Loading branch information
sergei-maertens authored Oct 11, 2024
2 parents 1ae8370 + 3e1e318 commit d0a504f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/openforms/forms/models/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)),
}
4 changes: 3 additions & 1 deletion src/openforms/forms/models/form_statistics.py
Original file line number Diff line number Diff line change
@@ -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 _


Expand Down Expand Up @@ -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)),
)
5 changes: 4 additions & 1 deletion src/openforms/forms/models/form_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})"
9 changes: 3 additions & 6 deletions src/openforms/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
]
6 changes: 0 additions & 6 deletions src/openforms/submissions/models/submission_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -154,9 +151,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)

Expand Down

0 comments on commit d0a504f

Please sign in to comment.