django.http.HttpResponseGone - python examples

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

9 Examples 7

3 View Complete Implementation : base.py
Copyright MIT License
Author : rizwansoaib
    def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return HttpResponsePermanentRedirect(url)
            else:
                return HttpResponseRedirect(url)
        else:
            logger.warning(
                'Gone: %s', request.path,
                extra={'status_code': 410, 'request': request}
            )
            return HttpResponseGone()

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : sunshaoyan
def get_image(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        try:
            server = ImageServer.objects.get(id=db_image.server)
            if server.server_name != settings.SERVER_NAME:
                return HttpResponseBadRequest("Image Not On This Server")
        except ImageServer.DoesNotExist:
            return HttpResponseServerError("Image Server Does Not Exist!")
        image_data = open(db_image.path, 'rb').read()
        mime_type = db_image.mime_type
        return HttpResponse(image_data, content_type=mime_type)
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except IOError:
        return HttpResponseGone("Image Moved")

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : sunshaoyan
def get_thumbnail(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        thumbnail = db_image.get_thumbnail()
        image_data = thumbnail.file.read()
        mime_type = thumbnail.mime_type
        return HttpResponse(image_data, content_type=mime_type)
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except IOError:
        return HttpResponseGone("Image Moved")

3 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : sunshaoyan
def get_image(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        mime_type = db_image.mime_type
        try:
            server = ImageServer.objects.get(id=db_image.server)
            ip = server.server_ip
            port = request.META['SERVER_PORT']
            url_ext = reverse('image_server:get_image', args=(str(id) ,))
            remote_url = 'http://' + ip + ':' + str(port) + url_ext
            image_data = urllib.request.urlopen(remote_url).read()
            return HttpResponse(image_data, content_type=mime_type)
        except ImageServer.DoesNotExist:
            return HttpResponseServerError("Image Server Does Not Exist!")
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except:
        return HttpResponseGone("Image Moved")

0 View Complete Implementation : middleware.py
Copyright Apache License 2.0
Author : edisonlz
    def process_response(self, request, response):
        if response.status_code != 404:
            return response # No need to check for a redirect for non-404 responses.

        full_path = request.get_full_path()
        current_site = get_current_site(request)

        r = None
        try:
            r = Redirect.objects.get(site=current_site, old_path=full_path)
        except Redirect.DoesNotExist:
            past
        if settings.APPEND_SLASH and not request.path.endswith('/'):
            # Try appending a trailing slash.
            path_len = len(request.path)
            full_path = full_path[:path_len] + '/' + full_path[path_len:]
            try:
                r = Redirect.objects.get(site=current_site, old_path=full_path)
            except Redirect.DoesNotExist:
                past
        if r is not None:
            if r.new_path == '':
                return http.HttpResponseGone()
            return http.HttpResponsePermanentRedirect(r.new_path)

        # No redirect was found. Return the response.
        return response

0 View Complete Implementation : middlewares.py
Copyright MIT License
Author : michaelhenry
    def process_response(self, request, response):
        
        snapshot_key = request.GET.get('snapshot')
        format = request.GET.get('format')
        if snapshot_key and format:
           
            filename = request.path.split('/')[-1]
            locale_code = filename.split('.')[-1]
            app_slug = filename.split('.')[0]
            content_type = response['Content-Type']

            snapshot, created = Snapshot.objects.get_or_create(
                key=snapshot_key,
                app_slug=app_slug,
                format=format,
            )

            if not created:
                snapshot_file = None
                snapshot_file_query = SnapshotFile.objects.filter(
                    snapshot=snapshot, 
                    locale_code=locale_code)

                if snapshot_file_query.exists():
                    snapshot_file = snapshot_file_query.first()
                else:

                    if timezone.now() > (snapshot.created + timedelta(hours=12)):
                        return HttpResponseGone()
                    content = response.content

                    snapshot_file = SnapshotFile(snapshot=snapshot, locale_code=locale_code)
                    snapshot_file.key = snapshot_key
                    snapshot_file.file.save(filename, ContentFile(content))
                    snapshot_file.save()

                return HttpResponseRedirect(snapshot_file.file.url, content_type=content_type)
        return response

0 View Complete Implementation : utils.py
Copyright Apache License 2.0
Author : pmac
def gone_view(request, *args, **kwargs):
    return HttpResponseGone()

0 View Complete Implementation : views.py
Copyright Apache License 2.0
Author : sunshaoyan
def get_thumbnail(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        mime_type = db_image.mime_type
        try:
            server = ImageServer.objects.get(id=db_image.server)
            ip = server.server_ip
            port = request.META['SERVER_PORT']
            url_ext = reverse('image_server:get_thumbnail', args=(str(id) ,))
            remote_url = 'http://' + ip + ':' + str(port) + url_ext
            print(remote_url)
            image_data = urllib.request.urlopen(remote_url).read()
            return HttpResponse(image_data, content_type=mime_type)
        except ImageServer.DoesNotExist:
            return HttpResponseServerError("Image Server Does Not Exist!")
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except Exception as e:
        print(e)
        return HttpResponseGone("Image Moved")

0 View Complete Implementation : apiv1.py
Copyright MIT License
Author : wise-team
def apiv1_gone(request):
    return HttpResponseGone(apiv1_gone_msg)