def make_comment_form(leaf, data=None, site=None, user=None): if site is None: site = get_site() if user is None: user = get_user() status = 'published' if user and user.is_authenticated() else site.preferences.default_comment_status return CommentForm(data, leaf=leaf, user=user, status=status)
def published(self, site=None, user=None, language=None, asof=None, bypass=False): if site is None: site = get_site() if user is None: user = get_user() if asof is None: asof = timezone.now() q_exp = models.Q(date_expires__isnull=True) | models.Q(date_expires__gt=asof) q_pub = models.Q(status='published') & models.Q(date_published__lte=asof) q_auth = models.Q(author=user) qs = self.get_query_set().filter(sites__pk=site.pk) if language: qs = qs.filter(language=language) else: qs = qs.filter(translation_of__isnull=True) if bypass: if user.is_superuser: # Superusers can see anything on the site, if we're bypassing the publishing checks. return qs elif user.is_authenticated(): # Otherwise, an authenticated user may see unpublished leaves if they are the author. return qs.filter((q_exp & q_pub) | q_auth) # By default, make sure only published, unexpired leaves are returned. return qs.filter(q_exp & q_pub)