mirror of https://github.com/logos-co/open-law.git
move creating flash about errors to controller
This commit is contained in:
parent
49128baa1f
commit
c7e6d8016a
|
@ -0,0 +1,8 @@
|
|||
from flask import flash
|
||||
|
||||
|
||||
def create_error_flash(form):
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
|
@ -17,6 +17,7 @@ from app.controllers.create_access_groups import (
|
|||
)
|
||||
from app.controllers.require_permission import require_permission
|
||||
from app.controllers.sorting import sort_by
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app import models as m, db, forms as f
|
||||
from app.logger import log
|
||||
from .bp import bp
|
||||
|
@ -130,10 +131,7 @@ def create():
|
|||
return redirect(url_for("book.my_library"))
|
||||
else:
|
||||
log(log.ERROR, "Book create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(url_for("book.my_library"))
|
||||
|
||||
|
||||
|
@ -162,10 +160,7 @@ def edit(book_id: int):
|
|||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
else:
|
||||
log(log.ERROR, "Book create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(url_for("book.settings", book_id=book_id))
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ from app.controllers.notification_producer import collection_notification
|
|||
from app.controllers.delete_nested_book_entities import (
|
||||
delete_nested_collection_entities,
|
||||
)
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app import models as m, db, forms as f
|
||||
from app.controllers.require_permission import require_permission
|
||||
from app.logger import log
|
||||
|
@ -127,10 +128,7 @@ def collection_create(book_id: int, collection_id: int | None = None):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Collection/Subcollection create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
@ -194,10 +192,7 @@ def collection_edit(book_id: int, collection_id: int):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Collection edit errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from flask_login import login_required
|
|||
|
||||
from app import models as m, db, forms as f
|
||||
from app.controllers.fork import fork_book
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app.logger import log
|
||||
from .bp import bp
|
||||
|
||||
|
@ -20,8 +21,5 @@ def fork(book_id):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Fork book errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
|
|
@ -16,6 +16,7 @@ from app.controllers.notification_producer import interpretation_notification
|
|||
from app.controllers.delete_nested_book_entities import (
|
||||
delete_nested_interpretation_entities,
|
||||
)
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app import models as m, db, forms as f
|
||||
from app.controllers.require_permission import require_permission
|
||||
from app.controllers.tags import set_interpretation_tags
|
||||
|
@ -122,10 +123,7 @@ def interpretation_create(
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Interpretation create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
@ -182,10 +180,7 @@ def interpretation_edit(
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Interpretation edit errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from flask_login import login_required, current_user
|
|||
from app.controllers import register_book_verify_route
|
||||
from app.controllers.notification_producer import section_notification
|
||||
from app.controllers.delete_nested_book_entities import delete_nested_section_entities
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app import models as m, db, forms as f
|
||||
from app.controllers.require_permission import require_permission
|
||||
from app.logger import log
|
||||
|
@ -58,10 +59,7 @@ def section_create(book_id: int, collection_id: int):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Section create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
@ -97,10 +95,7 @@ def section_edit(book_id: int, section_id: int):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Section edit errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ from app.controllers.contributor import (
|
|||
add_contributor_to_book,
|
||||
delete_contributor_from_book,
|
||||
)
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app.logger import log
|
||||
from .bp import bp
|
||||
|
||||
|
@ -59,10 +60,7 @@ def add_contributor(book_id: int):
|
|||
return response
|
||||
else:
|
||||
log(log.ERROR, "Book create errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
@ -89,10 +87,7 @@ def delete_contributor(book_id: int):
|
|||
return response
|
||||
else:
|
||||
log(log.ERROR, "Delete contributor errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
@ -161,10 +156,7 @@ def edit_contributor_role(book_id: int):
|
|||
)
|
||||
else:
|
||||
log(log.ERROR, "Edit contributor errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(
|
||||
url_for("book.settings", selected_tab=selected_tab, book_id=book_id)
|
||||
)
|
||||
|
|
|
@ -8,6 +8,7 @@ from app.controllers import (
|
|||
from app import models as m, db, forms as f
|
||||
from app.controllers.version import create_new_version
|
||||
from app.controllers.delete_nested_book_entities import delete_nested_version_entities
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from app.logger import log
|
||||
from .bp import bp
|
||||
|
||||
|
@ -28,10 +29,7 @@ def create_version(book_id):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Create version errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
@ -64,10 +62,7 @@ def edit_version(book_id: int):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Edit version errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
|
@ -102,8 +97,5 @@ def delete_version(book_id: int):
|
|||
return redirect(redirect_url)
|
||||
else:
|
||||
log(log.ERROR, "Delete version errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
return redirect(redirect_url)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from flask import Blueprint, render_template, request, flash, redirect, url_for, jsonify
|
||||
from flask_login import login_required, current_user, logout_user
|
||||
from app.controllers import create_pagination
|
||||
from app.controllers.error_flashes import create_error_flash
|
||||
from sqlalchemy import func, not_, or_
|
||||
|
||||
from app import models as m, db
|
||||
|
@ -46,10 +47,7 @@ def edit_profile():
|
|||
return redirect(url_for("main.index"))
|
||||
elif form.is_submitted():
|
||||
log(log.ERROR, "Update user errors: [%s]", form.errors)
|
||||
for field, errors in form.errors.items():
|
||||
field_label = form._fields[field].label.text
|
||||
for error in errors:
|
||||
flash(error.replace("Field", field_label), "danger")
|
||||
create_error_flash(form)
|
||||
|
||||
if current_user.is_activated:
|
||||
form.username.data = current_user.username
|
||||
|
|
Loading…
Reference in New Issue