Manual codefactor fixes

This commit is contained in:
simon987 2019-03-10 15:27:55 -04:00
parent 7ccc1f14d1
commit 089543d7b7

28
run.py
View File

@ -37,7 +37,6 @@ def get_dir_size(path):
def user_manage(user): def user_manage(user):
if "admin" in session and session["admin"]: if "admin" in session and session["admin"]:
return render_template("user_manage.html", directories=storage.dirs(), user=storage.users()[user]) return render_template("user_manage.html", directories=storage.dirs(), user=storage.users()[user])
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -77,7 +76,6 @@ def user_page():
if not admin_account_present or ("admin" in session and session["admin"]): if not admin_account_present or ("admin" in session and session["admin"]):
return render_template("user.html", users=storage.users(), admin_account_present=admin_account_present) return render_template("user.html", users=storage.users(), admin_account_present=admin_account_present)
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -98,7 +96,6 @@ def user_set_access(username):
flash("Permissions mises à jour", "success") flash("Permissions mises à jour", "success")
return redirect("/user/" + username) return redirect("/user/" + username)
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -142,7 +139,6 @@ def user_add():
"Make sure that the username is unique", "danger") "Make sure that the username is unique", "danger")
return redirect("/user") return redirect("/user")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -154,11 +150,9 @@ def user_del(username):
if session["username"] == username: if session["username"] == username:
flash("You cannot delete your own account", "warning") flash("You cannot delete your own account", "warning")
return redirect("/user/" + username) return redirect("/user/" + username)
else:
storage.remove_user(username) storage.remove_user(username)
flash("User deleted", "success") flash("User deleted", "success")
return redirect("/user") return redirect("/user")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -179,7 +173,8 @@ def document(doc_id):
@app.route("/dl/<doc_id>") @app.route("/dl/<doc_id>")
def file(doc_id): def serve_file(doc_id):
doc = search.get_doc(doc_id)["_source"] doc = search.get_doc(doc_id)["_source"]
directory = storage.dirs()[doc["directory"]] directory = storage.dirs()[doc["directory"]]
@ -215,13 +210,12 @@ def thumb(doc_id):
print(tn_path) print(tn_path)
if os.path.isfile(tn_path): if os.path.isfile(tn_path):
return send_file(tn_path) return send_file(tn_path)
else:
default_thumbnail = BytesIO() default_thumbnail = BytesIO()
Image.new("RGB", (255, 128), (0, 0, 0)).save(default_thumbnail, "JPEG") Image.new("RGB", (255, 128), (0, 0, 0)).save(default_thumbnail, "JPEG")
default_thumbnail.seek(0) default_thumbnail.seek(0)
return send_file(default_thumbnail, "image/jpeg") return send_file(default_thumbnail, "image/jpeg")
else:
default_thumbnail = BytesIO() default_thumbnail = BytesIO()
Image.new("RGB", (255, 128), (0, 0, 0)).save(default_thumbnail, "JPEG") Image.new("RGB", (255, 128), (0, 0, 0)).save(default_thumbnail, "JPEG")
default_thumbnail.seek(0) default_thumbnail.seek(0)
@ -248,11 +242,9 @@ def search_liste_page():
def get_allowed_dirs(username): def get_allowed_dirs(username):
if config.allow_guests: if config.allow_guests:
return [x for x in storage.dirs() if x.enabled] return [x for x in storage.dirs() if x.enabled]
else:
if username: if username:
user = storage.users()[username] user = storage.users()[username]
return [x for x in storage.dirs() if storage.dirs()[x].enabled and x in user.readable_directories] return [x for x in storage.dirs() if storage.dirs()[x].enabled and x in user.readable_directories]
else:
return list() return list()
@ -291,7 +283,6 @@ def scroll_route():
def dir_list(): def dir_list():
if "admin" in session and session["admin"]: if "admin" in session and session["admin"]:
return render_template("directory.html", directories=storage.dirs()) return render_template("directory.html", directories=storage.dirs())
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -314,7 +305,6 @@ def directory_add():
"danger") "danger")
return redirect("/directory") return redirect("/directory")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -328,7 +318,6 @@ def directory_manage(dir_id):
return render_template("directory_manage.html", directory=directory, tn_size=tn_size, return render_template("directory_manage.html", directory=directory, tn_size=tn_size,
tn_size_formatted=tn_size_formatted) tn_size_formatted=tn_size_formatted)
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -360,7 +349,6 @@ def directory_update(dir_id):
"danger") "danger")
return redirect("/directory/" + str(dir_id)) return redirect("/directory/" + str(dir_id))
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -375,7 +363,6 @@ def directory_update_opt(dir_id):
storage.update_option(Option(opt_key, opt_value, dir_id, opt_id)) storage.update_option(Option(opt_key, opt_value, dir_id, opt_id))
return redirect("/directory/" + str(dir_id)) return redirect("/directory/" + str(dir_id))
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -391,7 +378,6 @@ def directory_del(dir_id):
flash("<strong>Deleted folder</strong>", "success") flash("<strong>Deleted folder</strong>", "success")
return redirect("/directory") return redirect("/directory")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -416,7 +402,6 @@ def directory_reset(dir_id):
flash("<strong>Reset directory options</strong>", "success") flash("<strong>Reset directory options</strong>", "success")
return redirect("directory/" + str(dir_id)) return redirect("directory/" + str(dir_id))
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -426,7 +411,6 @@ def task():
if "admin" in session and session["admin"]: if "admin" in session and session["admin"]:
return render_template("task.html", tasks=storage.tasks(), directories=storage.dirs(), return render_template("task.html", tasks=storage.tasks(), directories=storage.dirs(),
task_list=json.dumps(list(storage.tasks().keys()))) task_list=json.dumps(list(storage.tasks().keys())))
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -437,9 +421,7 @@ def get_current_task():
if tm and tm.current_task: if tm and tm.current_task:
return tm.current_task.to_json() return tm.current_task.to_json()
else:
return "" return ""
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -460,7 +442,6 @@ def task_add():
flash("You must choose a directory", "danger") flash("You must choose a directory", "danger")
return redirect("/task") return redirect("/task")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -474,7 +455,6 @@ def task_del(task_id):
tm.cancel_task() tm.cancel_task()
return redirect("/task") return redirect("/task")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -490,7 +470,6 @@ def reset_es():
shutil.rmtree("static/thumbnails") shutil.rmtree("static/thumbnails")
return redirect("/dashboard") return redirect("/dashboard")
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")
@ -517,7 +496,6 @@ def dashboard():
elasticsearch_url=config.elasticsearch_url, elasticsearch_url=config.elasticsearch_url,
index_size=humanfriendly.format_size(search.get_index_size())) index_size=humanfriendly.format_size(search.get_index_size()))
else:
flash("You are not authorized to access this page", "warning") flash("You are not authorized to access this page", "warning")
return redirect("/") return redirect("/")