def test_date_ordering(self): """Test page date ordering feature.""" self.set_setting("PAGE_USE_SITE_ID", False) author = User.objects.all()[0] yesterday = now_utc() - datetime.timedelta(days=1) now = now_utc() p1 = Page(author=author, status=Page.PUBLISHED, publication_date=now) p1.save() p2 = Page(author=author, publication_date=now, status=Page.PUBLISHED) p2.save() p3 = Page(author=author, publication_date=yesterday, status=Page.PUBLISHED) p3.save() p2.move_to(p1, position='first-child') p3.move_to(p1, position='first-child') p1 = Page.objects.get(pk=p1.id) p2 = Page.objects.get(pk=p2.id) p3 = Page.objects.get(pk=p3.id) self.assertEqual([p.id for p in p1.get_children_for_frontend()], [p3.id, p2.id]) self.assertEqual( [p.id for p in p1.get_date_ordered_children_for_frontend()], [p2.id, p3.id])
def _get_calculated_status(self): """Get the calculated status of the page based on :attr:`Page.publication_date`, :attr:`Page.publication_end_date`, and :attr:`Page.status`.""" if settings.PAGE_SHOW_START_DATE and self.publication_date: if self.publication_date > now_utc(): return self.DRAFT if settings.PAGE_SHOW_END_DATE and self.publication_end_date: if self.publication_end_date < now_utc(): return self.EXPIRED return self.status
def test_page_caculated_status(self): """Test calculated status property.""" self.set_setting("PAGE_SHOW_START_DATE", True) yesterday = now_utc() - datetime.timedelta(days=1) tomorrow = now_utc() + datetime.timedelta(days=1) page = self.new_page() self.assertEqual(page.calculated_status, Page.PUBLISHED) page.publication_date = tomorrow self.assertEqual(page.calculated_status, Page.DRAFT) page.publication_date = yesterday self.assertEqual(page.calculated_status, Page.PUBLISHED) self.set_setting("PAGE_SHOW_END_DATE", True) page.publication_end_date = yesterday self.assertEqual(page.calculated_status, Page.EXPIRED)
def save(self, *args, **kwargs): """Override the default ``save`` method.""" if not self.status: self.status = self.DRAFT # Published pages should always have a publication date if self.publication_date is None and self.status == self.PUBLISHED: self.publication_date = now_utc() # Drafts should not, unless they have been set to the future if self.status == self.DRAFT: if settings.PAGE_SHOW_START_DATE: if self.publication_date and self.publication_date <= now_utc(): self.publication_date = None else: self.publication_date = None self.last_modification_date = now_utc() # let's assume there is no more broken links after a save cache.delete(self.PAGE_BROKEN_LINK_KEY % self.id) super(Page, self).save(*args, **kwargs) # fix sites many-to-many link when the're hidden from the form if settings.PAGE_HIDE_SITES and self.sites.count() == 0: self.sites.add(Site.objects.get(pk=settings.SITE_ID))
def save(self, *args, **kwargs): """Override the default ``save`` method.""" if not self.status: self.status = self.DRAFT # Published pages should always have a publication date if self.publication_date is None and self.status == self.PUBLISHED: self.publication_date = now_utc() # Drafts should not, unless they have been set to the future if self.status == self.DRAFT: if settings.PAGE_SHOW_START_DATE: if (self.publication_date and self.publication_date <= now_utc()): self.publication_date = None else: self.publication_date = None self.last_modification_date = now_utc() # let's assume there is no more broken links after a save cache.delete(self.PAGE_BROKEN_LINK_KEY % self.id) super(Page, self).save(*args, **kwargs) # fix sites many-to-many link when the're hidden from the form if settings.PAGE_HIDE_SITES and self.sites.count() == 0: self.sites.add(Site.objects.get(pk=settings.SITE_ID))
def test_date_ordering(self): """Test page date ordering feature.""" self.set_setting("PAGE_USE_SITE_ID", False) author = User.objects.all()[0] yesterday = now_utc() - datetime.timedelta(days=1) now = now_utc() p1 = Page(author=author, status=Page.PUBLISHED, publication_date=now) p1.save() p2 = Page( author=author, publication_date=now, status=Page.PUBLISHED ) p2.save() p3 = Page( author=author, publication_date=yesterday, status=Page.PUBLISHED ) p3.save() p2.move_to(p1, position='first-child') p3.move_to(p1, position='first-child') p1 = Page.objects.get(pk=p1.id) p2 = Page.objects.get(pk=p2.id) p3 = Page.objects.get(pk=p3.id) self.assertEqual( [p.id for p in p1.get_children_for_frontend()], [p3.id, p2.id] ) self.assertEqual( [p.id for p in p1.get_date_ordered_children_for_frontend()], [p2.id, p3.id] )