예제 #1
0
def grid_index():
    pubs = []
    grids = Grid.objects().order_by("-start_Date")
    for grid in grids:
        if grid.is_public == "true":
            pubs.append(grid.to_public_json())

    return jsonify(pubs)
예제 #2
0
def grids_user(username: str):
    try:
        user = User.objects(username=username).first()
    except ValidationError:
        return jsonify({"error": "User not found"}), 404

    grids = Grid.objects(user=user).order_by("-created")

    return jsonify([grid.to_public_json() for grid in grids])
예제 #3
0
def grids_item(id: str):
    try:
        grid = Grid.objects(pk=id).first()

        # If grid has alreay been deleted
        if not grid:
            raise ValidationError
    except ValidationError:
        return jsonify({"error": "grid not found"}), 404

    return jsonify(grid.to_public_json())
예제 #4
0
def grids_delete(username: str, id: str):
    try:
        grid = Grid.objects(pk=id).first()

        # If grid has alreay been deleted
        if not grid:
            raise ValidationError
    except ValidationError:
        return jsonify({"error": "Grid not found"}), 404

    # Check whether action was called by creator of the grid
    if username != grid.user.username:
        return jsonify({"error": "You are not the creator of the grid"}), 401

    grid_info = grid.to_public_json()

    grid.delete()

    return jsonify(grid_info)