data: deprecate get_last_update_time using signals (#39091)

This commit is contained in:
Nicolas Roche 2020-01-23 16:25:32 +01:00
parent c84c4751e2
commit 3e5e80f6e6
2 changed files with 15 additions and 20 deletions

View File

@ -353,7 +353,7 @@ class Page(models.Model):
cell_types.add(cell.get_cell_type_str())
if cell_types != set(self.related_cells.get('cell_types', [])):
self.related_cells['cell_types'] = list(cell_types)
self.save()
self.save()
def get_serialized_page(self):
cells = [x for x in self.get_cells() if x.placeholder and not x.placeholder.startswith('_')]
@ -433,8 +433,7 @@ class Page(models.Model):
return utils.get_templated_url(self.redirect_url, context=context)
def get_last_update_time(self):
cells = CellBase.get_cells(page_id=self.id)
return max([self.last_update_timestamp] + [x.last_update_timestamp for x in cells])
return self.last_update_timestamp
def is_new(self):
return self.creation_timestamp > timezone.now() - datetime.timedelta(days=7)

View File

@ -1,4 +1,3 @@
import datetime
import os
import pytest
import sys
@ -8,7 +7,6 @@ from django.contrib.auth.models import User, Group
from django.test import override_settings
from django.test.client import RequestFactory
from django.utils.six import StringIO
from django.utils.timezone import now
from combo.data.models import Page, PageSnapshot, CellBase, TextCell, LinkCell, LinkListCell
from combo.data.management.commands.import_site import Command as ImportSiteCommand
from combo.data.management.commands.export_site import Command as ExportSiteCommand
@ -355,21 +353,6 @@ def test_import_export_management_commands():
assert isinstance(CellBase.get_cells(page_id=new_page_1.id)[0], TextCell)
assert CellBase.get_cells(page_id=new_page_1.id)[0].text == 'foo'
def test_last_update_time():
page = Page(title=u'foo', slug='foo', order=0)
page.save()
cell = TextCell(page=page, text='foo', order=0)
cell.save()
cell = TextCell(page=page, text='bar', order=0)
cell.save()
future_time = now() + datetime.timedelta(days=2)
TextCell.objects.filter(pk=cell.id).update(last_update_timestamp=future_time)
assert page.get_last_update_time() == future_time
def test_get_placeholders():
page = Page(title=u'foo', slug='foo', template_name='standard-sidebar', order=0)
request = RequestFactory().get('/')
@ -410,6 +393,19 @@ def test_render_cell_having_href_template_error(app):
response = app.get(page.get_online_url())
assert "{{e-service_url}}backoffice/..." in response.text # href not rendered
def test_cell_maintain_page_cell_cache(freezer):
freezer.move_to('2020-01-01')
page = Page(title='page-1', slug='page-1')
page.save()
cell = TextCell(page=page, order=0, slug='cell-1', text='foo')
cell.save()
assert page.last_update_timestamp.isoformat().startswith('2020-01-01')
freezer.move_to('2020-02-02')
cell.text = 'bar'
cell.save()
assert page.last_update_timestamp.isoformat().startswith('2020-02-02')
def test_page_is_new(freezer):
freezer.move_to('2020-01-01')
page = Page(title='page-1', slug='page-1')