From fa17bffadfa73c7f6a38cf4c4e869aa8ebd142b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Fri, 14 Feb 2020 14:24:20 +0100 Subject: [PATCH] pages: add a default on Page.creation_timestamp field (#39865) --- .../migrations/0042_page_creation_timestamp.py | 3 +-- combo/data/models.py | 3 ++- tests/test_manager.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/combo/data/migrations/0042_page_creation_timestamp.py b/combo/data/migrations/0042_page_creation_timestamp.py index 7214a1ad..f6e754af 100644 --- a/combo/data/migrations/0042_page_creation_timestamp.py +++ b/combo/data/migrations/0042_page_creation_timestamp.py @@ -16,7 +16,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='page', name='creation_timestamp', - field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), - preserve_default=False, + field=models.DateTimeField(default=django.utils.timezone.now), ), ] diff --git a/combo/data/models.py b/combo/data/models.py index 230a51fc..68255c9c 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -47,6 +47,7 @@ from django.utils.html import strip_tags from django.utils.safestring import mark_safe from django.utils.six.moves.urllib import parse as urlparse from django.utils.text import slugify +from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _ from django.forms.widgets import MediaDefiningClass from django.template import Context, engines, TemplateDoesNotExist, TemplateSyntaxError @@ -141,7 +142,7 @@ class Page(models.Model): public = models.BooleanField(_('Public'), default=True) groups = models.ManyToManyField(Group, verbose_name=_('Groups'), blank=True) - creation_timestamp = models.DateTimeField(auto_now_add=True) + creation_timestamp = models.DateTimeField(default=now) last_update_timestamp = models.DateTimeField(auto_now=True) picture = models.ImageField(_('Picture'), upload_to='page-pictures/', null=True) diff --git a/tests/test_manager.py b/tests/test_manager.py index 3cc30646..a3c7eae8 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1472,6 +1472,22 @@ def test_page_versionning(app, admin_user): assert TextCell.objects.count() == 3 assert JsonCell.objects.count() == 0 + +def test_view_old_snapshot(app, admin_user): + page = Page.objects.create(title='One', slug='one') + PageSnapshot.take(page) + snapshot = PageSnapshot.objects.get() + # delete creation_timestamp field + del snapshot.serialization['fields']['creation_timestamp'] + snapshot.save() + # and try to visit the snapshot + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + resp = resp.click('History') + # should succeed + resp = resp.click('view') + + def test_django_admin(app, admin_user): resp = app.get('/admin/') resp = resp.follow() # -> /admin/login/