Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def get_leaves(*types, **kwargs):
    site = get_site()
    author = kwargs.get('author', None)
    tag = kwargs.get('tag', None)
    num = int(kwargs.get('num', site.preferences.stream_count))
    qs = Leaf.objects.stream()
    if types:
        models = [t.lower() for t in types]
        qs = qs.filter(leaf_type__model__in=models)
    if author:
        qs = qs.filter(author__username__iexact=author)
    if tag:
        qs = qs.filter(tags__slug__iexact=tag)
    return [leaf.resolved for leaf in qs[:num]]
Ejemplo n.º 3
0
 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)