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


Python shortcuts.Http404方法代码示例

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


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

示例1: user_profile

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def user_profile(username):
    user = get_object_or_404(User.objects.select_related('userinfo', 'userinfo__avatar'), username=username)

    if not user.is_active:
        raise Http404("Deactivated user.")

    follow_counts = following_models.counts(user)

    return {
        'user': user.details(),
        'bio': user.userinfo.bio_text,
        'quest_completion_count': Quest.completed_by_user_count(user),
        'follower_count': follow_counts['followers'],
        'following_count': follow_counts['following'],
    }

# Cache invalidation for user_profile. 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:19,代码来源:models.py

示例2: get

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def get(self, request, obj_type, obj_id, *args, **kwargs):
        filename = ""
        file_content = ""
        # Get the file content based
        if obj_type == "message_payload":
            obj = get_object_or_404(Message, pk=obj_id)
            filename = os.path.basename(obj.payload.name)
            file_content = obj.payload.read()

        elif obj_type == "mdn_payload":
            obj = get_object_or_404(Mdn, pk=obj_id)
            filename = os.path.basename(obj.payload.name)
            file_content = obj.payload.read()

        elif obj_type == "public_cert":
            obj = get_object_or_404(PublicCertificate, pk=obj_id)
            filename = obj.name
            file_content = obj.certificate

        elif obj_type == "private_key":
            obj = get_object_or_404(PrivateKey, pk=obj_id)
            filename = obj.name
            file_content = obj.key

        # Return the file contents as attachment
        if filename and file_content:
            response = HttpResponse(content_type="application/x-pem-file")
            disposition_type = "attachment"
            response["Content-Disposition"] = (
                disposition_type + "; filename=" + filename
            )
            response.write(bytes(file_content))
            return response
        else:
            raise Http404() 
开发者ID:abhishek-ram,项目名称:django-pyas2,代码行数:37,代码来源:views.py

示例3: non_proposal_schedule_item_view

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def non_proposal_schedule_item_view(request, sch_item_id):
    try:
        sch_item = ScheduleItem.objects.get(pk=sch_item_id)
        return render(
            request, "proposals/detail/schedule-item.html", {"sch_item": sch_item}
        )
    except ObjectDoesNotExist:
        raise Http404() 
开发者ID:pythonindia,项目名称:junction,代码行数:10,代码来源:views.py

示例4: admin_network_form

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def admin_network_form(request):
    """
    Ajax page for updating, removing and adding networks.
    """
    qs = request.GET.copy()

    if request.POST['action'] == 'update':
        try:
            net = Subnet.objects.select_related('owner', 'dc_bound').get(name=request.POST['adm-name'])
        except Subnet.DoesNotExist:
            raise Http404
    else:
        net = None

    form = AdminNetworkForm(request, net, request.POST, prefix='adm')

    if form.is_valid():
        args = (form.cleaned_data['name'],)
        status = form.save(args=args)

        if status == 204:
            return HttpResponse(None, status=status)
        elif status in (200, 201):
            if form.action == 'create' and not form.cleaned_data.get('dc_bound'):
                qs['all'] = 1  # Show all items if adding new item and not attaching

            # Redirect to ip list or network list depending on ips parameter
            if request.GET.get('ips', False):
                redir_view = 'dc_network_ip_list'
                redir_args = (net.name,)
            else:
                redir_view = 'dc_network_list'
                redir_args = ()

            return redirect(redir_view, *redir_args, query_string=qs)

    return render(request, 'gui/dc/network_admin_form.html', {'form': form, 'nodc': request.GET.get('ips', '')}) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:39,代码来源:views.py

示例5: network_ip_form

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def network_ip_form(request, name):
    """
    Ajax page for updating, removing and adding network IP address(es).
    """
    try:
        net = Subnet.objects.get(name=name)
    except Subnet.DoesNotExist:
        raise Http404

    form_class = NetworkIPForm

    if request.POST['action'] == 'update':
        try:
            ip = IPAddress.objects.get(subnet=net, ip=request.POST.get('ip'))
        except IPAddress.DoesNotExist:
            raise Http404
    else:
        ip = None
        if request.POST.get('ips', False):
            form_class = MultiNetworkIPForm

    form = form_class(request, net, ip, request.POST)

    if form.is_valid():
        status = form.save(args=form.api_call_args(name))

        if status == 204:
            return HttpResponse(None, status=status)
        elif status in (200, 201):
            messages.success(request, form.get_action_message())
            return redirect('dc_network_ip_list', net.name, query_string=request.GET)

    return render(request, form.template, {'form': form, 'net': {'name': name}}) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:35,代码来源:views.py

