Esempio n. 1
0
def add_file_to_folder(file_id, folder_id):
    user = session['user']

    # superuser can not add file to folder
    if user.id == 1:
        abort(404)

    # add file to folder
    if folder_id:
        files.add_file_to_folder(file_id, folder_id, user.id)

        return redirect(url_for('list_file'))

    folders = files.get_folders(user.id if user.id != 1 else None)

    return render_template('folders.html', folders=folders, file_id=file_id, type='addto')
Esempio n. 2
0
def upload_file():
    to_folder = request.args.get('to_folder', '')
    set_public_default = request.args.get('public_default', '') == '1'

    if re.search('^\d+$', to_folder) is None:
        to_folder = None

    if request.method == 'GET':
        return render_template('upload.html', to_folder=to_folder, set_public_default=set_public_default)

    if request.method == 'POST':
        user = session['user']
        f = files.upload_file(FILE_BASE, request, user.id)

        if to_folder:
            files.add_file_to_folder(f.id, to_folder, user.id)

        return redirect(url_for('list_file') if to_folder is None else url_for('list_folder_files', folder_id=to_folder))