Example #1
0
def publish_page_on_approve(sender, instance, created, **kwargs):
    site = get_site(settings.WIDGY_MEZZANINE_SITE)

    pages = WidgyPage.objects.filter(
        root_node=instance.tracker,
    )
    if instance.is_approved:
        pages = pages.filter(
            Q(publish_date__gte=instance.publish_at) |
            Q(status=CONTENT_STATUS_DRAFT)
        ).update(
            status=CONTENT_STATUS_PUBLISHED,
            publish_date=instance.publish_at,
        )
    elif not site.get_version_tracker_model().objects.filter(pk=instance.tracker.pk).published().exists():
        # unaproving a commit, and there are no other currently published commits
        CommitModel = site.get_version_tracker_model().commit_model
        beginning_of_validity = CommitModel.objects.approved().filter(
            tracker_id=instance.tracker.pk,
            publish_at__gt=timezone.now(),
        ).aggregate(min=Min('publish_at'))['min']
        if beginning_of_validity is not None:
            # There's a scheduled commit, move publish_date of the page forward
            # up to the publish_at of the commit.
            pages.update(
                publish_date=beginning_of_validity,
                status=CONTENT_STATUS_PUBLISHED,
            )
        else:
            # no other published commits at all, page needs to be unpublished
            pages.update(
                status=CONTENT_STATUS_DRAFT,
            )
Example #2
0
    def setUp(self):
        super(PageSetup, self).setUp()
        self.factory = RequestFactory()

        self.widgy_site = get_site(getattr(settings, 'WIDGY_MEZZANINE_SITE', widgy_site))

        self.page = WidgyPage.objects.create(
            root_node=self.widgy_site.get_version_tracker_model().objects.create(
                working_copy=MainContent.add_root(self.widgy_site).node,
            ),
            title='titleabc',
            slug='slugabc',
        )
Example #3
0
 def get_site(self):
     return get_site(settings.WIDGY_MEZZANINE_SITE)
Example #4
0
        if beginning_of_validity is not None:
            # There's a scheduled commit, move publish_date of the page forward
            # up to the publish_at of the commit.
            pages.update(
                publish_date=beginning_of_validity,
                status=CONTENT_STATUS_PUBLISHED,
            )
        else:
            # no other published commits at all, page needs to be unpublished
            pages.update(
                status=CONTENT_STATUS_DRAFT,
            )


if REVIEW_QUEUE_INSTALLED:
    from widgy.contrib.review_queue.admin import VersionCommitAdminBase
    from widgy.contrib.review_queue.models import ReviewedVersionCommit

    class VersionCommitAdmin(VersionCommitAdminBase):
        def get_site(self):
            return get_site(settings.WIDGY_MEZZANINE_SITE)

    admin.site.register(ReviewedVersionCommit, VersionCommitAdmin)

    site = get_site(settings.WIDGY_MEZZANINE_SITE)

    if isinstance(site, ReviewedWidgySite):
        # In the tests, review_queue is installed but a ReviewedWidgySite might
        # not be in use.
        post_save.connect(publish_page_on_approve, sender=site.get_version_tracker_model().commit_model)