def published(self, for_user=None, force_exchange=True):
"""
Customise `UrlNodeQuerySet.published()` to add filtering by publication
date constraints and exchange of draft items for published ones.
"""
qs = self._single_site()
# Avoid filtering to only published items when we are in a draft
# context and we know this method is triggered by Fluent (because
# the `for_user` is present) because we may actually want to find
# and return draft items to priveleged users in this situation.
if for_user and is_draft_request_context():
return qs
if for_user is not None and for_user.is_staff:
pass # Don't filter by publication date for Staff
else:
qs = qs.filter(
Q(publication_date__isnull=True) |
Q(publication_date__lt=now())
).filter(
Q(publication_end_date__isnull=True) |
Q(publication_end_date__gte=now())
)
if force_exchange:
return _exchange_for_published(qs)
else:
return qs.filter(status=UrlNode.PUBLISHED)
评论列表
文章目录