def unarchive_list(): shopping_list_name = request.form["shopping_list"] model.ShoppingList.archived().filter_by( name=shopping_list_name).one().isarchived = False model.db.session.commit() return jsonify({"lists": utils.get_list_info_raw(True)})
def list_shopping_lists(): shopping_lists = [] raw_shopping_lists = utils.get_list_info_raw(None) user_department = current_user.department.name if current_user.department else None if not user_department or current_user.has_role("admin"): shopping_lists = raw_shopping_lists else: for list_info in raw_shopping_lists: if user_department == list_info["department"]: shopping_lists.append(list_info) return jsonify({"lists": shopping_lists})
def archive_list(): shopping_list_name = request.form["shopping_list"] model.ShoppingList.active().filter_by( name=shopping_list_name).one().isarchived = True model.db.session.commit() next_list = model.ShoppingList.next() return jsonify({ "lists": utils.get_list_info_raw(False), "load": next_list.name if next_list else None })
def delete_list(): shopping_list_name = request.form["shopping_list"] # Delete from database model.db.session.delete( model.ShoppingList.query.filter_by(name=shopping_list_name).one()) model.db.session.commit() next_list = model.ShoppingList.next() return jsonify({ "lists": utils.get_list_info_raw(), "load": next_list.name if next_list else None })
def create_new_list(): name = request.form["name"] departure_seconds = int(request.form["departureSeconds"]) department_name = request.form.get("department") if model.ShoppingList.query.filter_by(name=name).first(): return jsonify({ "error": { "message": f"The list \"{name}\" already exists.", "field": "name" } }), 409 department = model.Department.query.filter_by(name=department_name).first() model.db.session.add( model.ShoppingList(name=name, departure=departure_seconds, department=department)) model.db.session.commit() return jsonify({"lists": utils.get_list_info_raw(False)})
def get_active_list_info(): return jsonify({"lists": utils.get_list_info_raw(False)})
def get_archived_list_info(): return jsonify({"lists": utils.get_list_info_raw(True)})
def get_list_info(): return jsonify({"lists": utils.get_list_info_raw(None)})