Example #1
0
def web_open_round():
    if request.method == 'GET':

        rounds = get_rounds_from_database(True)
        people = get_people_from_database()
        drinks = []

        open_round = None
        if len(rounds) > 0:
            open_round = rounds[-1]
            drinks = get_drinks_from_database()

        return render_template('open_round.html',
                               title='Open Round',
                               open_round=open_round,
                               people=people,
                               drinks=drinks)

    if request.method == 'POST':

        person_id = request.form.get('person_id')

        person = get_person_by_id_from_database(person_id)
        new_round = Round(brewer=person)
        create_new_open_round_in_database(new_round)

        return redirect(url_for('web_open_round'))

    else:
        return "Unsupported HTTP Request Type"
Example #2
0
def web_people():
    if request.method == 'GET':

        people = get_people_from_database()
        drinks = get_drinks_from_database()

        return render_template('people.html',
                               title='People',
                               people=people,
                               drinks=drinks)

    if request.method == 'POST':
        drink_id = request.form.get('drink_id')

        drink = None
        if drink_id != 'None':
            drink = get_drink_by_id_from_database(drink_id)

        person_name = request.form.get('person_name').strip()
        people = get_people_from_database()
        drinks = get_drinks_from_database()

        if len(person_name) == 0:
            return render_template(
                'people.html',
                title='People',
                people=people,
                drinks=drinks,
                error_message='The name of the person cannot be empty')
        if len(search_person_by_name(person_name)) > 0:
            return render_template(
                'people.html',
                title='People',
                people=people,
                drinks=drinks,
                error_message='There is already a person with that name')

        new_person = Person(person_name, drink)
        saved_person = save_new_user_in_database(new_person)
        people.append(saved_person)

        return render_template('people.html',
                               title='People',
                               people=people,
                               drinks=drinks)
    else:
        return "Unsupported HTTP Request Type"
Example #3
0
def api_get_people():
    if request.method == 'GET':
        people = get_people_from_database()
        return {'People': [person.to_json() for person in people]}

    if request.method == 'POST':
        data = request.get_json() or {}
        if 'name' not in data or 'favourite_drink_id' not in data:
            return Response(
                status=400,
                response='must include name and favourite_drink_id fields')
        drink = get_drink_by_id_from_database(data['favourite_drink_id'])
        if drink == None:
            return Response(status=400,
                            response='there is no drink with that id')
        new_person = Person(data['name'], drink)
        save_person = save_new_user_in_database(new_person)
        response = jsonify(save_person.to_json())
        response.status_code = 201

        return response
    else:
        return "Unsupported HTTP Request Type"
Example #4
0
def get_people():
    people = get_people_from_database()
    return json.dumps(people, cls=PeopleEncoder)
Example #5
0
def render_website():
    drinks = get_drinks_from_database()
    people = get_people_from_database()
    rounds = get_rounds_from_database()

    return f"""
Example #6
0
def run():
    people = []
    drinks = []
    rounds = []

    # Default filepaths
    drinks_filepath = "briw/resources/drinks.txt"
    people_filepath = "briw/resources/people.txt"
    rounds_filepath = "briw/resources/rounds.txt"

    rounds = round_controller.get_rounds_from_database()
    people = people_controller.get_people_from_database()
    drinks = drinks_controller.get_drinks_from_database()

    # Read data from files
    # people = file_functions.read_people_from_file(people_filepath)
    # drinks = file_functions.read_drinks_from_file(drinks_filepath)
    # rounds = file_functions.read_rounds(rounds_filepath)

    # Check arguments
    functions.check_args(sys.argv, people, drinks)

    while True:
        # Print the available options
        printer_aux.print_options()

        minimumOptionNumber = 0
        maximumOptionNumber = 12

        # Ask for a value, which must be a number,
        # and repeat the question until the user enters a number.
        op = functions.ask_number(texts.ENTER_OPTION, minimumOptionNumber,
                                  maximumOptionNumber)

        if op == 1:
            # Print list of drinks
            printer_aux.print_list(texts.DRINKS, drinks)
        elif op == 2:
            # Print list of users
            printer_aux.print_list(texts.PEOPLE, people)
        elif op == 3:
            # Print list of users and preferences
            printer_aux.print_users_preferences(people)
        elif op == 4:
            # Call the function to follow the steps to add a new drink
            drinks = functions.add_drink(drinks)
        elif op == 5:
            # Call the function to follow the steps to add a new person
            people = functions.create_new_person(people, drinks)
        elif op == 6:
            # Set favourite drink
            people = functions.set_favourite_drink(people, drinks)
        elif op == 7:
            # Create a new round
            rounds = functions.create_round_and_set_brewer(people, rounds)
        elif op == 8:
            # Add order to round
            rounds = functions.add_order_to_round(people, drinks, rounds)
        elif op == 9:
            # Close open round
            rounds = functions.close_open_round(rounds)
        elif op == 10:
            # Print rounds
            printer_aux.print_rounds(rounds)
        elif op == 11:
            # HELP MESSAGE
            print(texts.HELP_MESSAGE)
        elif op == 0 or op == None:
            # Just exit the program
            functions.goodbye(people, drinks, rounds, people_filepath,
                              drinks_filepath, rounds_filepath)
            exit()
        else:
            # If the number you entered is not in the options, ask for it again
            print(texts.INCORRECT_OPTION)
        printer_aux.enter_to_continue()