當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。