• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shortcuts.get_int_or_404函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misago.core.shortcuts.get_int_or_404函数的典型用法代码示例。如果您正苦于以下问题:Python get_int_or_404函数的具体用法?Python get_int_or_404怎么用?Python get_int_or_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_int_or_404函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: read

    def read(self, request, thread_pk, pk):
        thread = self.get_thread(request, get_int_or_404(thread_pk))
        post = self.get_post(request, thread, get_int_or_404(pk)).model

        request.user.lock()

        return post_read_endpoint(request, thread.model, post)
开发者ID:l0ud,项目名称:Misago,代码行数:7,代码来源:threadposts.py


示例2: post_editor

    def post_editor(self, request, thread_pk, pk):
        thread = self.get_thread(
            request,
            get_int_or_404(thread_pk),
            read_aware=False,
            subscription_aware=False
        )
        post = self.get_post(request, thread, get_int_or_404(pk)).model

        allow_edit_post(request.user, post)

        attachments = []
        for attachment in post.attachment_set.order_by('-id'):
            add_acl(request.user, attachment)
            attachments.append(attachment)
        attachments_json = AttachmentSerializer(
            attachments, many=True, context={'user': request.user}).data

        return Response({
            'id': post.pk,
            'api': post.get_api_url(),
            'post': post.original,
            'attachments': attachments_json,
            'can_protect': bool(thread.category.acl['can_protect_posts']),
            'is_protected': post.is_protected,
            'poster': post.poster_name
        })
开发者ID:l0ud,项目名称:Misago,代码行数:27,代码来源:threadposts.py


示例3: generic

def generic(request):
    queryset = get_user_model().objects
    if request.query_params.get('followers'):
        user_pk = get_int_or_404(request.query_params.get('followers'))
        queryset = get_object_or_404(queryset, pk=user_pk).followed_by
    elif request.query_params.get('follows'):
        user_pk = get_int_or_404(request.query_params.get('follows'))
        queryset = get_object_or_404(queryset, pk=user_pk).follows

    if request.query_params.get('rank'):
        rank_pk = get_int_or_404(request.query_params.get('rank'))
        rank = get_object_or_404(Rank.objects, pk=rank_pk, is_tab=True)
        queryset = queryset.filter(rank=rank)

    if request.query_params.get('name'):
        name_starts_with = request.query_params.get('name').strip().lower()
        if name_starts_with:
            queryset = queryset.filter(slug__startswith=name_starts_with)
        else:
            raise Http404()

    queryset = queryset.select_related('rank', 'ban_cache', 'online_tracker')

    paginator = Paginator()
    users = paginator.paginate_queryset(queryset.order_by('slug'), request)

    make_users_status_aware(users, request.user.acl)
    return paginator.get_paginated_response(
        UserSerializer(users, many=True).data)
开发者ID:Didan,项目名称:Misago,代码行数:29,代码来源:list.py


