当前位置: 首页>>代码示例>>Python>>正文


Python shortcuts.get_list_or_404方法代码示例

本文整理汇总了Python中django.shortcuts.get_list_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python shortcuts.get_list_or_404方法的具体用法?Python shortcuts.get_list_or_404怎么用?Python shortcuts.get_list_or_404使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.shortcuts的用法示例。


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

示例1: blog_search

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def blog_search(request,):

    search_for = request.GET['search_for']

    if search_for:
        results = []
        article_list = get_list_or_404(Article)
        category_list = get_list_or_404(Category)
        for article in article_list:
            if re.findall(search_for, article.title):
                results.append(article)
        for article in results:
            article.body = markdown.markdown(article.body, )
        tag_list = Tag.objects.all().order_by('name')
        return render(request, 'blog/search.html', {'article_list': results,
                                                    'category_list': category_list,
                                                    'tag_list': tag_list})
    else:
        return redirect('app:index') 
开发者ID:erenming,项目名称:blog,代码行数:21,代码来源:views.py

示例2: get_users_and_groups

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def get_users_and_groups(resource_permission):
    group_popover = OrderedDict()
    inactive_user = {str(user.username) for user in models.User.objects.filter(is_active=False)}
    superusers_set = {str(user.username) for user in models.User.objects.filter(is_superuser=True)}
    try:
        group_resource_permission_list = get_list_or_404(models.GroupResourcePermission,
                                                         resource_permission=resource_permission)
        groups_list = [str(obj.group.name) for obj in group_resource_permission_list]
        for obj in groups_list:
            users_set = {str(user.username) for user in get_user_model().objects.filter(groups__name=obj)}
            users_list = sorted(users_set - inactive_user)
            group_popover.setdefault('@' + obj, users_list)
    except Http404:
        pass
    group_popover.setdefault('@superusers', sorted(superusers_set - inactive_user))
    return group_popover 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:18,代码来源:views.py

示例3: preview_collection

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def preview_collection(request, slug):
    acitvities = [
        {
            'url': (
                f'{reverse("lti:source-preview")}?source_id={a.id}&source_name={urllib.parse.quote_plus(a.name)}'
                f'&source_lti_url={a.source_launch_url}&content_source_id={a.lti_content_source_id}'
            ),
            'pos': pos,
        }
        for pos, a in enumerate(get_list_or_404(Activity, collection__slug=slug), start=1)
    ]
    return render(
        request,
        template_name="module/sequence_preview.html",
        context={
            'activities': acitvities,
            'back_url': (
                f"{reverse('module:collection-detail', kwargs={'slug': slug})}"
                f"?back_url={request.GET.get('back_url')}"
            )
        }
    ) 
开发者ID:harvard-vpal,项目名称:bridge-adaptivity,代码行数:24,代码来源:views.py

示例4: test_bad_class

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def test_bad_class(self):
        # Given an argument klass that is not a Model, Manager, or Queryset
        # raises a helpful ValueError message
        msg = "First argument to get_object_or_404() must be a Model, Manager, or QuerySet, not 'str'."
        with self.assertRaisesMessage(ValueError, msg):
            get_object_or_404("Article", title__icontains="Run")

        class CustomClass:
            pass

        msg = "First argument to get_object_or_404() must be a Model, Manager, or QuerySet, not 'CustomClass'."
        with self.assertRaisesMessage(ValueError, msg):
            get_object_or_404(CustomClass, title__icontains="Run")

        # Works for lists too
        msg = "First argument to get_list_or_404() must be a Model, Manager, or QuerySet, not 'list'."
        with self.assertRaisesMessage(ValueError, msg):
            get_list_or_404([Article], title__icontains="Run") 
开发者ID:nesdis,项目名称:djongo,代码行数:20,代码来源:tests.py

示例5: _get_faculty_or_404

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def _get_faculty_or_404(allowed_units, userid_or_emplid):
    """
    Get the Person who has Role[role=~"faculty"] if we're allowed to see it, or raise Http404.
    """
    sub_unit_ids = Unit.sub_unit_ids(allowed_units)
    person = get_object_or_404(Person, find_userid_or_emplid(userid_or_emplid))
    roles = get_list_or_404(Role, role='FAC', unit__id__in=sub_unit_ids, person=person)
    units = set(r.unit for r in roles)
    return person, units 
开发者ID:sfu-fas,项目名称:coursys,代码行数:11,代码来源:views.py

示例6: get

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def get(self, request):
        empty_qs = APIRequestLog.objects.none()
        return get_list_or_404(empty_qs) 
开发者ID:aschn,项目名称:drf-tracking,代码行数:5,代码来源:views.py

示例7: get_queryset

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def get_queryset(self):
        self.tag = get_object_or_404(Tags, slug=self.kwargs.get("tag_slug"))
        return get_list_or_404(Post, tags=self.tag, status='Published', category__is_active=True) 
开发者ID:MicroPyramid,项目名称:django-blog-it,代码行数:5,代码来源:views.py

示例8: get_queryset

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def get_queryset(self):
        # 重写通用视图的 get_queryset 函数,获取定制数据
        queryset = super(IndexView, self).get_queryset()

        # 日期归档
        year = self.kwargs.get('year', 0)
        month = self.kwargs.get('month', 0)

        # 标签
        tag = self.kwargs.get('tag', 0)

        # 导航条
        self.big_slug = self.kwargs.get('bigslug', '')

        # 文章分类
        slug = self.kwargs.get('slug', '')

        if self.big_slug:
            big = get_object_or_404(BigCategory, slug=self.big_slug)
            queryset = queryset.filter(category__bigcategory=big)

            if slug:
                slu = get_object_or_404(Category, slug=slug)
                queryset = queryset.filter(category=slu)

        if year and month:
            queryset = get_list_or_404(queryset, create_date__year=year, create_date__month=month)

        if tag:
            tags = get_object_or_404(Tag, name=tag)
            self.big_slug = BigCategory.objects.filter(category__article__tags=tags)
            self.big_slug = self.big_slug[0].slug
            queryset = queryset.filter(tags=tags)

        return queryset 
开发者ID:stormsha,项目名称:blog,代码行数:37,代码来源:views.py

示例9: test_get_list_or_404_queryset_attribute_error

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import get_list_or_404 [as 别名]
def test_get_list_or_404_queryset_attribute_error(self):
        """AttributeError raised by QuerySet.filter() isn't hidden."""
        with self.assertRaisesMessage(AttributeError, 'AttributeErrorManager'):
            get_list_or_404(Article.attribute_error_objects, title__icontains='Run') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py


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