Projet

Général

Profil

0001-data-add-creation-timestamp-on-Page-object-39091.patch

Nicolas Roche, 27 janvier 2020 17:55

Télécharger (3,44 ko)

Voir les différences:

Subject: [PATCH 1/4] data: add creation timestamp on Page object (#39091)

 .../0041_page_creation_timestamp.py           | 22 +++++++++++++++++++
 combo/data/models.py                          |  7 +++++-
 tests/test_pages.py                           | 10 +++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 combo/data/migrations/0041_page_creation_timestamp.py
combo/data/migrations/0041_page_creation_timestamp.py
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.18 on 2020-01-27 14:46
3
from __future__ import unicode_literals
4

  
5
from django.db import migrations, models
6
import django.utils.timezone
7

  
8

  
9
class Migration(migrations.Migration):
10

  
11
    dependencies = [
12
        ('data', '0040_auto_20200119_1017'),
13
    ]
14

  
15
    operations = [
16
        migrations.AddField(
17
            model_name='page',
18
            name='creation_timestamp',
19
            field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
20
            preserve_default=False,
21
        ),
22
    ]
combo/data/models.py
16 16

  
17 17
import collections
18 18
import copy
19
import datetime
19 20
import feedparser
20 21
import hashlib
21 22
import json
......
39 40
from django.forms import models as model_forms
40 41
from django import forms
41 42
from django import template
42
from django.utils import six
43
from django.utils import six, timezone
43 44
from django.utils.encoding import python_2_unicode_compatible, force_text, smart_bytes
44 45
from django.utils.html import strip_tags
45 46
from django.utils.safestring import mark_safe
......
139 140

  
140 141
    public = models.BooleanField(_('Public'), default=True)
141 142
    groups = models.ManyToManyField(Group, verbose_name=_('Groups'), blank=True)
143
    creation_timestamp = models.DateTimeField(auto_now_add=True)
142 144
    last_update_timestamp = models.DateTimeField(auto_now=True)
143 145

  
144 146
    picture = models.ImageField(_('Picture'), upload_to='page-pictures/', null=True)
......
433 435
        cells = CellBase.get_cells(page_id=self.id)
434 436
        return max([self.last_update_timestamp] + [x.last_update_timestamp for x in cells])
435 437

  
438
    def is_new(self):
439
        return self.creation_timestamp > timezone.now() - datetime.timedelta(days=7)
440

  
436 441
    def duplicate(self):
437 442
        # clone current page
438 443
        new_page = copy.deepcopy(self)
tests/test_pages.py
409 409
    cell.save()
410 410
    response = app.get(page.get_online_url())
411 411
    assert "{{e-service_url}}backoffice/..." in response.text  # href not rendered
412

  
413
def test_page_is_new(freezer):
414
    freezer.move_to('2020-01-01')
415
    page = Page(title='page-1', slug='page-1')
416
    page.save()
417
    assert page.is_new()
418

  
419
    freezer.move_to('2020-01-08')
420
    page = Page.objects.get(slug='page-1')
421
    assert not page.is_new()
412
-