示例4: forum_options

    def forum_options(self, request, pk=None):
        get_int_or_404(pk)
        allow_self_only(request.user, pk, _("You can't change other users options."))

        serializer = ForumOptionsSerializer(request.user, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response({'detail': _("Your forum options have been changed.")})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:10,代码来源:users.py


示例5: forum_options

    def forum_options(self, request, pk=None):
        get_int_or_404(pk)
        allow_self_only(request.user, pk, _("You can't change other users options."))

        form = ForumOptionsForm(request.data, instance=request.user)
        if form.is_valid():
            form.save()
            return Response({
                'detail': _("Your forum options have been changed.")
            })
        else:
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:1905410,项目名称:Misago,代码行数:12,代码来源:users.py


示例6: search

def search(request, search_provider=None):
    allowed_providers = searchproviders.get_allowed_providers(request)
    if not request.user.acl_cache['can_search'] or not allowed_providers:
        raise PermissionDenied(_("You don't have permission to search site."))

    search_query = get_search_query(request)
    response = []
    for provider in allowed_providers:
        provider_data = {
            'id': provider.url,
            'name': six.text_type(provider.name),
            'icon': provider.icon,
            'url': reverse('misago:search', kwargs={'search_provider': provider.url}),
            'api': reverse('misago:api:search', kwargs={'search_provider': provider.url}),
            'results': None,
            'time': None,
        }

        if not search_provider or search_provider == provider.url:
            start_time = time()

            if search_provider == provider.url:
                page = get_int_or_404(request.query_params.get('page', 1))
            else:
                page = 1

            provider_data['results'] = provider.search(search_query, page)
            provider_data['time'] = float('%.2f' % (time() - start_time))

        response.append(provider_data)
    return Response(response)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:31,代码来源:api.py


示例7: get_votes

    def get_votes(self, request, thread_pk, pk):
        poll_pk = get_int_or_404(pk)

        try:
            thread = self.get_thread(request, thread_pk)
            if thread.poll.pk != poll_pk:
                raise Http404()
        except Poll.DoesNotExist:
            raise Http404()

        allow_see_poll_votes(request.user, thread.poll)

        choices = []
        voters = {}

        for choice in thread.poll.choices:
            choice['voters'] = []
            voters[choice['hash']] = choice['voters']

            choices.append(choice)

        queryset = thread.poll.pollvote_set.values(
            'voter_id', 'voter_name', 'voter_slug', 'voted_on', 'choice_hash')

        for voter in queryset.order_by('voter_name').iterator():
            voters[voter['choice_hash']].append(PollVoteSerializer(voter).data)

        return Response(choices)
开发者ID:1905410,项目名称:Misago,代码行数:28,代码来源:threadpoll.py


示例8: test_invalid_inputs

    def test_invalid_inputs(self):
        """get_int_or_404 raises Http404 for invalid values"""
        INVALID_VALUES = (
            None,
            '',
            'bob',
            '1bob',
            'b0b',
            'bob123',
            '12.321',
            '.4',
            '5.',
        )

        for value in INVALID_VALUES:
            with self.assertRaises(Http404):
                get_int_or_404(value)
开发者ID:fengrussell,项目名称:Misago,代码行数:17,代码来源:test_shortcuts.py


示例9: get_thread

 def get_thread(self, request, pk, path_aware=False, read_aware=False, subscription_aware=False):
     return self.thread(
         request,
         get_int_or_404(pk),
         path_aware=path_aware,
         read_aware=read_aware,
         subscription_aware=subscription_aware,
     )
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:8,代码来源:threadposts.py


示例10: get_thread

 def get_thread(self, request, pk, read_aware=True, subscription_aware=True, select_for_update=False):
     return self.thread(
         request,
         get_int_or_404(pk),
         None,
         read_aware,
         subscription_aware,
         select_for_update
     )
开发者ID:l0ud,项目名称:Misago,代码行数:9,代码来源:threads.py


示例11: posts

    def posts(self, request, pk=None):
        profile = self.get_user(pk)

        page = get_int_or_404(request.query_params.get('page', 0))
        if page == 1:
            page = 0 # api allows explicit first page

        feed = UserPosts(request, profile, page)

        return Response(feed.get_frontend_context())
开发者ID:1905410,项目名称:Misago,代码行数:10,代码来源:users.py


示例12: test_valid_inputs

    def test_valid_inputs(self):
        """get_int_or_404 returns int for valid values"""
        VALID_VALUES = (
            ('0', 0),
            ('123', 123),
            ('000123', 123),
            ('1', 1),
        )

        for value, result in VALID_VALUES:
            self.assertEqual(get_int_or_404(value), result)
开发者ID:fengrussell,项目名称:Misago,代码行数:11,代码来源:test_shortcuts.py


示例13: get

    def get(self, request, list_type=None, **kwargs):
        page = get_int_or_404(request.GET.get('page', 0))

        category = self.get_category(request, **kwargs)
        threads = self.get_threads(request, category, list_type, page)

        frontend_context = self.get_frontend_context(request, category, threads)
        request.frontend_context.update(frontend_context)

        template_context = self.get_template_context(request, category, threads)
        return render(request, self.template_name, template_context)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:11,代码来源:list.py


示例14: patch_top_category

def patch_top_category(request, thread, value):
    category_pk = get_int_or_404(value)
    root_category = get_object_or_404(
        Category.objects.all_categories(include_root=True),
        pk=category_pk
    )

    categories = list(Category.objects.all_categories().filter(
        id__in=request.user.acl['visible_categories']
    ))
    add_categories_to_items(root_category, categories, [thread])
    return {'top_category': CategorySerializer(thread.top_category).data}
开发者ID:1905410,项目名称:Misago,代码行数:12,代码来源:patch.py


示例15: get_thread

    def get_thread(self, user, thread_id):
        thread = get_object_or_404(Thread.objects.select_related('category'),
            id=get_int_or_404(thread_id),
            category__tree_id=self.TREE_ID,
        )

        add_acl(user, thread.category)
        add_acl(user, thread)

        self.validate_thread_visible(user, thread)

        return thread
开发者ID:Didan,项目名称:Misago,代码行数:12,代码来源:threads.py


示例16: list

    def list(self, request, thread_pk):
        page = get_int_or_404(request.query_params.get('page', 0))
        if page == 1:
            page = 0 # api allows explicit first page

        thread = self.get_thread(request, thread_pk)
        posts = self.get_posts(request, thread, page)

        data = thread.get_frontend_context()
        data['post_set'] = posts.get_frontend_context()

        return Response(data)
开发者ID:h094071,项目名称:Misago,代码行数:12,代码来源:threadposts.py


示例17: follows

    def follows(self, request, pk=None):
        profile = self.get_user(request, pk)

        page = get_int_or_404(request.query_params.get('page', 0))
        if page == 1:
            page = 0  # api allows explicit first page

        search = request.query_params.get('search')

        users = Follows(request, profile, page, search)

        return Response(users.get_frontend_context())
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:12,代码来源:users.py


示例18: read_threads

def read_threads(user, pk):
    user.lock()

    category_id = get_int_or_404(pk)
    threads_tree_id = trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)

    category = get_object_or_404(Category, id=category_id, tree_id=threads_tree_id)

    if category.level:
        allow_see_category(user, category)
        allow_browse_category(user, category)

    read_category(user, category)
开发者ID:rafalp,项目名称:Misago,代码行数:13,代码来源:read.py


示例19: get_poll

    def get_poll(self, thread, pk):
        try:
            poll_id = get_int_or_404(pk)
            if thread.poll.pk != poll_id:
                raise Http404()

            poll = Poll.objects.select_for_update().get(pk=thread.poll.pk)

            poll.thread = thread
            poll.category = thread.category

            return poll
        except Poll.DoesNotExist:
            raise Http404()
开发者ID:1905410,项目名称:Misago,代码行数:14,代码来源:threadpoll.py


示例20: get_category

    def get_category(self, request):
        if request.query_params.get('category'):
            category_id = get_int_or_404(request.query_params['category'])
            category = get_object_or_404(
                Category.objects.select_related('parent'),
                tree_id=CATEGORIES_TREE_ID,
                id=category_id,
            )

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

            return category
        else:
            return Category.objects.root_category()
开发者ID:fengrussell,项目名称:Misago,代码行数:15,代码来源:list.py



注:本文中的misago.core.shortcuts.get_int_or_404函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shortcuts.get_object_or_404函数代码示例发布时间:2022-05-27
下一篇:
Python settings.override_setting函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap