Exemplo n.º 1
0
def conv(id):
    settings = {}
    for key, value in request.values.items():
        settings[key] = value
        if value.isdigit():
            settings[key] = int(value)
        if value == 'true':
            settings[key] = True
        if value == 'false':
            settings[key] = False
    extension = settings['extension']
    file = File.query.get(id)
    path = file.path
    basename = Tools.get_basename(file.name)
    new_name = (basename + '.' + extension).encode('utf-8')
    document = Document(path)
    properties = document.get_export_options(extension)
    properties['FilterData'] = settings
    document.set_properties(properties)
    # return jsonify({
    #     'id': id,
    #     'settings': settings,
    #     'options': options,
    #     'export_options': document.get_export_options(extension),
    #     'arguments': dir(document.arguments),
    #     'statistics': document.get_statistics(),
    #     'get_settings': file.get_settings()
    # })
    new = path + '.' + extension
    save = document.save(new)
    if save is False:
        return jsonify({
            'error': 'File not saved'
        })
    type = mimetypes.guess_type(urllib.pathname2url(new_name))
    model = File.query.filter_by(path=new).first()
    if model is None:
        model = File()
    model.user_id = g.user.id
    model.name = new_name.decode('utf-8')
    model.path = new
    model.size = os.path.getsize(new)
    model.type = type[0]
    model.extension = extension
    db.session.add(model)
    db.session.commit()
    return jsonify({
        'save': save,
        'name': new_name,
        'url': '/download/' + str(model.id),
        'type': type[0],
        'path': new,
        'properties': properties
    })
Exemplo n.º 2
0
def convert():
    upload = Tools.upload()
    path = upload['path']
    basename = Tools.get_basename(upload['name'])
    new_name = (basename + '.pdf').encode('utf-8')
    document = Document(upload['path'])
    new = path + '.pdf'
    save = document.save(new)
    user_id = 1
    type = mimetypes.guess_type(urllib.pathname2url(new_name))
    model = File(user_id=user_id,
                 name=new_name.decode('utf-8'),
                 path=new,
                 type=type[0])
    db.session.add(model)
    db.session.commit()
    return jsonify({
        'save': save,
        'name': new_name,
        'url': '/download/' + str(model.id),
        'type': type[0],
        'path': new
    })