def upload_form(): # Get upload directory options, and convert path templates to actual paths upload_dirs = [ get_upload_directory(i) for i in range(len(app.config['IMAGE_UPLOAD_DIRS'])) ] # Add in whether the user is allowed to upload and view upload_dirs = [( udir[0], udir[1], permissions_engine.is_folder_permitted( udir[1], FolderPermission.ACCESS_UPLOAD, get_session_user(), folder_must_exist=False ), permissions_engine.is_folder_permitted( udir[1], FolderPermission.ACCESS_VIEW, get_session_user(), folder_must_exist=False ) ) for udir in upload_dirs] # Determine which radio button to pre-select dir_idx = -1 to_path = request.args.get('path', None) if not to_path or to_path == os.path.sep: # Default to the first entry that allows upload for (idx, udir) in enumerate(upload_dirs): if udir[2]: dir_idx = idx break else: # Try matching the defined paths to_path = strip_seps(to_path) for (idx, udir) in enumerate(upload_dirs): if strip_seps(udir[1]) == to_path: dir_idx = idx break # If it's a manual path, use it only if it exists manual_path = '' if dir_idx == -1 and to_path and path_exists(to_path, require_directory=True): manual_path = to_path return render_template( 'upload.html', upload_dirs=upload_dirs, sel_radio_num=dir_idx, manual_path=manual_path )
def wrap_is_folder_permitted(folder, folder_access): """ Provides a template function to return whether the current user has a particular access level to a folder. """ return permissions_engine.is_folder_permitted( folder, folder_access, get_session_user() )