django.http.HttpResponseNotFound - python examples

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

145 Examples 7

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get(self, request, cv_id, *args, **kwargs):
        try:
            wexps = Curriculum.objects.get(id=cv_id, owner=request.user).\
                work_experiences.filter(end_date__isnull=True).order_by('-start_date')
            if wexps:
                data = model_to_dict(wexps[0])
            else:
                data = {}
            return JsonResponse(data, status=200, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def delete(self, request, cv_id, skill_id, *args, **kwargs):
        try:
            Curriculum.objects.get(id=cv_id, owner=request.user).\
                skills.get(id=skill_id).delete()
            return JsonResponse('', status=204, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()
        except Skill.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_response_redirect_clast(self):
        request = self.rf.get('/slash')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/slash/')
        self.astertIsInstance(r, HttpResponsePermanentRedirect)

3 View Complete Implementation : main.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
def feature_popup_content(request):
    url = request.POST.get("url", None)

    if url is not None:
        host = "{uri.hostname}".format(uri=urlparse(url))
        try:
            if host in settings.ALLOWED_POPUP_HOSTS:
                if url is not None:
                    f = urllib.request.urlopen(url)
                    return HttpResponse(f.read())
            else:
                raise Exception()
        except:
            return HttpResponseNotFound()
    else:
        return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_redirect_querystring(self):
        """
        APPEND_SLASH should preserve querystrings when redirecting.
        """
        request = self.rf.get('/slash?test=1')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.url, '/slash/?test=1')

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_redirect_querystring_have_slash(self):
        """
        APPEND_SLASH should append slash to path when redirecting a request
        with a querystring ending with slash.
        """
        request = self.rf.get('/slash?test=slash/')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertIsInstance(r, HttpResponsePermanentRedirect)
        self.astertEqual(r.url, '/slash/?test=slash/')

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get(self, request, cv_id, skill_id, *args, **kwargs):
        try:
            skill = Curriculum.objects.get(id=cv_id, owner=request.user).\
                        skills.get(id=skill_id)
            data = model_to_dict(skill)
            return JsonResponse(data, status=200, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()
        except Skill.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_redirect_querystring_have_slash(self):
        """
        APPEND_SLASH should append slash to path when redirecting a request
        with a querystring ending with slash.
        """
        request = self.rf.get('/slash?test=slash/')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertIsInstance(r, HttpResponsePermanentRedirect)
        self.astertEqual(r.url, '/slash/?test=slash/')

3 View Complete Implementation : views.py
Copyright MIT License
Author : CCrypto
@csrf_exempt
def callback_paypal_subscr(request, id):
    """ PayPal Subscription IPN """
    if not BACKENDS['paypal'].backend_enabled:
        return HttpResponseNotFound()

    p = Subscription.objects.get(id=id)
    if BACKENDS['paypal'].callback_subscr(p, request):
        return HttpResponse()
    else:
        return HttpResponseBadRequest()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_have_slash_custom_urlconf(self):
        """
        URLs with slashes should go unmolested.
        """
        request = self.rf.get('/customurlconf/slash/')
        request.urlconf = 'middleware.extra_urls'
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : graph.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def get(self, request):
        nodegroupid = None
        try:
            nodegroupid = uuid.UUID(str(request.GET.get("nodegroupid")))
        except Exception as e:
            print(e)
        if self.action == "exportable":
            res = []
            if nodegroupid is not None:
                nodegroup = models.NodeGroup.objects.get(nodegroupid=nodegroupid)
                exportable = False if nodegroup.exportable is None else nodegroup.exportable
                res.append({"exportable": exportable})
                return JSONResponse(res)
            else:
                return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=False)
    def test_append_slash_disabled(self):
        """
        Disabling append slash functionality should leave slashless URLs alone.
        """
        request = self.rf.get('/slash')
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True, DEBUG=True)
    def test_append_slash_no_redirect_on_POST_in_DEBUG_custom_urlconf(self):
        """
        While in debug mode, an exception is raised with a warning
        when a failed attempt is made to POST to an URL which would normally be
        redirected to a slashed version.
        """
        request = self.rf.get('/customurlconf/slash')
        request.urlconf = 'middleware.extra_urls'
        request.method = 'POST'
        response = HttpResponseNotFound()
        with self.astertRaisesMessage(RuntimeError, 'end in a slash'):
            CommonMiddleware().process_response(request, response)

3 View Complete Implementation : resource.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def delete(self, request, resourceid=None):

        if resourceid is not None:
            ret = Resource.objects.get(pk=resourceid)
            ret.delete(user=request.user)
            return JSONResponse(ret)

        return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_redirect_custom_urlconf(self):
        """
        APPEND_SLASH should redirect slashless URLs to a valid pattern.
        """
        request = self.rf.get('/customurlconf/slash')
        request.urlconf = 'middleware.extra_urls'
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertIsNotNone(r, "CommonMiddleware failed to return APPEND_SLASH redirect using request.urlconf")
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/customurlconf/slash/')

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get(self, request, cv_id, workexp_id,  *args, **kwargs):
        try:
            wexp = Curriculum.objects.get(id=cv_id, owner=request.user).\
                work_experiences.get(id=workexp_id)
            data = model_to_dict(wexp)
            return JsonResponse(data, status=200, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()
        except WorkExperience.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_slashless_unknown(self):
        """
        APPEND_SLASH should not redirect to unknown resources.
        """
        request = self.rf.get('/unknown')
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def delete(self, request, cv_id, workexp_id, *args, **kwargs):
        try:
            Curriculum.objects.get(id=cv_id, owner=request.user).\
                work_experiences.get(id=workexp_id).delete()
            return JsonResponse('', status=204, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()
        except WorkExperience.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_leading_slashes(self):
        """
        Paths starting with two slashes are escaped to prevent open redirects.
        If there's a URL pattern that allows paths to start with two slashes, a
        request with path //evil.com must not redirect to //evil.com/ (appended
        slash) which is a schemaless absolute URL. The browser would navigate
        to evil.com/.
        """
        # Use 4 slashes because of RequestFactory behavior.
        request = self.rf.get('////evil.com/security')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_request(request)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/%2Fevil.com/security/')
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/%2Fevil.com/security/')

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@login_required(login_url="user-login")
def download_quote_picture(request, pk):
    quote = get_object_or_404(InspirationalQuote, pk=pk)
    try:
        filename, extension = os.path.splitext(
            quote.picture.file.name)
        extension = extension[1:]  # remove the dot
        response = FileResponse(
            quote.picture.file,
            content_type=f"image/{extension}")
        author = slugify(quote.author)[:100]
        excerpt = slugify(quote.quote)[:100]
        response["Content-Disposition"] = \
            "attachment; filename=" \
            f"{author}---{excerpt}.{extension}"
    except ValueError:
        response = HttpResponseNotFound(
            content='Picture unavailable')
    return response

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_have_slash(self):
        """
        URLs with slashes should go unmolested.
        """
        request = self.rf.get('/slash/')
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_redirect_querystring(self):
        """
        APPEND_SLASH should preserve querystrings when redirecting.
        """
        request = self.rf.get('/slash?test=1')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.url, '/slash/?test=1')

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=False)
    def test_append_slash_disabled_custom_urlconf(self):
        """
        Disabling append slash functionality should leave slashless URLs alone.
        """
        request = self.rf.get('/customurlconf/slash')
        request.urlconf = 'middleware.extra_urls'
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=False)
    def test_append_slash_disabled(self):
        """
        Disabling append slash functionality should leave slashless URLs alone.
        """
        request = self.rf.get('/slash')
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_response_redirect_clast_subclast(self):
        clast MyCommonMiddleware(CommonMiddleware):
            response_redirect_clast = HttpResponseRedirect

        request = self.rf.get('/slash')
        response = HttpResponseNotFound()
        r = MyCommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 302)
        self.astertEqual(r.url, '/slash/')
        self.astertIsInstance(r, HttpResponseRedirect)

