Skip to content

Commit

Permalink
🚸 [#3705] Update some more timestamps in str representations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergei-maertens committed Oct 11, 2024
1 parent a646c1c commit 3e1e318
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 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})"

Check warning on line 97 in src/openforms/forms/models/form_version.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/forms/models/form_version.py#L96-L97

Added lines #L96 - L97 were not covered by tests

0 comments on commit 3e1e318

Please sign in to comment.