Example #1
0
    def get_queryset(self):
        if not perms.may_view_topic(self.request.user, self.topic):
            raise PermissionDenied
        if self.request.user.is_authenticated() or not defaults.PYBB_ANONYMOUS_VIEWS_CACHE_BUFFER:
            Topic.objects.filter(id=self.topic.id).update(views=F('views') + 1)
        else:
            cache_key = util.build_cache_key('anonymous_topic_views', topic_id=self.topic.id)
            cache.add(cache_key, 0)
            if cache.incr(cache_key) % defaults.PYBB_ANONYMOUS_VIEWS_CACHE_BUFFER == 0:
                Topic.objects.filter(id=self.topic.id).update(views=F('views') +
                                                                    defaults.PYBB_ANONYMOUS_VIEWS_CACHE_BUFFER)
                cache.set(cache_key, 0)
        qs = self.topic.posts.all().select_related('user')
        if defaults.PYBB_PROFILE_RELATED_NAME:
            if defaults.PYBB_POST_SORT_REVERSE:
                qs = qs.select_related('user__%s' % defaults.PYBB_PROFILE_RELATED_NAME).order_by('-created')
            else:
                qs = qs.select_related('user__%s' % defaults.PYBB_PROFILE_RELATED_NAME)

        if not perms.may_moderate_topic(self.request.user, self.topic):
            if defaults.PYBB_POST_SORT_REVERSE:
                qs = perms.filter_posts(self.request.user, qs).order_by('-created')
            else:
                qs = perms.filter_posts(self.request.user, qs)
        return qs
Example #2
0
 def get_queryset(self):
     self.topic = get_object_or_404(Topic.objects.select_related('forum'), pk=self.kwargs['pk'])
     if not perms.may_view_topic(self.request.user, self.topic):
         raise PermissionDenied
     self.topic.views += 1
     self.topic.save()
     qs = self.topic.posts.all().select_related('user')
     if not perms.may_moderate_topic(self.request.user, self.topic):
         qs = perms.filter_posts(self.request.user, qs)
     return qs
Example #3
0
    def get_queryset(self):
        if not perms.may_view_topic(self.request.user, self.topic):
            raise PermissionDenied

        self.topic.views += 1
        self.topic.save()
        qs = self.topic.posts.all().select_related('user')
        if not perms.may_moderate_topic(self.request.user, self.topic):
            qs = perms.filter_posts(self.request.user, qs)
        return qs
Example #4
0
    def get_queryset(self):
        if not perms.may_view_topic(self.request.user, self.topic):
            raise PermissionDenied

        self.topic.views += 1
        self.topic.save()
        qs = self.topic.posts.all().select_related('user')
        if not perms.may_moderate_topic(self.request.user, self.topic):
            qs = perms.filter_posts(self.request.user, qs)
        return qs
Example #5
0
File: views.py Project: atas3/pybbm
    def get_queryset(self):
        if not perms.may_view_topic(self.request.user, self.topic):
            raise PermissionDenied

        self.topic.views += 1
        self.topic.save()
        qs = self.topic.posts.all().select_related('user')
        if defaults.PYBB_PROFILE_RELATED_NAME:
            qs = qs.select_related('user__%s' % defaults.PYBB_PROFILE_RELATED_NAME)
        if not perms.may_moderate_topic(self.request.user, self.topic):
            qs = perms.filter_posts(self.request.user, qs)
        return qs
Example #6
0
    def get_queryset(self):
        if not perms.may_view_topic(self.request.user, self.topic):
            raise PermissionDenied

        self.topic.views += 1
        self.topic.save()
        qs = self.topic.posts.all().select_related('user')
        if defaults.PYBB_PROFILE_RELATED_NAME:
            qs = qs.select_related('user__%s' %
                                   defaults.PYBB_PROFILE_RELATED_NAME)
        if not perms.may_moderate_topic(self.request.user, self.topic):
            qs = perms.filter_posts(self.request.user, qs)
        return qs
Example #7
0
 def get_queryset(self):
     if not perms.may_view_topic(self.request.user, self.topic):
         raise PermissionDenied
     if self.request.user.is_authenticated() or not defaults.PYBB_ANONYMOUS_VIEWS_CACHE_BUFFER:
         Topic.objects.filter(id=self.topic.id).update(views=F('views') + 1)
     else:
         cache_key = util.build_cache_key('anonymous_topic_views', topic_id=self.topic.id)
         cache.add(cache_key, 0)
         if cache.incr(cache_key) % defaults.PYBB_ANONYMOUS_VIEWS_CACHE_BUFFER == 0:
             Topic.objects.filter(id=self.topic.id).update(views=F('views') +
                                                             defaults.PYBB_ANONYMOUS_VIEWS_CACHE_BUFFER)
             cache.set(cache_key, 0)
     qs = self.topic.posts.all().select_related('user')
     if defaults.PYBB_PROFILE_RELATED_NAME:
         qs = qs.select_related('user__%s' % defaults.PYBB_PROFILE_RELATED_NAME)
     if not perms.may_moderate_topic(self.request.user, self.topic):
         qs = perms.filter_posts(self.request.user, qs)
     return qs
Example #8
0
def pybb_may_view_topic(topic, user):

    return perms.may_view_topic(user, topic)
Example #9
0
def pybb_may_view_post(post, user):

    return perms.may_view_topic(user, post)