summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2020-02-14 13:24:20 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2020-02-18 13:02:09 (GMT)
commitfa17bffadfa73c7f6a38cf4c4e869aa8ebd142b0 (patch)
treea2c3527cbf7df21577f3aee63b8d8082665e68ba
parent7698d8a398d8b5391e8c8ce76d35edc992a17a8e (diff)
downloadcombo-wip/39865-snapshot-creation_timestamp.zip
combo-wip/39865-snapshot-creation_timestamp.tar.gz
combo-wip/39865-snapshot-creation_timestamp.tar.bz2
pages: add a default on Page.creation_timestamp field (#39865)wip/39865-snapshot-creation_timestamp
-rw-r--r--combo/data/migrations/0042_page_creation_timestamp.py3
-rw-r--r--combo/data/models.py3
-rw-r--r--tests/test_manager.py16
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 7214a1a..f6e754a 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 230a51f..68255c9 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 3cc3064..a3c7eae 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/