Exemple #1
0
 def get_forum(self, **kwargs):
     if 'pk' in kwargs:
         forum = get_object_or_404(perms.filter_forums(self.request, Forum.objects.all()), pk=kwargs['pk'])
     elif ('slug' and 'category_slug') in kwargs:
         forum = get_object_or_404(perms.filter_forums(self.request, Forum.objects.all()), slug=kwargs['slug'], category__slug=kwargs['category_slug'])
     else:
         raise Http404(_('Forum does not exist'))
     return forum
Exemple #2
0
 def get_context_data(self, **kwargs):
     ctx = super(IndexView, self).get_context_data(**kwargs)
     categories = ctx['categories']
     for category in categories:
         category.forums_accessed = perms.filter_forums(self.request.user, category.forums.filter(parent=None))
     ctx['categories'] = categories
     return ctx
Exemple #3
0
    def dispatch(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            self.user = request.user
        else:
            if defaults.PYBB_ENABLE_ANONYMOUS_POST:
                self.user, new = User.objects.get_or_create(**{username_field: defaults.PYBB_ANONYMOUS_USERNAME})
            else:
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(request.get_full_path())

        self.forum = None
        self.topic = None
        if 'forum_id' in kwargs:
            self.forum = get_object_or_404(perms.filter_forums(request.user, Forum.objects.all()), pk=kwargs['forum_id'])
            if not perms.may_create_topic(self.user, self.forum):
                raise PermissionDenied
        elif 'topic_id' in kwargs:
            self.topic = get_object_or_404(perms.filter_topics(request.user, Topic.objects.all()), pk=kwargs['topic_id'])
            if not perms.may_create_post(self.user, self.topic):
                raise PermissionDenied

            self.quote = ''
            if 'quote_id' in request.GET:
                try:
                    quote_id = int(request.GET.get('quote_id'))
                except TypeError:
                    raise Http404
                else:
                    post = get_object_or_404(Post, pk=quote_id)
                    self.quote = defaults.PYBB_QUOTE_ENGINES[defaults.PYBB_MARKUP](post.body, getattr(post.user, username_field))

                if self.quote and request.is_ajax():
                    return HttpResponse(self.quote)
        return super(AddPostView, self).dispatch(request, *args, **kwargs)
Exemple #4
0
 def get_context_data(self, **kwargs):
     ctx = super(CategoryView, self).get_context_data(**kwargs)
     ctx["category"].forums_accessed = perms.filter_forums(
         self.request.user, ctx["category"].forums.filter(parent=None)
     )
     ctx["categories"] = [ctx["category"]]
     return ctx
Exemple #5
0
def mark_all_as_read(request):
    for forum in perms.filter_forums(request.user, Forum.objects.all()):
        forum_mark, new = ForumReadTracker.objects.get_or_create_tracker(forum=forum, user=request.user)
        forum_mark.save()
    TopicReadTracker.objects.filter(user=request.user).delete()
    msg = _('All forums marked as read')
    messages.success(request, msg, fail_silently=True)
    return redirect(reverse('pybb:index'))
Exemple #6
0
 def get_context_data(self, **kwargs):
     ctx = super(IndexView, self).get_context_data(**kwargs)
     ctx.update(get_intial_home_data(self.request))
     categories = ctx['categories']
     for category in categories:
         category.forums_accessed = perms.filter_forums(self.request.user, category.forums.all())
     ctx['categories'] = categories
     return ctx
Exemple #7
0
 def get_queryset(self):
     self.forum = get_object_or_404(perms.filter_forums(self.request.user, Forum.objects.all()), pk=self.kwargs['pk'])
     qs = self.forum.topics.order_by('-sticky', '-updated').select_related()
     if not (self.request.user.is_superuser or self.request.user in self.forum.moderators.all()):
         if self.request.user.is_authenticated():
             qs = qs.filter(Q(user=self.request.user)|Q(on_moderation=False))
         else:
             qs = qs.filter(on_moderation=False)
     return qs
Exemple #8
0
 def get_context_data(self, **kwargs):
     ctx = super(ForumView, self).get_context_data(**kwargs)
     ctx['forum'] = self.forum
     if self.request.user.is_authenticated():
         try:
             ctx['subscription'] = ForumSubscription.objects.get(
                 user=self.request.user,
                 forum=self.forum
             )
         except ForumSubscription.DoesNotExist:
             ctx['subscription'] = None
     else:
         ctx['subscription'] = None
     ctx['forum'].forums_accessed = perms.filter_forums(self.request.user, self.forum.child_forums.all())
     return ctx
Exemple #9
0
    def dispatch(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            self.user = request.user
        else:
            if defaults.PYBB_ENABLE_ANONYMOUS_POST:
                self.user, new = User.objects.get_or_create(**{username_field: defaults.PYBB_ANONYMOUS_USERNAME})
            else:
                from django.contrib.auth.views import redirect_to_login

                return redirect_to_login(request.get_full_path())

        self.forum = None
        self.topic = None
        if "forum_id" in kwargs:
            self.forum = get_object_or_404(
                perms.filter_forums(request.user, Forum.objects.all()), pk=kwargs["forum_id"]
            )
            if not perms.may_create_topic(self.user, self.forum):
                raise PermissionDenied
        elif "topic_id" in kwargs:
            self.topic = get_object_or_404(
                perms.filter_topics(request.user, Topic.objects.all()), pk=kwargs["topic_id"]
            )
            if not perms.may_create_post(self.user, self.topic):
                raise PermissionDenied

            self.quote = ""
            if "quote_id" in request.GET:
                try:
                    quote_id = int(request.GET.get("quote_id"))
                except TypeError:
                    raise Http404
                else:
                    post = get_object_or_404(Post, pk=quote_id)
                    if not perms.may_view_post(request.user, post):
                        raise PermissionDenied
                    profile = util.get_pybb_profile(post.user)
                    self.quote = util._get_markup_quoter(defaults.PYBB_MARKUP)(post.body, profile.get_display_name())

                if self.quote and request.is_ajax():
                    return HttpResponse(self.quote)
        return super(AddPostView, self).dispatch(request, *args, **kwargs)
Exemple #10
0
    def dispatch(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            self.user = request.user
        else:
            if defaults.PYBB_ENABLE_ANONYMOUS_POST:
                self.user, new = User.objects.get_or_create(username=defaults.PYBB_ANONYMOUS_USERNAME)
            else:
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(request.get_full_path())

        self.forum = None
        self.topic = None
        if 'forum_id' in kwargs:
            self.forum = get_object_or_404(perms.filter_forums(request.user, Forum.objects.all()), pk=kwargs['forum_id'])
            if not perms.may_create_topic(self.user, self.forum):
                raise PermissionDenied
        elif 'topic_id' in kwargs:
            self.topic = get_object_or_404(perms.filter_topics(request.user, Topic.objects.all()), pk=kwargs['topic_id'])
            if not perms.may_create_post(self.user, self.topic):
                raise PermissionDenied
        return super(AddPostView, self).dispatch(request, *args, **kwargs)
Exemple #11
0
 def get_context_data(self, **kwargs):
     ctx = super(ForumView, self).get_context_data(**kwargs)
     ctx['forum'] = self.forum
     ctx['forum'].forums_accessed = perms.filter_forums(self.request.user, self.forum.child_forums.all())
     return ctx
Exemple #12
0
 def get_context_data(self, **kwargs):
     ctx = super(CategoryView, self).get_context_data(**kwargs)
     ctx.update(get_intial_home_data(self.request))
     ctx['category'].forums_accessed = perms.filter_forums(self.request.user, ctx['category'].forums.all())
     ctx['categories'] = [ctx['category']]
     return ctx