Пример #1
0
def swf_file(request):
    sbid = request.matchdict['sbid']
    req_part = request.matchdict['part']

    monograph = Monograph.get(request.db, sbid)
    if req_part == monograph.isbn:
        try:
            pdf_file = request.db.fetch_attachment(monograph._id, monograph.pdf_file['filename'])
        except (couchdbkit.ResourceNotFound, AttributeError):
            raise exceptions.NotFound()
    else:
        parts = get_book_parts(monograph._id, request)
        try:
            selected_part = parts[int(req_part)]
        except (IndexError, ValueError):
            raise exceptions.NotFound()

        part = Part.get(request.db, selected_part['part_sbid'])
        try:
            pdf_file = request.db.fetch_attachment(part._id, part.pdf_file['filename'])
        except (couchdbkit.ResourceNotFound, AttributeError):
            raise exceptions.NotFound()

    swf_file = functions.convert_pdf2swf(pdf_file)

    response = Response(content_type='application/x-shockwave-flash', expires=datetime_rfc822(365))
    response.app_iter = swf_file
    try:
        response.etag = str(hash(swf_file))
    except TypeError:
        #cannot generate a hash for the object, return it without the ETag
        pass

    return response
Пример #2
0
def swf_file(request):
    sbid = request.matchdict['sbid']
    req_part = request.matchdict['part']

    monograph = Monograph.get(request.db, sbid)
    parts = get_book_parts(monograph._id, request)
    try:
        selected_part = parts[int(req_part)]
    except (IndexError, ValueError):
        raise exceptions.NotFound()

    part = Part.get(request.db, selected_part['part_sbid'])
    try:
        pdf_file = request.db.fetch_attachment(part._id,
                                               part.pdf_file['filename'])
    except (couchdbkit.ResourceNotFound, AttributeError):
        raise exceptions.NotFound()

    swf_file = functions.convert_pdf2swf(pdf_file)

    response = Response(content_type='application/x-shockwave-flash',
                        expires=datetime_rfc822(365))
    response.app_iter = swf_file
    try:
        response.etag = str(hash(swf_file))
    except TypeError:
        #cannot generate a hash for the object, return it without the ETag
        pass

    return response
Пример #3
0
def swf_file(request):
    sbid = request.matchdict["sbid"]
    req_part = request.matchdict["part"]

    monograph = Monograph.get(request.db, sbid)
    if req_part == monograph.isbn:
        try:
            pdf_file = request.db.fetch_attachment(monograph._id, monograph.pdf_file["filename"])
        except (couchdbkit.ResourceNotFound, AttributeError):
            raise exceptions.NotFound()
    else:
        parts = get_book_parts(monograph._id, request)
        try:
            selected_part = parts[int(req_part)]
        except (IndexError, ValueError):
            raise exceptions.NotFound()

        part = Part.get(request.db, selected_part["part_sbid"])
        try:
            pdf_file = request.db.fetch_attachment(part._id, part.pdf_file["filename"])
        except (couchdbkit.ResourceNotFound, AttributeError):
            raise exceptions.NotFound()

    swf_file = functions.convert_pdf2swf(pdf_file)

    response = Response(content_type="application/x-shockwave-flash")
    response.app_iter = swf_file

    return response