data: add creation timestamp on Page object (#39091)
This commit is contained in:
parent
9c02f4a883
commit
c84c4751e2
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2020-01-31 15:40
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('data', '0041_auto_20200130_1619'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='page',
|
||||
name='creation_timestamp',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import collections
|
||||
import copy
|
||||
import datetime
|
||||
import feedparser
|
||||
import hashlib
|
||||
import html
|
||||
|
@ -40,7 +41,7 @@ from django.dispatch import receiver
|
|||
from django.forms import models as model_forms
|
||||
from django import forms
|
||||
from django import template
|
||||
from django.utils import six
|
||||
from django.utils import six, timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible, force_text, smart_bytes
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.safestring import mark_safe
|
||||
|
@ -140,6 +141,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)
|
||||
last_update_timestamp = models.DateTimeField(auto_now=True)
|
||||
|
||||
picture = models.ImageField(_('Picture'), upload_to='page-pictures/', null=True)
|
||||
|
@ -434,6 +436,9 @@ class Page(models.Model):
|
|||
cells = CellBase.get_cells(page_id=self.id)
|
||||
return max([self.last_update_timestamp] + [x.last_update_timestamp for x in cells])
|
||||
|
||||
def is_new(self):
|
||||
return self.creation_timestamp > timezone.now() - datetime.timedelta(days=7)
|
||||
|
||||
def duplicate(self):
|
||||
# clone current page
|
||||
new_page = copy.deepcopy(self)
|
||||
|
|
|
@ -409,3 +409,13 @@ def test_render_cell_having_href_template_error(app):
|
|||
cell.save()
|
||||
response = app.get(page.get_online_url())
|
||||
assert "{{e-service_url}}backoffice/..." in response.text # href not rendered
|
||||
|
||||
def test_page_is_new(freezer):
|
||||
freezer.move_to('2020-01-01')
|
||||
page = Page(title='page-1', slug='page-1')
|
||||
page.save()
|
||||
assert page.is_new()
|
||||
|
||||
freezer.move_to('2020-01-08')
|
||||
page = Page.objects.get(slug='page-1')
|
||||
assert not page.is_new()
|
||||
|
|
Loading…
Reference in New Issue