Exemplo n.º 1
0
    def decorator(request, *args, **kwargs):
        User = get_user_model()

        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = User.objects.select_related(*relations)
        profile = get_object_or_404(queryset, id=kwargs.pop('user_id'))

        validate_slug(profile, kwargs.pop('user_slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        if profile.acl_['can_follow']:
            profile.is_followed = request.user.is_following(profile)
        else:
            profile.is_followed = False

        if profile.acl_['can_block'] and request.user.is_authenticated():
            profile.is_blocked = request.user.is_blocking(profile)
        else:
            profile.is_blocked = False

        if request.user.is_authenticated and request.method == "GET":
            read_user_notification(request.user, "profile_%s" % profile.pk)

        return f(request, *args, **kwargs)
Exemplo n.º 2
0
    def decorator(request, *args, **kwargs):
        User = get_user_model()

        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = User.objects.select_related(*relations)
        profile = get_object_or_404(queryset, id=kwargs.pop('user_id'))

        validate_slug(profile, kwargs.pop('user_slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        if profile.acl_['can_follow']:
            profile.is_followed = request.user.is_following(profile)
        else:
            profile.is_followed = False

        if profile.acl_['can_block'] and request.user.is_authenticated():
            profile.is_blocked = request.user.is_blocking(profile)
        else:
            profile.is_blocked = False

        if request.user.is_authenticated and request.method == "GET":
            read_user_notification(request.user, "profile_%s" % profile.pk)

        return f(request, *args, **kwargs)
Exemplo n.º 3
0
    def get_thread(self, request, lock=False, **kwargs):
        thread = self.fetch_thread(request, lock, **kwargs)
        self.check_thread_permissions(request, thread)

        if kwargs.get('thread_slug'):
            validate_slug(thread, kwargs.get('thread_slug'))

        return thread
Exemplo n.º 4
0
        def decorator(request, forum_slug, forum_id):
            allow_see_forum(request.user, forum_id)

            forums = Forum.objects.all_forums()
            forum = get_object_or_404(forums, pk=forum_id, role=role)
            validate_slug(forum, forum_slug)

            return f(request, forum)
Exemplo n.º 5
0
    def get_forum(self, request, lock=False, **kwargs):
        forum = self.fetch_forum(request, lock, **kwargs)
        self.check_forum_permissions(request, forum)

        if kwargs.get('forum_slug'):
            validate_slug(forum, kwargs.get('forum_slug'))

        return forum
Exemplo n.º 6
0
    def get_forum(self, request, lock=False, **kwargs):
        forum = self.fetch_forum(request, lock, **kwargs)
        self.check_forum_permissions(request, forum)

        if kwargs.get('forum_slug'):
            validate_slug(forum, kwargs.get('forum_slug'))

        return forum
Exemplo n.º 7
0
    def get_thread(self, request, lock=False, **kwargs):
        thread = self.fetch_thread(request, lock, **kwargs)
        self.check_thread_permissions(request, thread)

        if kwargs.get('thread_slug'):
            validate_slug(thread, kwargs.get('thread_slug'))

        return thread
Exemplo n.º 8
0
    def dispatch(self, request, *args, **kwargs):
        relations = ['forum', 'starter', 'last_poster', 'first_post']
        thread = self.fetch_thread(request, select_related=relations, **kwargs)
        forum = thread.forum

        self.check_forum_permissions(request, forum)
        self.check_thread_permissions(request, thread)

        validate_slug(thread, kwargs['thread_slug'])

        threadstracker.make_read_aware(request.user, thread)

        thread_actions = self.ThreadActions(user=request.user, thread=thread)
        posts_actions = self.PostsActions(user=request.user, thread=thread)

        if request.method == 'POST':
            if thread_actions.query_key in request.POST:
                response = thread_actions.handle_post(request, thread)
                if response:
                    return response
            if posts_actions.query_key in request.POST:
                queryset = self.get_posts_queryset(request.user, forum, thread)
                response = posts_actions.handle_post(request, queryset)
                if response:
                    return response

        page, posts = self.get_posts(request.user, forum, thread, kwargs)
        make_posts_reports_aware(request.user, thread, posts)

        threadstracker.make_posts_read_aware(request.user, thread, posts)
        threadstracker.read_thread(request.user, thread, posts[-1])

        try:
            allow_reply_thread(request.user, thread)
            thread_reply_message = None
        except PermissionDenied as e:
            thread_reply_message = unicode(e)

        return self.render(request, {
            'link_name': request.resolver_match.view_name,
            'links_params': {
                'thread_id': thread.id, 'thread_slug': thread.slug
            },

            'forum': forum,
            'path': get_forum_path(forum),

            'thread': thread,
            'thread_actions': thread_actions,
            'thread_reply_message': thread_reply_message,

            'posts': posts,
            'posts_actions': posts_actions,
            'selected_posts': posts_actions.get_selected_ids(),

            'paginator': page.paginator,
            'page': page,
        })
Exemplo n.º 9
0
    def dispatch(self, request, *args, **kwargs):
        relations = ['forum', 'starter', 'last_poster', 'first_post']
        thread = self.fetch_thread(request, select_related=relations, **kwargs)
        forum = thread.forum

        self.check_forum_permissions(request, forum)
        self.check_thread_permissions(request, thread)

        validate_slug(thread, kwargs['thread_slug'])

        threadstracker.make_read_aware(request.user, thread)

        thread_actions = self.ThreadActions(user=request.user, thread=thread)
        posts_actions = self.PostsActions(user=request.user, thread=thread)

        if request.method == 'POST':
            if thread_actions.query_key in request.POST:
                response = thread_actions.handle_post(request, thread)
                if response:
                    return response
            if posts_actions.query_key in request.POST:
                queryset = self.get_posts_queryset(request.user, forum, thread)
                response = posts_actions.handle_post(request, queryset)
                if response:
                    return response

        page, posts = self.get_posts(request.user, forum, thread, kwargs)

        threadstracker.make_posts_read_aware(request.user, thread, posts)
        threadstracker.read_thread(request.user, thread, posts[-1])

        try:
            allow_reply_thread(request.user, thread)
            thread_reply_message = None
        except PermissionDenied as e:
            thread_reply_message = unicode(e)

        return self.render(request, {
            'link_name': thread.get_url_name(),
            'links_params': {
                'thread_id': thread.id, 'thread_slug': thread.slug
            },

            'forum': forum,
            'path': get_forum_path(forum),

            'thread': thread,
            'thread_actions': thread_actions,
            'thread_reply_message': thread_reply_message,

            'posts': posts,
            'posts_actions': posts_actions,
            'selected_posts': posts_actions.get_selected_ids(),

            'paginator': page.paginator,
            'page': page,
        })
Exemplo n.º 10
0
    def get_thread(self, request, pk, slug=None):
        thread = get_object_or_404(
            Thread.objects.select_related(*BASE_RELATIONS),
            pk=pk,
            category__tree_id=trees_map.get_tree_id_for_root(THREADS_ROOT_NAME),
        )

        allow_see_thread(request.user, thread)
        if slug:
            validate_slug(thread, slug)
        return thread
Exemplo n.º 11
0
    def get_thread(self, request, pk, slug=None):
        thread = get_object_or_404(
            BASE_QUERYSET,
            pk=pk,
            category__tree_id=Category.objects.root_category().tree_id,
        )

        allow_see_thread(request.user, thread)
        if slug:
            validate_slug(thread, slug)
        return thread
Exemplo n.º 12
0
    def get_profile(self, request, pk, slug):
        queryset = UserModel.objects.select_related('rank', 'online_tracker', 'ban_cache')

        profile = get_object_or_404(queryset, pk=pk)

        if not profile.is_active and not request.user.is_staff:
            raise Http404()

        validate_slug(profile, slug)
        add_acl(request.user, profile)

        return profile
Exemplo n.º 13
0
    def dispatch(self, request, *args, **kwargs):
        forum = self.get_forum(request, **kwargs)
        validate_slug(forum, kwargs['forum_slug'])

        forum.labels = Label.objects.get_forum_labels(forum)

        if forum.lft + 1 < forum.rght:
            forum.subforums = get_forums_list(request.user, forum)
        else:
            forum.subforums = []

        page_number = kwargs.pop('page', None)
        cleaned_kwargs = self.clean_kwargs(request, kwargs)

        link_name = request.resolver_match.view_name

        sorting = self.Sorting(link_name, cleaned_kwargs)
        cleaned_kwargs = sorting.clean_kwargs(cleaned_kwargs)

        filtering = self.Filtering(forum, link_name, cleaned_kwargs)
        cleaned_kwargs = filtering.clean_kwargs(cleaned_kwargs)

        if cleaned_kwargs != kwargs:
            return redirect(link_name, **cleaned_kwargs)

        threads = self.Threads(request.user, forum)
        sorting.sort(threads)
        filtering.filter(threads)

        actions = self.Actions(user=request.user, forum=forum)
        if request.method == 'POST':
            response = actions.handle_post(request, threads.get_queryset())
            if response:
                return response

        return self.render(request, {
            'link_name': link_name,
            'links_params': cleaned_kwargs,

            'forum': forum,
            'path': get_forum_path(forum),

            'threads': threads.list(page_number),
            'threads_count': threads.count(),
            'page': threads.page,
            'paginator': threads.paginator,

            'threads_actions': actions,
            'selected_threads': actions.get_selected_ids(),

            'sorting': sorting,
            'filtering': filtering,
        })
Exemplo n.º 14
0
        def decorator(request, *args, **kwargs):
            queryset = get_user_model().objects.select_for_update()
            user_id = kwargs.pop('user_id')

            kwargs['user'] = get_object_or_404(queryset, id=user_id)
            validate_slug(kwargs['user'], kwargs.pop('user_slug'))
            add_acl(request.user, kwargs['user'])

            if required_permission:
                required_permission(request.user, kwargs['user'])

            return f(request, *args, **kwargs)
Exemplo n.º 15
0
    def get_profile(self, request, pk, slug):
        queryset = UserModel.objects.select_related('rank', 'online_tracker', 'ban_cache')

        profile = get_object_or_404(queryset, pk=pk)

        if not profile.is_active and not request.user.is_staff:
            raise Http404()

        validate_slug(profile, slug)
        add_acl(request.user, profile)

        return profile
Exemplo n.º 16
0
        def decorator(request, *args, **kwargs):
            queryset = get_user_model().objects.select_for_update()
            user_id = kwargs.pop('user_id')

            kwargs['user'] = get_object_or_404(queryset, id=user_id)
            validate_slug(kwargs['user'], kwargs.pop('user_slug'))
            add_acl(request.user, kwargs['user'])

            if required_permission:
                required_permission(request.user, kwargs['user'])

            return f(request, *args, **kwargs)
Exemplo n.º 17
0
    def get_category(self, request, categories, **kwargs):
        for category in categories:
            if category.pk == int(kwargs['pk']):
                if not category.level:
                    raise Http404()

                allow_see_category(request.user, category)
                allow_browse_category(request.user, category)

                validate_slug(category, kwargs['slug'])
                return category
        else:
            raise Http404()
Exemplo n.º 18
0
    def get_category(self, request, categories, **kwargs):
        for category in categories:
            if category.pk == int(kwargs['category_id']):
                if category.special_role:
                    raise Http404()

                allow_see_category(request.user, category)
                allow_browse_category(request.user, category)

                validate_slug(category, kwargs['category_slug'])
                return category
        else:
            raise Http404()
Exemplo n.º 19
0
    def decorator(request, *args, **kwargs):
        User = get_user_model()

        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = User.objects.select_related(*relations)
        profile = get_object_or_404(queryset, pk=kwargs.pop('pk'))

        validate_slug(profile, kwargs.pop('slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        return f(request, *args, **kwargs)
Exemplo n.º 20
0
    def decorator(request, *args, **kwargs):
        User = get_user_model()

        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = User.objects.select_related(*relations)
        profile = get_object_or_404(queryset, pk=kwargs.pop('pk'))

        validate_slug(profile, kwargs.pop('slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        return f(request, *args, **kwargs)
Exemplo n.º 21
0
    def get_category(self, request, categories, **kwargs):
        for category in categories:
            if category.pk == int(kwargs['pk']):
                if not category.special_role:
                    # don't check permissions for non-special category
                    allow_see_category(request.user, category)
                    allow_browse_category(request.user, category)

                if 'slug' in kwargs:
                    validate_slug(category, kwargs['slug'])

                return category
        raise Http404()
Exemplo n.º 22
0
    def get_category(self, request, categories, **kwargs):
        for category in categories:
            if category.pk == int(kwargs['pk']):
                if not category.special_role:
                    # don't check permissions for non-special category
                    allow_see_category(request.user, category)
                    allow_browse_category(request.user, category)

                if 'slug' in kwargs:
                    validate_slug(category, kwargs['slug'])

                return category
        raise Http404()
Exemplo n.º 23
0
    def get_category(self, request, categories, **kwargs):
        for category in categories:
            if category.pk == int(kwargs['pk']):
                if not category.level:
                    raise Http404()

                allow_see_category(request.user, category)
                allow_browse_category(request.user, category)

                validate_slug(category, kwargs['slug'])
                return category
        else:
            raise Http404()
Exemplo n.º 24
0
    def dispatch(self, request, *args, **kwargs):
        forum = self.get_forum(request, **kwargs)
        validate_slug(forum, kwargs['forum_slug'])

        forum.labels = Label.objects.get_forum_labels(forum)

        if forum.lft + 1 < forum.rght:
            forum.subforums = get_forums_list(request.user, forum)
        else:
            forum.subforums = []

        page_number = kwargs.pop('page', None)
        cleaned_kwargs = self.clean_kwargs(request, kwargs)

        sorting = self.Sorting(self.link_name, cleaned_kwargs)
        cleaned_kwargs = sorting.clean_kwargs(cleaned_kwargs)

        filtering = self.Filtering(forum, self.link_name, cleaned_kwargs)
        cleaned_kwargs = filtering.clean_kwargs(cleaned_kwargs)

        if cleaned_kwargs != kwargs:
            return redirect(self.link_name, **cleaned_kwargs)

        threads = self.Threads(request.user, forum)
        sorting.sort(threads)
        filtering.filter(threads)

        actions = self.Actions(user=request.user, forum=forum)
        if request.method == 'POST':
            response = actions.handle_post(request, threads.get_queryset())
            if response:
                return response

        return self.render(request, {
            'link_name': self.link_name,
            'links_params': cleaned_kwargs,

            'forum': forum,
            'path': get_forum_path(forum),

            'threads': threads.list(page_number),
            'threads_count': threads.count(),
            'page': threads.page,
            'paginator': threads.paginator,

            'threads_actions': actions,
            'selected_threads': actions.get_selected_ids(),

            'sorting': sorting,
            'filtering': filtering,
        })
Exemplo n.º 25
0
    def decorator(request, *args, **kwargs):
        relations = ('rank', 'online_tracker', 'ban_cache')
        queryset = UserModel.objects.select_related(*relations)

        profile = get_object_or_404(queryset, pk=kwargs.pop('pk'))

        if not profile.is_active and not request.user.is_staff:
            raise Http404()

        validate_slug(profile, kwargs.pop('slug'))
        kwargs['profile'] = profile

        add_acl(request.user, profile)

        return f(request, *args, **kwargs)
Exemplo n.º 26
0
    def get_thread(self, request, pk, slug=None, select_for_update=False):
        if select_for_update:
            queryset = Thread.objects.select_for_update()
        else:
            queryset = Thread.objects.select_related(*BASE_RELATIONS)

        thread = get_object_or_404(
            queryset,
            pk=pk,
            category__tree_id=trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)
        )

        allow_see_thread(request.user, thread)
        if slug:
            validate_slug(thread, slug)
        return thread
Exemplo n.º 27
0
    def get_thread(self, request, pk, slug=None, select_for_update=False):
        if select_for_update:
            queryset = Thread.objects.select_for_update().select_related('category')
        else:
            queryset = Thread.objects.select_related(*BASE_RELATIONS)

        thread = get_object_or_404(
            queryset,
            pk=pk,
            category__tree_id=trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)
        )

        allow_see_thread(request.user, thread)
        if slug:
            validate_slug(thread, slug)
        return thread
Exemplo n.º 28
0
    def get_thread(self, request, pk, slug=None):
        allow_use_private_threads(request.user)

        thread = get_object_or_404(
            Thread.objects.select_related(*BASE_RELATIONS),
            pk=pk,
            category__tree_id=trees_map.get_tree_id_for_root(PRIVATE_THREADS_ROOT_NAME),
        )

        make_participants_aware(request.user, thread)
        allow_see_private_thread(request.user, thread)

        if slug:
            validate_slug(thread, slug)

        return thread
Exemplo n.º 29
0
def validate_slug_view(request, pk, slug):
    model = Model(int(pk), 'eric-the-fish')
    validate_slug(model, slug)
    return HttpResponse("Allright!")
Exemplo n.º 30
0
def validate_slug_view(request, pk, slug):
    model = Model(int(pk), 'eric-the-fish')
    validate_slug(model, slug)
    return HttpResponse("Allright!")