Beispiel #1
0
def download(item_name):
    item_name = encode(item_name)
    c = get_class_for_item(item_name)
    if c:
        item = c(item_name, flask.request.args)
        if item.user_may_download():
            raw_path = item.raw_path()
            if os.path.isfile(raw_path):
                return flask.send_file(raw_path, as_attachment=True)
            elif os.path.isdir(raw_path):
                def add_to_archive(arc, item):
                    for entry in item.itemlist():
                        if os.path.isfile(entry.raw_path()):
                            arc.write(entry.raw_path(), entry._rel_path)
                        else:
                            add_to_archive(arc, entry)
                mf = StringIO.StringIO()
                with zipfile.ZipFile(mf, mode='w', compression=zipfile.ZIP_STORED) as zf:
                    add_to_archive(zf, item)
                response = flask.make_response(mf.getvalue())
                response.headers['Content-Type'] = 'application/zip'
                response.headers["Content-Disposition"] = 'attachment; filename="%s.zip"' % item.name()
                return response
        flask.abort(404)
    else:
        # TODO: implement answer
        return '!!! not yet implemented !!!'
Beispiel #2
0
def raw(item_name):
    item_name = encode(item_name)
    c = get_class_for_item(item_name)
    if c:
        item = c(item_name, flask.request.args)
        if item.user_may_download():
            raw_path = item.raw_path()
            if os.path.isfile(raw_path):
                return flask.send_file(raw_path)
        flask.abort(404)
    else:
        # TODO: implement answer
        return '!!! not yet implemented !!!'