3 View Complete Implementation : graph.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def post(self, request):
        nodegroupid = None
        try:
            nodegroupid = uuid.UUID(str(request.POST.get("nodegroupid")))
        except Exception as e:
            print(e)
        if self.action == "exportable" and nodegroupid is not None:
            exportable = json.loads(request.POST.get("exportable"))

            nodegroup = models.NodeGroup.objects.select_for_update().filter(nodegroupid=nodegroupid)
            with transaction.atomic():
                for ng in nodegroup:
                    ng.exportable = exportable
                    ng.save()

            return JSONResponse({"nodegroup": nodegroupid, "status": "success"})

        return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_response_redirect_clast(self):
        request = self.rf.get('/slash')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/slash/')
        self.astertIsInstance(r, HttpResponsePermanentRedirect)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_slashless_unknown_custom_urlconf(self):
        """
        APPEND_SLASH should not redirect to unknown resources.
        """
        request = self.rf.get('/customurlconf/unknown')
        request.urlconf = 'middleware.extra_urls'
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : graph.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def post(self, request, cardid=None):
        data = JSONDeserializer().deserialize(request.body)
        if self.action == "update_card":
            if data:
                card = Card(data)
                card.save()
                return JSONResponse(card)

        if self.action == "reorder_cards":
            if "cards" in data and len(data["cards"]) > 0:
                with transaction.atomic():
                    for card_data in data["cards"]:
                        card = models.CardModel.objects.get(pk=card_data["id"])
                        card.sortorder = card_data["sortorder"]
                        card.save()
                return JSONResponse(data["cards"])

        return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_quoted_custom_urlconf(self):
        """
        URLs which require quoting should be redirected to their slash version.
        """
        request = self.rf.get(quote('/customurlconf/needsquoting#'))
        request.urlconf = 'middleware.extra_urls'
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertIsNotNone(r, "CommonMiddleware failed to return APPEND_SLASH redirect using request.urlconf")
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/customurlconf/needsquoting%23/')

3 View Complete Implementation : resource.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def delete(self, request, resourceid=None):
        if resourceid is not None:
            ret = Resource.objects.get(pk=resourceid)
            try:
                deleted = ret.delete(user=request.user)
            except ModelInactiveError as e:
                message = _("Unable to delete. Please verify the model status is active")
                return JSONResponse({"status": "false", "message": [_(e.satle), _(str(message))]}, status=500)
            if deleted is True:
                return JSONResponse(ret)
            else:
                return JSONErrorResponse("Unable to Delete Resource", "Provisional users cannot delete resources with authoritative data")
        return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_response_redirect_clast_subclast(self):
        clast MyCommonMiddleware(CommonMiddleware):
            response_redirect_clast = HttpResponseRedirect

        request = self.rf.get('/slash')
        response = HttpResponseNotFound()
        r = MyCommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 302)
        self.astertEqual(r.url, '/slash/')
        self.astertIsInstance(r, HttpResponseRedirect)

