def generate_files(self):
        """
        generate_data method

        generate random file data so we can map it

        """

        # generate 500 file records
        total_records = 500
        messagelog = []

        for i in range(total_records):
            # create new file entity
            download_count = random.randint(1, 10)
            file_name = uuid.uuid4()
            new_file = File()
            new_file.name = str(file_name) + '.txt'
            new_file.download_count = download_count
            new_file.put()
            messagelog.append("File added: {0} - {1}".format(i, new_file.name))

        context = {'messagelog': messagelog}

        self.render_response('file.html', context=context)
Esempio n. 2
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
    })