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()):
        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):
            pages.update(publish_date=beginning_of_validity, status=CONTENT_STATUS_PUBLISHED)
        else:
            pages.update(status=CONTENT_STATUS_DRAFT)
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()):
        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):
            pages.update(publish_date=beginning_of_validity, status=CONTENT_STATUS_PUBLISHED)
        else:
            pages.update(status=CONTENT_STATUS_DRAFT)