poprawki
This commit is contained in:
27
app.py
27
app.py
@@ -3518,9 +3518,10 @@ def add_suggestion():
|
||||
|
||||
|
||||
@app.route("/admin/lists-access", methods=["GET", "POST"])
|
||||
@app.route("/admin/lists-access/<int:list_id>", methods=["GET", "POST"])
|
||||
@login_required
|
||||
@admin_required
|
||||
def admin_lists_access():
|
||||
def admin_lists_access(list_id=None):
|
||||
try:
|
||||
page = int(request.args.get("page", 1))
|
||||
except ValueError:
|
||||
@@ -3535,6 +3536,19 @@ def admin_lists_access():
|
||||
ShoppingList.created_at.desc()
|
||||
)
|
||||
|
||||
if list_id is not None:
|
||||
target_list = db.session.get(ShoppingList, list_id)
|
||||
if not target_list:
|
||||
flash("Lista nie istnieje.", "danger")
|
||||
return redirect(url_for("admin_lists_access"))
|
||||
lists = [target_list]
|
||||
list_ids = [list_id]
|
||||
pagination = None
|
||||
else:
|
||||
pagination = q.paginate(page=page, per_page=per_page, error_out=False)
|
||||
lists = pagination.items
|
||||
list_ids = [l.id for l in lists]
|
||||
|
||||
if request.method == "POST":
|
||||
action = request.form.get("action")
|
||||
target_list_id = request.form.get("target_list_id", type=int)
|
||||
@@ -3575,9 +3589,9 @@ def admin_lists_access():
|
||||
if action == "save_changes":
|
||||
ids = request.form.getlist("visible_ids", type=int)
|
||||
if ids:
|
||||
lists = ShoppingList.query.filter(ShoppingList.id.in_(ids)).all()
|
||||
lists_edit = ShoppingList.query.filter(ShoppingList.id.in_(ids)).all()
|
||||
posted = request.form
|
||||
for l in lists:
|
||||
for l in lists_edit:
|
||||
l.is_public = posted.get(f"is_public_{l.id}") is not None
|
||||
l.is_temporary = posted.get(f"is_temporary_{l.id}") is not None
|
||||
l.is_archived = posted.get(f"is_archived_{l.id}") is not None
|
||||
@@ -3585,10 +3599,6 @@ def admin_lists_access():
|
||||
flash("Zapisano zmiany statusów.", "success")
|
||||
return redirect(request.url)
|
||||
|
||||
pagination = q.paginate(page=page, per_page=per_page, error_out=False)
|
||||
lists = pagination.items
|
||||
|
||||
list_ids = [l.id for l in lists]
|
||||
perms = (
|
||||
db.session.query(
|
||||
ListPermission.list_id,
|
||||
@@ -3613,8 +3623,9 @@ def admin_lists_access():
|
||||
permitted_by_list=permitted_by_list,
|
||||
page=page,
|
||||
per_page=per_page,
|
||||
total_pages=pagination.pages or 1,
|
||||
total_pages=pagination.pages if pagination else 1,
|
||||
query_string=query_string,
|
||||
list_id=list_id,
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user