Esempio n. 1
0
def index():
    print(request.form)
    # if request.method == 'GET':
    db = JsonDB()
    db.load()
    print(request.form)
    if request.method == 'POST':
        db['todos'].append({
            'text': request.form['text'],
            'priority': request.form['priority']
        })
        db.save()

    return render_template("index.html", todo=db['todos'])
Esempio n. 2
0
def create():
    # print(request.method)
    # print(request.form)
    db = JsonDB()
    db.load()
    if request.method == 'POST':
        db['contacts'].append({
            'first_name': request.form['first_name'],
            'last_name': request.form['last_name'],
            'phone': request.form['phone'],
            'email': request.form['email'],
            'blood_type': request.form['blood_type'],
            'favorite_color': request.form['favorite_color']
        })
        db.save()
        return redirect('/')
    return render_template('create.html', blood_types=db['blood_types'])
Esempio n. 3
0
def get_file(request, id_file, config):
    # First, open JsonDB for read-only
    db = JsonDB(dbfile=config['FILE_LIST'])
    db.load()
    if id_file not in db.db or db.db[id_file]['burn_after_read'] == 'Burned':
        return abort(404)
    if db.db[id_file]['burn_after_read'] == 'True':
        # Now, try to lock the db
        if not db._lock():
            return "Can't lock db for burning file"
        db.db[id_file]['burn_after_read'] = 'Burned'
        db.save()
        db._release()

    filename = os.path.basename(db.db[id_file]['storage_full_filename'])
    LOG.info("[GET] Client %s has requested: %s (%s)"
             % (request.remote_addr, db.db[id_file]['real_name'], id_file))

    if not os.path.isabs(config['UPLOAD_FOLDER']):
        path = "%s/%s" % (os.path.dirname(config['instance_path']),
                          config['UPLOAD_FOLDER'])
    else:
        path = config['UPLOAD_FOLDER']

    # If the user agent is in the display list,
    # format headers to direct display feature
    if request.user_agent.browser in config['DISPLAY_FOR']:
        return send_from_directory(path,
                                   filename,
                                   mimetype=db.db[id_file]['mime_type'],
                                   attachment_filename=db.db[id_file]
                                   ['real_name'])

    # Else keep the regular send file
    return send_from_directory(path,
                               filename,
                               mimetype=db.db[id_file]['mime_type'],
                               attachment_filename=db.db[id_file]['real_name'],
                               as_attachment=True)
Esempio n. 4
0
def get_file(request, id_file, config):
    # First, open JsonDB for read-only
    db = JsonDB(dbfile=config['FILE_LIST'])
    db.load()
    if id_file not in db.db or db.db[id_file]['burn_after_read'] == 'Burned':
        return abort(404)
    if db.db[id_file]['burn_after_read'] == 'True':
        # Now, try to lock the db
        if not db._lock():
            return "Can't lock db for burning file"
        db.db[id_file]['burn_after_read'] = 'Burned'
        db.save()
        db._release()

    filename = os.path.basename(db.db[id_file]['storage_full_filename'])
    LOG.info("[GET] Client %s has requested: %s (%s)"
             % (request.remote_addr, db.db[id_file]['real_name'], id_file))

    if not os.path.isabs(config['UPLOAD_FOLDER']):
        path = "%s/%s" % (os.path.dirname(config['instance_path']),
                          config['UPLOAD_FOLDER'])
    else:
        path = config['UPLOAD_FOLDER']

    # If the user agent is in the display list, format headers to direct display feature
    if request.user_agent.browser in config['DISPLAY_FOR']:
        return send_from_directory(path,
                                   filename,
                                   mimetype=db.db[id_file]['mime_type'],
                                   attachment_filename=db.db[id_file]['real_name'])

    # Else keep the regular send file
    return send_from_directory(path,
                               filename,
                               mimetype=db.db[id_file]['mime_type'],
                               attachment_filename=db.db[id_file]['real_name'],
                               as_attachment=True)
Esempio n. 5
0
def delete(index):
    db = JsonDB()
    db.load()
    db['contacts'].pop(index)
    db.save()
    return redirect('/')