Python django.http.response.Http404() Examples

The following are 30 code examples of django.http.response.Http404(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.http.response , or try the search function .
Example #1
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get_v6(self, request, name):
        """Retrieves the details for a recipe type and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param name: The name of the recipe type
        :type name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        try:
            recipe_type = RecipeType.objects.get_details_v6(name)
        except RecipeType.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(recipe_type)
        return Response(serializer.data) 
Example #2
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get_v6(self, request, dsm_id):
        """Retrieves the details for a dataset member and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param dsm_id: The dataset member id
        :type dsm_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            dsm = DataSetMember.objects.get_details_v6(dsm_id)
        except DataSet.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(dsm)
        return Response(serializer.data) 
Example #3
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def list_v6(self, request, dataset_id):
        """Retrieves the members for a dataset version and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param dataset_id: The dataset id
        :type dataset_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            dataset = DataSet.objects.get(pk=dataset_id)
        except DataSet.DoesNotExist:
            raise Http404

        dsm = DataSetMember.objects.get_dataset_members(dataset=dataset)

        page = self.paginate_queryset(dsm)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data) 
Example #4
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def retrieve(self, request, ingest_id=None, file_name=None):
        """Determine api version and call specific method

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param ingest_id: The id of the ingest
        :type ingest_id: int encoded as a str
        :param file_name: The name of the ingest
        :type file_name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6' or request.version == 'v7':
            return self.retrieve_v6(request, ingest_id)

        raise Http404() 
Example #5
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get(self, request, scan_id):
        """Retrieves the details for a Scan process and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: The ID of the Scan process
        :type scan_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._get_v6(request, scan_id)
        elif request.version == 'v7':
            return self._get_v6(request, scan_id)

        raise Http404() 
Example #6
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def post(self, request, scan_id=None):
        """Launches a scan to ingest from an existing scan model instance

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: ID for Scan record to pull configuration from
        :type scan_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._post_v6(request, scan_id)
        elif request.version == 'v7':
            return self._post_v6(request, scan_id)

        raise Http404() 
Example #7
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def retrieve_impl(self, request, name):
        """Retrieves the details for metrics and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param name: the name of the metrics detail to retrieve.
        :type name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        try:
            metrics_type = registry.get_metrics_type(name, include_choices=True)
            serializer_class = registry.get_serializer(name) or MetricsTypeDetailsSerializer
        except MetricsTypeError:
            raise Http404

        return Response(serializer_class(metrics_type).data) 
Example #8
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def _get_v6(self, request, scan_id):
        """Retrieves the details for a Scan process and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: The ID of the Scan process
        :type scan_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            scan = Scan.objects.get_details(scan_id)
        except Scan.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(scan)
        return Response(serializer.data) 
Example #9
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def patch(self, request, scan_id):
        """Edits an existing Scan process and returns the updated details

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: The ID of the Scan process
        :type scan_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._patch_v6(request, scan_id)
        elif request.version == 'v7':
            return self._patch_v6(request, scan_id)

        raise Http404() 
Example #10
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get(self, request, strike_id):
        """Determine api version and call specific method

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :param strike_id: The ID of the Strike process
        :type strike_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self.get_impl(request, strike_id)
        elif request.version == 'v7':
            return self.get_impl(request, strike_id)

        raise Http404() 
Example #11
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get_impl(self, request, strike_id):
        """Retrieves the details for a Strike process and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param strike_id: The ID of the Strike process
        :type strike_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            is_staff = False
            if request.user:
                is_staff = request.user.is_staff
            strike = Strike.objects.get_details(strike_id, is_staff)
        except Strike.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(strike)
        return Response(serializer.data) 
Example #12
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def patch(self, request, strike_id):
        """Determine api version and call specific method

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :param strike_id: The ID of the Strike process
        :type strike_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self.patch_impl_v6(request, strike_id)
        elif request.version == 'v7':
            return self.patch_impl_v6(request, strike_id)

        raise Http404() 
Example #13
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def retrieve(self, request, batch_id):
        """Retrieves the details for a batch and returns them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param batch_id: The batch ID
        :type batch_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._retrieve_v6(batch_id)
        elif request.version == 'v7':
            return self._retrieve_v6(batch_id)

        raise Http404() 
Example #14
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def update(self, request, batch_id, **kwargs):
        """Updates the given batch

        :param request: the HTTP PATCH request
        :type request: :class:`rest_framework.request.Request`
        :param batch_id: the batch id
        :type batch_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._update_v6(request, batch_id)
        elif request.version == 'v7':
            return self._update_v6(request, batch_id)

        raise Http404() 
Example #15
Source File: views.py    From djreservation with GNU General Public License v3.0 6 votes vote down vote up
def finish_reservation(request):
    if not hasattr(request, 'reservation'):
        raise Http404(_("No reservation object started"))

    if request.method == "GET":
        response = render(
            request,
            'djreservation/reservation_confirm.html',
            {"reservation": request.reservation})
    elif request.method == "POST":
        reservation = request.reservation
        reservation.status = reservation.REQUESTED
        reservation.save()
        request.reservation = None
        send_reservation_email(reservation, request.user)
        response = render(
            request, 'djreservation/reservation_finished.html')
        response.set_cookie("reservation", "0")
        messages.success(request, _('Reservation finised'))
    return response 
Example #16
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get(self, request, root_batch_id):
        """Validates a new batch

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param root_batch_id: The root batch ID
        :type root_batch_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._get_v6(request, root_batch_id)
        elif request.version == 'v7':
            return self._get_v6(request, root_batch_id)

        raise Http404() 
Example #17
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get_v6(self, request, name, revision_num):
        """Retrieves the list of all recipe type revisions returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param name: The name of the recipe type
        :type name: string
        :param revision_num: The revision number of the job type
        :type revision_num: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            recipe_type_rev = RecipeTypeRevision.objects.get_revision(name, revision_num)
        except RecipeTypeRevision.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(recipe_type_rev)
        return Response(serializer.data) 
Example #18
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def retrieve(self, request, recipe_id):
        """Retrieves the details for a recipe and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param recipe_id: The id of the recipe
        :type recipe_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._retrieve_v6(request, recipe_id)
        elif request.version == 'v7':
            return self._retrieve_v6(request, recipe_id)

        raise Http404() 
Example #19
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def _retrieve_v6(self, request, recipe_id):
        """Retrieves the details for a recipe and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param recipe_id: The id of the recipe
        :type recipe_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            recipe = Recipe.objects.get_details(recipe_id)
        except Recipe.DoesNotExist:
            raise Http404

        serializer = self.serializer_class(recipe)
        return Response(serializer.data) 
Example #20
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def post(self, request, recipe_id):
        """Schedules a recipe for reprocessing and returns it in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param recipe_id: The id of the recipe
        :type recipe_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._post_v6(request, recipe_id)
        elif request.version == 'v7':
            return self._post_v6(request, recipe_id)

        raise Http404() 
Example #21
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get_v6(self, request):
        """Gets v6 scheduler info

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            scheduler = Scheduler.objects.get_master()
        except Scheduler.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(scheduler)
        return Response(serializer.data) 
Example #22
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def retrieve(self, request, file_id):
        """Determine api version and call specific method

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :param file_id: The id of the file
        :type file_id: int encoded as a string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self.retrieve_impl(request, file_id)
        elif request.version == 'v7':
            return self.retrieve_impl(request, file_id)

        raise Http404() 
Example #23
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def retrieve_impl(self, request, file_id):
        """Retrieves the details for a file and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param file_id: The id of the file
        :type file_id: int encoded as a string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            scale_file = ScaleFile.objects.get_details(file_id)
        except ScaleFile.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(scale_file)
        return Response(serializer.data) 
Example #24
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get(self, request, workspace_id):
        """Retrieves the details for a workspace and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param workspace_id: The id of the workspace
        :type workspace_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._get_v6(request, workspace_id)
        elif request.version == 'v7':
            return self._get_v6(request, workspace_id)

        raise Http404() 
Example #25
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def _get_v6(self, request, workspace_id):
        """Retrieves the details for a workspace and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param workspace_id: The id of the workspace
        :type workspace_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            is_staff = False
            if request.user:
                is_staff = request.user.is_staff
            workspace = Workspace.objects.get_details(workspace_id, is_staff)
        except Workspace.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(workspace)
        return Response(serializer.data) 
Example #26
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def patch(self, request, workspace_id):
        """Edits an existing workspace and returns the updated details

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param workspace_id: The id of the workspace
        :type workspace_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._patch_v6(request, workspace_id)
        elif request.version == 'v7':
            return self._patch_v6(request, workspace_id)

        raise Http404() 
Example #27
Source File: views.py    From scale with Apache License 2.0 6 votes vote down vote up
def get_impl(self, request, node_id):
        """Gets node info

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param node_id: The ID for the node.
        :type node_id: str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            node = Node.objects.get_details(node_id)
        except Node.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(node)
        return Response(serializer.data) 
Example #28
Source File: decorators.py    From janeway with GNU Affero General Public License v3.0 6 votes vote down vote up
def editor_is_not_author(func):
    """
    This decorator confirms that the current user is not an author on an article. Can only be used where there is a
    article_id keyword arg.
    :param func: the function to callback from the decorator
    :return: the function call or a permission denied
    """

    def wrapper(request, *args, **kwargs):
        article_id = kwargs.get('article_id', None)

        if not article_id:
            raise Http404

        article = get_object_or_404(models.Article, pk=article_id)

        if request.user in article.authors.all() and not article.editor_override(request.user):
            return redirect(reverse('review_warning', kwargs={'article_id': article.pk}))

        return func(request, *args, **kwargs)

    return wrapper 
Example #29
Source File: decorators.py    From janeway with GNU Affero General Public License v3.0 6 votes vote down vote up
def senior_editor_user_required(func):
    """ This decorator checks that a user is an editor, Note that this decorator does NOT check for conflict of interest
    problems. Use the article_editor_user_required decorator (not yet written) to do a check against an article.

    :param func: the function to callback from the decorator
    :return: either the function call or raises an Http404
    """

    @base_check_required
    def wrapper(request, *args, **kwargs):

        if request.user.is_editor(request) or request.user.is_staff:
            return func(request, *args, **kwargs)

        else:
            deny_access(request)

    return wrapper 
Example #30
Source File: decorators.py    From janeway with GNU Affero General Public License v3.0 6 votes vote down vote up
def reviewer_user_required(func):
    """ This decorator checks that a user is a reviewer, Note that this decorator does NOT check for conflict of
    interest problems. Use the article_editor_user_required decorator (not yet written) to do a check against an
    article.

    :param func: the function to callback from the decorator
    :return: either the function call or raises an Http404
    """

    @base_check_required
    def wrapper(request, *args, **kwargs):

        if request.user.is_reviewer(request) or request.user.is_staff:
            return func(request, *args, **kwargs)
        else:
            deny_access(request)

    return wrapper