Ejemplo n.º 1
0
def media_view_image(request, mediatype, username, slug):
    """A view which returns the raw image"""
    resource = media_view(request, mediatype, username, slug, piston=True)
    if not resource:
        raise Http404()

    if type(resource) is not Photo:
        raise Http404('Not a photo')

    options = _parse_media_args(request)

    if options['h'] == 0 and options['w'] == 0 and options['footer'] and options['extended']:
        do_resize = False
    else:
        do_resize = options['h'] > 0 or options['w'] > 0 or options['footer'] or options['extended']

    if do_resize:
        img, fn = resource.resized(**options)
    else:
        log.debug('returning base display file')
        fn = resource.display.file.name

    log.debug('media file: %s', fn)
    data = open(fn,'r').read()

    imgtype = imghdr.what(resource.image.file.name, data)
    return HttpResponse(data, mimetype='image/%s' % imgtype)
Ejemplo n.º 2
0
    def read(self, request, mediatype=None, username=None, slug=None):
        log.debug("MediaViewHandler read: %s, %s, %s", mediatype, username, slug)
        try:
            resource = media_view(request, mediatype, username, slug, piston=True)
            for field in ("_state", "_owner_cache", "child_attrpath"):
                if hasattr(resource, field):
                    setattr(resource, field, None)
            log.debug("got resource: %s", resource)

        except Http404:
            log.debug("404")
            return rc.NOT_FOUND

        except PermissionDenied:
            log.debug("Denied")
            return rc.FORBIDDEN

        rtype = type(resource)
        if rtype is HttpResponseNotFound:
            log.debug("Not Found")
            return rc.NOT_FOUND

        if rtype is HttpResponseBadRequest:
            log.debug("Bad request")
            return rc.BAD_REQUEST

        log.debug("returning resource")
        return resource
Ejemplo n.º 3
0
    def read(self, request, mediatype=None, username=None, slug=None):
        log.debug('MediaViewHandler read: %s, %s, %s', mediatype, username, slug)
        try:
            resource = media_view(request, mediatype, username, slug, piston=True)
            log.debug('got resource: %s', resource)

        except Http404:
            log.debug('404')
            return rc.NOT_FOUND

        except PermissionDenied:
            log.debug('Denied')
            return rc.FORBIDDEN

        rtype = type(resource)
        if rtype is HttpResponseNotFound:
            log.debug('Not Found')
            return rc.NOT_FOUND

        if rtype is HttpResponseBadRequest:
            log.debug('Bad request')
            return rc.BAD_REQUEST

        log.debug('returning resource')
        return resource
Ejemplo n.º 4
0
def media_image_caption(request, mediatype, username, slug):
    """A view which returns the raw image caption"""
    log.debug("getting caption .................................... %s %s %s", mediatype, username, slug)
    auth = IPUserAuthentication()
    if not auth.is_authenticated(request):
        return auth.challenge()
    resource = media_view(request, mediatype, username, slug, piston=True)
    log.debug("got resource: %s", resource)
    if not resource:
        raise Http404()

    if type(resource) is not Photo:
        raise Http404("Not a photo")

    log.debug("returning caption: %s", resource.title)
    return HttpResponse(resource.title, mimetype="text/plain")
Ejemplo n.º 5
0
def media_view_image(request, mediatype, username, slug):
    """A view which returns the raw image"""
    auth = IPUserAuthentication()
    if not auth.is_authenticated(request):
        return auth.challenge()
    resource = media_view(request, mediatype, username, slug, piston=True)
    if not resource:
        raise Http404()

    if type(resource) is not Photo:
        raise Http404("Not a photo")

    options = _parse_media_args(request)

    img, fn = resource.resized(**options)

    log.debug("media file: %s", fn)
    data = open(fn, "r").read()

    imgtype = imghdr.what(resource.image.file.name, data)
    return HttpResponse(data, mimetype="image/%s" % imgtype)