Пример #1
0
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)})
Пример #2
0
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})
Пример #3
0
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
    })
Пример #4
0
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
    })
Пример #5
0
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)})
Пример #6
0
def get_active_list_info():
    return jsonify({"lists": utils.get_list_info_raw(False)})
Пример #7
0
def get_archived_list_info():
    return jsonify({"lists": utils.get_list_info_raw(True)})
Пример #8
0
def get_list_info():
    return jsonify({"lists": utils.get_list_info_raw(None)})