3 View Complete Implementation : resource.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def get(self, request, resourceid=None, formid=None):
        if formid is not None:
            form = Form(resourceid=resourceid, formid=formid, user=request.user)
            return JSONResponse(form)

        return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_slashless_unknown_custom_urlconf(self):
        """
        APPEND_SLASH should not redirect to unknown resources.
        """
        request = self.rf.get('/customurlconf/unknown')
        request.urlconf = 'middleware.extra_urls'
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get(self, request, cv_id, school_id, *args, **kwargs):
        try:
            school = Curriculum.objects.get(id=cv_id, owner=request.user).\
                        schools.get(id=school_id)
            data = model_to_dict(school)
            return JsonResponse(data, status=200, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()
        except School.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=False)
    def test_append_slash_disabled_custom_urlconf(self):
        """
        Disabling append slash functionality should leave slashless URLs alone.
        """
        request = self.rf.get('/customurlconf/slash')
        request.urlconf = 'middleware.extra_urls'
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def delete(self, request, cv_id, *args, **kwargs):
        # this deletes also all related wexps, schools and skills!
        try:
            cv = Curriculum.objects.get(id=cv_id, owner=request.user)
            cv.work_experiences.all().delete()
            cv.schools.all().delete()
            cv.skills.all().delete()
            cv.delete()
            return JsonResponse('', status=204, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_leading_slashes(self):
        """
        Paths starting with two slashes are escaped to prevent open redirects.
        If there's a URL pattern that allows paths to start with two slashes, a
        request with path //evil.com must not redirect to //evil.com/ (appended
        slash) which is a schemaless absolute URL. The browser would navigate
        to evil.com/.
        """
        # Use 4 slashes because of RequestFactory behavior.
        request = self.rf.get('////evil.com/security')
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_request(request)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/%2Fevil.com/security/')
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/%2Fevil.com/security/')

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get(self, request, cv_id, *args, **kwargs):
        try:
            cv = Curriculum.objects.get(id=cv_id, owner=request.user)
            data = curriculum_to_dict(cv)
            return JsonResponse(data, status=200, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_have_slash(self):
        """
        URLs with slashes should go unmolested.
        """
        request = self.rf.get('/slash/')
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def delete(self, request, cv_id, school_id, *args, **kwargs):
        try:
            Curriculum.objects.get(id=cv_id, owner=request.user).\
                schools.get(id=school_id).delete()
            return JsonResponse('', status=204, safe=False)
        except Curriculum.DoesNotExist:
            return HttpResponseNotFound()
        except School.DoesNotExist:
            return HttpResponseNotFound()

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_redirect_custom_urlconf(self):
        """
        APPEND_SLASH should redirect slashless URLs to a valid pattern.
        """
        request = self.rf.get('/customurlconf/slash')
        request.urlconf = 'middleware.extra_urls'
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertIsNotNone(r, "CommonMiddleware failed to return APPEND_SLASH redirect using request.urlconf")
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/customurlconf/slash/')

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@login_required(login_url="user-login")
def download_quote_picture(request, pk):
    quote = get_object_or_404(InspirationalQuote, pk=pk)
    try:
        filename, extension = os.path.splitext(
            quote.picture.file.name)
        extension = extension[1:]  # remove the dot
        response = FileResponse(
            quote.picture.file,
            content_type=f"image/{extension}")
        author = slugify(quote.author)[:100]
        excerpt = slugify(quote.quote)[:100]
        response["Content-Disposition"] = \
            "attachment; filename=" \
            f"{author}---{excerpt}.{extension}"
    except ValueError:
        response = HttpResponseNotFound(
            content='Picture unavailable')
    return response

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_slashless_unknown(self):
        """
        APPEND_SLASH should not redirect to unknown resources.
        """
        request = self.rf.get('/unknown')
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_have_slash_custom_urlconf(self):
        """
        URLs with slashes should go unmolested.
        """
        request = self.rf.get('/customurlconf/slash/')
        request.urlconf = 'middleware.extra_urls'
        self.astertIsNone(CommonMiddleware().process_request(request))
        response = HttpResponseNotFound()
        self.astertEqual(CommonMiddleware().process_response(request, response), response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True, DEBUG=True)
    def test_append_slash_no_redirect_on_POST_in_DEBUG_custom_urlconf(self):
        """
        While in debug mode, an exception is raised with a warning
        when a failed attempt is made to POST to an URL which would normally be
        redirected to a slashed version.
        """
        request = self.rf.get('/customurlconf/slash')
        request.urlconf = 'middleware.extra_urls'
        request.method = 'POST'
        response = HttpResponseNotFound()
        with self.astertRaisesMessage(RuntimeError, 'end in a slash'):
            CommonMiddleware().process_response(request, response)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_quoted(self):
        """
        URLs which require quoting should be redirected to their slash version.
        """
        request = self.rf.get(quote('/needsquoting#'))
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/needsquoting%23/')

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_quoted(self):
        """
        URLs which require quoting should be redirected to their slash version.
        """
        request = self.rf.get(quote('/needsquoting#'))
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/needsquoting%23/')

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(APPEND_SLASH=True)
    def test_append_slash_quoted_custom_urlconf(self):
        """
        URLs which require quoting should be redirected to their slash version.
        """
        request = self.rf.get(quote('/customurlconf/needsquoting#'))
        request.urlconf = 'middleware.extra_urls'
        response = HttpResponseNotFound()
        r = CommonMiddleware().process_response(request, response)
        self.astertIsNotNone(r, "CommonMiddleware failed to return APPEND_SLASH redirect using request.urlconf")
        self.astertEqual(r.status_code, 301)
        self.astertEqual(r.url, '/customurlconf/needsquoting%23/')

3 View Complete Implementation : mobile_survey.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    def delete(self, request, surveyid):
        try:
            connection_error = False
            with transaction.atomic():
                if surveyid is not None:
                    ret = MobileSurvey.objects.get(pk=surveyid)
                    ret.delete()
                    return JSONResponse({"success": True})
        except Exception as e:
            if connection_error is False:
                error_satle = _("Unable to delete survey")
                if "strerror" in e and e.strerror == "Connection refused" or "Connection refused" in e:
                    error_message = _("Unable to connect to CouchDB. Please confirm that CouchDB is running")
                else:
                    error_message = e.message
                connection_error = JSONErrorResponse(error_satle, error_message)
            return connection_error

        return HttpResponseNotFound()