summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/editing_routes.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2021-11-03 15:45:35 -0700
committerBryan Newbold <bnewbold@robocracy.org>2021-11-03 16:52:44 -0700
commit91bd35a1ee0993126c369e39fbf8f81f775840ee (patch)
tree87e8bc6257359326f26102e7765e508d5529f0f5 /python/fatcat_web/editing_routes.py
parent2e92e28df34d302fe02d1e1ff7169b7888648b9c (diff)
downloadfatcat-91bd35a1ee0993126c369e39fbf8f81f775840ee.tar.gz
fatcat-91bd35a1ee0993126c369e39fbf8f81f775840ee.zip
web: add type annotations
This commit does not include type fixes, only annotations. A small number of tuples were also converted to lists.
Diffstat (limited to 'python/fatcat_web/editing_routes.py')
-rw-r--r--python/fatcat_web/editing_routes.py163
1 files changed, 89 insertions, 74 deletions
diff --git a/python/fatcat_web/editing_routes.py b/python/fatcat_web/editing_routes.py
index 03668e1e..32bff51d 100644
--- a/python/fatcat_web/editing_routes.py
+++ b/python/fatcat_web/editing_routes.py
@@ -1,6 +1,7 @@
-from typing import Optional
+from typing import Any, Optional
from fatcat_openapi_client import (
+ ApiClient,
ContainerEntity,
CreatorEntity,
Editgroup,
@@ -16,7 +17,7 @@ from flask import abort, flash, redirect, render_template, session
from flask_login import login_required
from fatcat_tools.transforms import entity_from_toml
-from fatcat_web import api, app, auth_api
+from fatcat_web import AnyResponse, api, app, auth_api
from fatcat_web.entity_helpers import generic_get_editgroup_entity, generic_get_entity
from fatcat_web.forms import (
ContainerEntityForm,
@@ -30,7 +31,7 @@ from fatcat_web.forms import (
def generic_entity_create_from_toml(
- user_api, entity_type: str, editgroup_id: str, toml_str: str
+ user_api: ApiClient, entity_type: str, editgroup_id: str, toml_str: str
) -> EntityEdit:
if entity_type == "container":
entity = entity_from_toml(toml_str, ContainerEntity)
@@ -59,7 +60,7 @@ def generic_entity_create_from_toml(
def generic_entity_delete_edit(
- user_api, entity_type: str, editgroup_id: str, edit_id: str
+ user_api: ApiClient, entity_type: str, editgroup_id: str, edit_id: str
) -> None:
try:
if entity_type == "container":
@@ -86,7 +87,7 @@ def generic_entity_delete_edit(
def generic_entity_delete_entity(
- user_api, entity_type: str, editgroup_id: str, entity_ident: str
+ user_api: ApiClient, entity_type: str, editgroup_id: str, entity_ident: str
) -> EntityEdit:
try:
if entity_type == "container":
@@ -111,7 +112,7 @@ def generic_entity_delete_entity(
def generic_entity_update_from_toml(
- user_api, entity_type: str, editgroup_id: str, existing_ident, toml_str: str
+ user_api: ApiClient, entity_type: str, editgroup_id: str, existing_ident: str, toml_str: str
) -> EntityEdit:
if entity_type == "container":
entity = entity_from_toml(toml_str, ContainerEntity)
@@ -139,7 +140,7 @@ def generic_entity_update_from_toml(
return edit
-def form_editgroup_get_or_create(api, edit_form):
+def form_editgroup_get_or_create(api: ApiClient, edit_form: Any) -> Optional[Editgroup]:
"""
This function expects a submitted, validated edit form
"""
@@ -168,7 +169,12 @@ def form_editgroup_get_or_create(api, edit_form):
return eg
-def generic_entity_edit(editgroup_id, entity_type, existing_ident, edit_template):
+def generic_entity_edit(
+ editgroup_id: Optional[str],
+ entity_type: str,
+ existing_ident: Optional[str],
+ edit_template: str,
+) -> AnyResponse:
"""
existing (entity)
@@ -342,7 +348,12 @@ def generic_entity_edit(editgroup_id, entity_type, existing_ident, edit_template
)
-def generic_entity_toml_edit(editgroup_id, entity_type, existing_ident, edit_template):
+def generic_entity_toml_edit(
+ editgroup_id: Optional[str],
+ entity_type: Any,
+ existing_ident: Optional[str],
+ edit_template: str,
+) -> AnyResponse:
"""
Similar to generic_entity_edit(), but for TOML editing mode.
@@ -469,7 +480,9 @@ def generic_entity_toml_edit(editgroup_id, entity_type, existing_ident, edit_tem
)
-def generic_entity_delete(editgroup_id: Optional[str], entity_type: str, existing_ident: str):
+def generic_entity_delete(
+ editgroup_id: Optional[str], entity_type: str, existing_ident: str
+) -> AnyResponse:
"""
Similar to generic_entity_edit(), but for deleting entities. This is a bit
simpler!
@@ -570,7 +583,9 @@ def generic_entity_delete(editgroup_id: Optional[str], entity_type: str, existin
)
-def generic_edit_delete(editgroup_id, entity_type, edit_id):
+def generic_edit_delete(
+ editgroup_id: Optional[str], entity_type: Any, edit_id: str
+) -> AnyResponse:
# fetch editgroup (if set) or 404
editgroup = None
if editgroup_id:
@@ -597,177 +612,177 @@ def generic_edit_delete(editgroup_id, entity_type, edit_id):
@app.route("/container/create", methods=["GET", "POST"])
@login_required
-def container_create_view():
+def container_create_view() -> AnyResponse:
return generic_entity_edit(None, "container", None, "container_create.html")
@app.route("/container/<ident>/edit", methods=["GET", "POST"])
@login_required
-def container_edit_view(ident):
+def container_edit_view(ident: str) -> AnyResponse:
return generic_entity_edit(None, "container", ident, "container_edit.html")
@app.route("/container/<ident>/delete", methods=["GET", "POST"])
@login_required
-def container_delete_view(ident):
+def container_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "container", ident)
@app.route("/editgroup/<editgroup_id>/container/<ident>/edit", methods=["GET", "POST"])
@login_required
-def container_editgroup_edit_view(editgroup_id, ident):
+def container_editgroup_edit_view(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_edit(editgroup_id, "container", ident, "container_edit.html")
@app.route("/editgroup/<editgroup_id>/container/<ident>/delete", methods=["GET", "POST"])
@login_required
-def container_editgroup_delete_view(editgroup_id, ident):
+def container_editgroup_delete_view(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "container", ident)
@app.route("/editgroup/<editgroup_id>/container/edit/<edit_id>/delete", methods=["POST"])
@login_required
-def container_edit_delete(editgroup_id, edit_id):
+def container_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "container", edit_id)
@app.route("/creator/<ident>/delete", methods=["GET", "POST"])
@login_required
-def creator_delete_view(ident):
+def creator_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "creator", ident)
@app.route("/editgroup/<editgroup_id>/creator/edit/<edit_id>/delete", methods=["POST"])
-def creator_edit_delete(editgroup_id, edit_id):
+def creator_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "creator", edit_id)
@app.route("/editgroup/<editgroup_id>/creator/<ident>/delete", methods=["GET", "POST"])
@login_required
-def creator_editgroup_delete(editgroup_id, ident):
+def creator_editgroup_delete(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "creator", ident)
@app.route("/file/create", methods=["GET", "POST"])
@login_required
-def file_create_view():
+def file_create_view() -> AnyResponse:
return generic_entity_edit(None, "file", None, "file_create.html")
@app.route("/file/<ident>/edit", methods=["GET", "POST"])
@login_required
-def file_edit_view(ident):
+def file_edit_view(ident: str) -> AnyResponse:
return generic_entity_edit(None, "file", ident, "file_edit.html")
@app.route("/file/<ident>/delete", methods=["GET", "POST"])
@login_required
-def file_delete_view(ident):
+def file_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "file", ident)
@app.route("/editgroup/<editgroup_id>/file/<ident>/edit", methods=["GET", "POST"])
@login_required
-def file_editgroup_edit_view(editgroup_id, ident):
+def file_editgroup_edit_view(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_edit(editgroup_id, "file", ident, "file_edit.html")
@app.route("/editgroup/<editgroup_id>/file/<ident>/delete", methods=["GET", "POST"])
@login_required
-def file_editgroup_delete_view(editgroup_id, ident):
+def file_editgroup_delete_view(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "file", ident)
@app.route("/editgroup/<editgroup_id>/file/edit/<edit_id>/delete", methods=["POST"])
@login_required
-def file_edit_delete(editgroup_id, edit_id):
+def file_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "file", edit_id)
@app.route("/fileset/<ident>/delete", methods=["GET", "POST"])
@login_required
-def fileset_delete_view(ident):
+def fileset_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "fileset", ident)
@app.route("/editgroup/<editgroup_id>/fileset/edit/<edit_id>/delete", methods=["POST"])
-def fileset_edit_delete(editgroup_id, edit_id):
+def fileset_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "fileset", edit_id)
@app.route("/editgroup/<editgroup_id>/fileset/<ident>/delete", methods=["GET", "POST"])
@login_required
-def fileset_editgroup_delete(editgroup_id, ident):
+def fileset_editgroup_delete(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "fileset", ident)
@app.route("/webcapture/<ident>/delete", methods=["GET", "POST"])
@login_required
-def webcapture_delete_view(ident):
+def webcapture_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "webcapture", ident)
@app.route("/editgroup/<editgroup_id>/webcapture/edit/<edit_id>/delete", methods=["POST"])
-def webcapture_edit_delete(editgroup_id, edit_id):
+def webcapture_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "webcapture", edit_id)
@app.route("/editgroup/<editgroup_id>/webcapture/<ident>/delete", methods=["GET", "POST"])
@login_required
-def webcapture_editgroup_delete(editgroup_id, ident):
+def webcapture_editgroup_delete(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "webcapture", ident)
@app.route("/release/create", methods=["GET", "POST"])
@login_required
-def release_create_view():
+def release_create_view() -> AnyResponse:
return generic_entity_edit(None, "release", None, "release_create.html")
@app.route("/release/<ident>/edit", methods=["GET", "POST"])
@login_required
-def release_edit_view(ident):
+def release_edit_view(ident: str) -> AnyResponse:
return generic_entity_edit(None, "release", ident, "release_edit.html")
@app.route("/release/<ident>/delete", methods=["GET", "POST"])
@login_required
-def release_delete_view(ident):
+def release_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "release", ident)
@app.route("/editgroup/<editgroup_id>/release/<ident>/edit", methods=["GET", "POST"])
@login_required
-def release_editgroup_edit(editgroup_id, ident):
+def release_editgroup_edit(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_edit(editgroup_id, "release", ident, "release_edit.html")
@app.route("/editgroup/<editgroup_id>/release/<ident>/delete", methods=["GET", "POST"])
@login_required
-def release_editgroup_delete(editgroup_id, ident):
+def release_editgroup_delete(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "release", ident)
@app.route("/editgroup/<editgroup_id>/release/edit/<edit_id>/delete", methods=["POST"])
@login_required
-def release_edit_delete(editgroup_id, edit_id):
+def release_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "release", edit_id)
@app.route("/work/<ident>/delete", methods=["GET", "POST"])
@login_required
-def work_delete_view(ident):
+def work_delete_view(ident: str) -> AnyResponse:
return generic_entity_delete(None, "work", ident)
@app.route("/editgroup/<editgroup_id>/work/edit/<edit_id>/delete", methods=["POST"])
-def work_edit_delete(editgroup_id, edit_id):
+def work_edit_delete(editgroup_id: str, edit_id: str) -> AnyResponse:
return generic_edit_delete(editgroup_id, "work", edit_id)
@app.route("/editgroup/<editgroup_id>/work/<ident>/delete", methods=["GET", "POST"])
@login_required
-def work_editgroup_delete(editgroup_id, ident):
+def work_editgroup_delete(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_delete(editgroup_id, "work", ident)
@@ -776,127 +791,127 @@ def work_editgroup_delete(editgroup_id, ident):
@app.route("/container/create/toml", methods=["GET", "POST"])
@login_required
-def container_create_toml_view():
+def container_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "container", None, "entity_create_toml.html")
@app.route("/container/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def container_edit_toml_view(ident):
+def container_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "container", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/container/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def container_editgroup_edit_toml(editgroup_id, ident):
+def container_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "container", ident, "entity_edit_toml.html")
@app.route("/creator/create/toml", methods=["GET", "POST"])
@login_required
-def creator_create_toml_view():
+def creator_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "creator", None, "entity_create_toml.html")
@app.route("/creator/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def creator_edit_toml_view(ident):
+def creator_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "creator", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/creator/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def creator_editgroup_edit_toml(editgroup_id, ident):
+def creator_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "creator", ident, "entity_edit_toml.html")
@app.route("/file/create/toml", methods=["GET", "POST"])
@login_required
-def file_create_toml_view():
+def file_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "file", None, "entity_create_toml.html")
@app.route("/file/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def file_edit_toml_view(ident):
+def file_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "file", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/file/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def file_editgroup_edit_toml(editgroup_id, ident):
+def file_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "file", ident, "entity_edit_toml.html")
@app.route("/fileset/create/toml", methods=["GET", "POST"])
@login_required
-def fileset_create_toml_view():
+def fileset_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "fileset", None, "entity_create_toml.html")
@app.route("/fileset/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def fileset_edit_toml_view(ident):
+def fileset_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "fileset", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/fileset/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def fileset_editgroup_edit_toml(editgroup_id, ident):
+def fileset_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "fileset", ident, "entity_edit_toml.html")
@app.route("/webcapture/create/toml", methods=["GET", "POST"])
@login_required
-def webcapture_create_toml_view():
+def webcapture_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "webcapture", None, "entity_create_toml.html")
@app.route("/webcapture/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def webcapture_edit_toml_view(ident):
+def webcapture_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "webcapture", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/webcapture/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def webcapture_editgroup_edit_toml(editgroup_id, ident):
+def webcapture_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "webcapture", ident, "entity_edit_toml.html")
@app.route("/release/create/toml", methods=["GET", "POST"])
@login_required
-def release_create_toml_view():
+def release_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "release", None, "entity_create_toml.html")
@app.route("/release/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def release_edit_toml_view(ident):
+def release_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "release", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/release/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def release_editgroup_edit_toml(editgroup_id, ident):
+def release_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "release", ident, "entity_edit_toml.html")
@app.route("/work/create/toml", methods=["GET", "POST"])
@login_required
-def work_create_toml_view():
+def work_create_toml_view() -> AnyResponse:
return generic_entity_toml_edit(None, "work", None, "entity_create_toml.html")
@app.route("/work/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def work_edit_toml_view(ident):
+def work_edit_toml_view(ident: str) -> AnyResponse:
return generic_entity_toml_edit(None, "work", ident, "entity_edit_toml.html")
@app.route("/editgroup/<editgroup_id>/work/<ident>/edit/toml", methods=["GET", "POST"])
@login_required
-def work_editgroup_edit_toml(editgroup_id, ident):
+def work_editgroup_edit_toml(editgroup_id: str, ident: str) -> AnyResponse:
return generic_entity_toml_edit(editgroup_id, "work", ident, "entity_edit_toml.html")
@@ -905,71 +920,71 @@ def work_editgroup_edit_toml(editgroup_id, ident):
@app.route("/creator/create", methods=["GET"])
@login_required
-def creator_create_view():
+def creator_create_view() -> AnyResponse:
return redirect("/creator/create/toml")
@app.route("/creator/<ident>/edit", methods=["GET"])
@login_required
-def creator_edit_view(ident):
+def creator_edit_view(ident: str) -> AnyResponse:
return redirect(f"/creator/{ident}/edit/toml")
@app.route("/editgroup/<editgroup_id>/creator/<ident>/edit", methods=["GET", "POST"])
@login_required
-def creator_editgroup_edit(editgroup_id, ident):
+def creator_editgroup_edit(editgroup_id: str, ident: str) -> AnyResponse:
return redirect(f"/editgroup/{editgroup_id}/creator/{ident}/edit/toml")
@app.route("/fileset/create", methods=["GET"])
@login_required
-def fileset_create_view():
+def fileset_create_view() -> AnyResponse:
return redirect("/fileset/create/toml")
@app.route("/fileset/<ident>/edit", methods=["GET"])
@login_required
-def fileset_edit_view(ident):
+def fileset_edit_view(ident: str) -> AnyResponse:
return redirect(f"/fileset/{ident}/edit/toml")
@app.route("/editgroup/<editgroup_id>/fileset/<ident>/edit", methods=["GET", "POST"])
@login_required
-def fileset_editgroup_edit(editgroup_id, ident):
+def fileset_editgroup_edit(editgroup_id: str, ident: str) -> AnyResponse:
return redirect(f"/editgroup/{editgroup_id}/fileset/{ident}/edit/toml")
@app.route("/webcapture/create", methods=["GET"])
@login_required
-def webcapture_create_view():
+def webcapture_create_view() -> AnyResponse:
return redirect("/webcapture/create/toml")
@app.route("/webcapture/<ident>/edit", methods=["GET"])
@login_required
-def webcapture_edit_view(ident):
+def webcapture_edit_view(ident: str) -> AnyResponse:
return redirect(f"/webcapture/{ident}/edit/toml")
@app.route("/editgroup/<editgroup_id>/webcapture/<ident>/edit", methods=["GET", "POST"])
@login_required
-def webcapture_editgroup_edit(editgroup_id, ident):
+def webcapture_editgroup_edit(editgroup_id: str, ident: str) -> AnyResponse:
return redirect(f"/editgroup/{editgroup_id}/webcapture/{ident}/edit/toml")
@app.route("/work/create", methods=["GET"])
@login_required
-def work_create_view():
+def work_create_view() -> AnyResponse:
return redirect("/work/create/toml")
@app.route("/work/<ident>/edit", methods=["GET"])
@login_required
-def work_edit_view(ident):
+def work_edit_view(ident: str) -> AnyResponse:
return redirect(f"/work/{ident}/edit/toml")
@app.route("/editgroup/<editgroup_id>/work/<ident>/edit", methods=["GET", "POST"])
@login_required
-def work_editgroup_edit(editgroup_id, ident):
+def work_editgroup_edit(editgroup_id: str, ident: str) -> AnyResponse:
return redirect(f"/editgroup/{editgroup_id}/work/{ident}/edit/toml")