django.shortcuts.Http404 - python examples

Here are the examples of the python api django.shortcuts.Http404 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

0 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : abhishek-ram
    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()

0 View Complete Implementation : views.py
Copyright MIT License
Author : F0RE1GNERS
  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__satle', '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:
          past
      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)