示例6: dc_subnet_ip_list

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def dc_subnet_ip_list(request, network, netmask, vlan_id):
    context = collect_view_data(request, 'dc_network_list')
    context['is_staff'] = request.user.is_staff

    try:
        context['ip_network'] = ip_network = Subnet.get_ip_network(network, netmask)  # Invalid IPv4 network
        context['vlan_id'] = int(vlan_id)
    except ValueError:
        raise Http404

    network, netmask = ip_network.with_netmask.split('/')
    context['netinfo'] = Subnet.get_ip_network_hostinfo(ip_network)
    nets = Subnet.objects.filter(network=network, netmask=netmask, vlan_id=vlan_id)
    context['num_networks'] = num_networks = nets.count()

    if not num_networks:
        raise Http404  # Invalid user input - made-up IPv4network

    context['order_by'], order_by = get_order_by(request, api_view=NetworkIPPlanView)
    ips = IPAddress.objects.select_related('vm', 'vm__dc', 'subnet')\
                           .prefetch_related('vms')\
                           .filter(subnet__in=nets)\
                           .order_by(*order_by).distinct()
    context['ips'] = context['pager'] = pager = get_pager(request, ips, per_page=50)
    context['total'] = pager.paginator.count
    context['free'] = ips.filter(usage=IPAddress.VM, vm__isnull=True, vms=None).count()

    return render(request, 'gui/dc/subnet_ip_list.html', context) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:30,代码来源:views.py

示例7: create_proposal_comment

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def create_proposal_comment(request, conference_slug, proposal_slug):
    conference = get_object_or_404(Conference, slug=conference_slug)
    proposal = get_object_or_404(Proposal, slug=proposal_slug, conference=conference)
    form = ProposalCommentForm(request.POST)

    if request.user.is_active is False:
        raise PermissionDenied()

    if form.is_valid():
        comment = form.cleaned_data["comment"]
        private = form.cleaned_data["private"]
        reviewer = form.cleaned_data["reviewer"]

        has_perm = permissions.is_proposal_author_or_proposal_section_reviewer(
            user=request.user, conference=conference, proposal=proposal
        )

        if private and not has_perm:
            raise Http404()

        proposal_comment = ProposalComment.objects.create(
            proposal=proposal,
            comment=comment,
            private=private,
            reviewer=reviewer,
            commenter=request.user,
        )
        host = "{}://{}".format(settings.SITE_PROTOCOL, request.META.get("HTTP_HOST"))

        if settings.USE_ASYNC_FOR_EMAIL:
            send_mail_for_new_comment.delay(proposal_comment.id, host)
        else:
            send_mail_for_new_comment(proposal_comment.id, host)

    redirect_url = reverse("proposal-detail", args=[conference.slug, proposal.slug])

    if private:
        redirect_url += "#js-reviewers"
    elif reviewer:
        redirect_url += "#js-only-reviewers"
    else:
        redirect_url += "#js-comments"

    return HttpResponseRedirect(redirect_url) 
开发者ID:pythonindia,项目名称:junction,代码行数:46,代码来源:comments_views.py

示例8: get_queryset

# 需要导入模块: from django import shortcuts [as 别名]
# 或者: from django.shortcuts import Http404 [as 别名]
def get_queryset(self):
    try:
      queryset = self.get_selected_from().select_related('problem', 'author'). \
        only('pk', 'contest_id', 'create_time', 'author_id', 'author__username',
             'author__magic', 'problem_id', 'problem__title', 'lang', 'status', 'status_time', 'status_percent',
             'code_length', 'ip', 'status_test', 'status_memory', 'visible', 'judge_server', 'contest_time')

      if 'user' in self.request.GET:
        queryset = queryset.filter(author_id=self.request.GET['user'])
      if self.allow_problem_query and 'problem' in self.request.GET:
        problem_id = self.reinterpret_problem_identifier(self.request.GET['problem'])
        try:
          if is_problem_manager(self.request.user, Problem.objects.get(pk=problem_id)):
            self.privileged = True
          queryset = queryset.filter(problem_id=problem_id)
        except:
          pass
      if 'lang' in self.request.GET:
        queryset = queryset.filter(lang=self.request.GET['lang'])
      if self.allow_verdict_query and 'verdict' in self.request.GET:
        queryset = queryset.filter(status=int(self.request.GET['verdict'][1:]))

      if is_admin_or_root(self.request.user):
        self.privileged = True
      if not self.privileged:
        queryset = queryset.filter(visible=True)
      if not self.privileged and not self.contest_submission_visible:
        queryset = queryset.filter(contest__isnull=True)

      ordering = self.get_ordering()
      if ordering is not None:
        if isinstance(ordering, str):
          ordering = (ordering,)
        queryset = queryset.order_by(*ordering)

      if self.distinct_by_author:
        author_set = set()
        res = []
        for submission in queryset.all():
          if submission.author_id not in author_set:
            author_set.add(submission.author_id)
            res.append(submission)
            if self.query_number and len(res) >= self.query_number:
              break
        return res
      else:
        return queryset.all()[:self.query_number]
    except Exception as e:
      raise Http404(e) 
开发者ID:F0RE1GNERS,项目名称:eoj3,代码行数:51,代码来源:views.py


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