misc: add method to get last update time of a page and its cells (#15001)
This commit is contained in:
parent
39fead2b3d
commit
0e99dbd053
|
@ -264,6 +264,10 @@ class Page(models.Model):
|
||||||
def get_redirect_url(self):
|
def get_redirect_url(self):
|
||||||
return utils.get_templated_url(self.redirect_url)
|
return utils.get_templated_url(self.redirect_url)
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
|
||||||
class CellMeta(MediaDefiningClass, ModelBase):
|
class CellMeta(MediaDefiningClass, ModelBase):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
|
from django.utils.timezone import now
|
||||||
from combo.data.models import Page, CellBase, TextCell, LinkCell
|
from combo.data.models import Page, CellBase, TextCell, LinkCell
|
||||||
from combo.data.management.commands.import_site import Command as ImportSiteCommand
|
from combo.data.management.commands.import_site import Command as ImportSiteCommand
|
||||||
from combo.data.management.commands.export_site import Command as ExportSiteCommand
|
from combo.data.management.commands.export_site import Command as ExportSiteCommand
|
||||||
|
@ -245,3 +247,18 @@ def test_import_export_management_commands():
|
||||||
assert len(CellBase.get_cells(page_id=new_page_1.id)) == 1
|
assert len(CellBase.get_cells(page_id=new_page_1.id)) == 1
|
||||||
assert isinstance(CellBase.get_cells(page_id=new_page_1.id)[0], TextCell)
|
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'
|
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
|
||||||
|
|
Loading…
Reference in New Issue