예제 #1
0
def choose_product(category, db, warning=''):
    '''
    chose a product in a category
    Arguments:
        category {string}
        db {database}
    '''
    question = 'Which product do you want to substitute?'
    res = {
        'B': choose_category,
        'Q': quit_app,
    }
    # list of Product
    products = db.get_products(category)
    # list of codes
    products_codes = [product.code for product in products]
    # list of names
    products_names = [
        prod.name + ' (' + prod.nutrition_grade.upper() + ')'
        for prod in products
    ]
    choice = view.get_choice(question, products_names, warning)
    if choice.isdigit():
        next_parameter = products[int(choice)]
    else:
        next_parameter = choice
    # By default, return random_healthier
    res.get(choice, random_healthier)(next_parameter, db)
예제 #2
0
def choose():
    option = int(input(view.get_choice()))
    if option == 0:
        location_lists = model.location_lists_maker()
        view.location_list(location_lists)
    elif option == 4:
        view.endview()
예제 #3
0
def manage_favourites(_, db):
    '''
    Manage favourites
    Arguments:
        _ unused
        db {database}: database
    '''
    question = 'Which favourite to delete?\n'
    res = {
        'B': choose_action,
        'Q': quit_app,
    }
    # list of favourites
    favourites = db.list_favourites()
    # build the fav view of all favourites
    fav_view = []
    for fav in favourites:
        product = fav[0]
        substitute = fav[1]
        fav_view.append(product.category + ': ' + substitute.name + ' (' +
                        substitute.purchase + ')\n ' + ' REPLACE: ' +
                        product.name)

    choice = view.get_choice(question, fav_view, 'Yes, ' + question)
    if choice.isdigit():
        next_parameter = favourites[int(choice)]
    else:
        next_parameter = choice
    # By default, return confirm
    res.get(choice, confirm_delete_favourite)(next_parameter, db)
예제 #4
0
    def OK_for_substitute(substitute_list, database, answer='1'):
        question = "Do you want to save it?"
        answers = ['Yes', 'No']
        res = {'0': save_it, 'B': choose_product, 'Q': quit_app}
        while answer == '1':
            print('This product is healthier')
            # pick a random substitute
            substitute = substitute_list[randint(0, len(substitute_list) - 1)]
            print(substitute)
            answer = view.get_choice(question, answers)
        if answer == 'B':
            next_parameter = substitute.category
        else:
            next_parameter = substitute

        res.get(answer)(next_parameter, database)
예제 #5
0
def choose_action(_, db):
    '''
    chose a basic action
    Arguments:
        _ unused
        db {database}
    '''
    question = 'What do you want?'
    answers = ['Substitute a product.', 'Manage favourites.']
    res = {
        '0': choose_category,
        '1': manage_favourites,
        'B': quit_app,
        'Q': quit_app,
    }
    choice = view.get_choice(question, answers)
    res.get(choice)(_, db)
예제 #6
0
def confirm_delete_favourite(favourite, db):
    '''
    Confirm deletion a favourite in db
    Arguments:
        favourite {(Product, Product)}
        db {Database}
    '''
    question = 'Are you sure you want to delete this favourite?'
    res = {
        '1': manage_favourites,
        'B': manage_favourites,
        'Q': quit_app,
    }
    choice = view.get_choice(question, ['Yes', 'No'], '')
    # breakpoint()
    if choice == '0':
        db.delete_favourite(favourite)
        choose_action(favourite, db)
    else:
        res.get(choice)(favourite, db)
예제 #7
0
def choose_category(_, db):
    '''
    Chose a category
    Arguments:
        _ unused
        db {database}
    '''
    question = 'Which category of product do you want to use?'
    answers = model.CATEGORIES
    res = {
        'B': choose_action,
        'Q': quit_app,
    }
    choice = view.get_choice(question, answers)
    # Default is choose_product, else choose_action or quit_app
    if choice.isdigit():
        next_parameter = answers[int(choice)]
    else:
        next_parameter = choice
    # call chosen function with next_parameter
    res.get(choice, choose_product)(next_parameter, db)
예제 #8
0
def start():

    events.PrivateMentoring.read_events()
    events.Checkpoint.read_events()

    convert_existing_date(events.Event.get_events())
    """
    Contain main logic of controller,
    call functions to perform task chosen by user
    """

    choice = None

    head = "Chose option:"
    options_list = [
        "Book private mentoring", "Book checkpoint", "Show all my events",
        "Cancel event", "Reschedule event"
    ]
    exit_msg = "Exit program"

    while choice != "0":
        view.print_menu(head, options_list, exit_msg)
        choice = view.get_choice()
        if choice == "1":
            book_private_mentoring()
        elif choice == "2":
            book_checkpoint()
        elif choice == "3":
            display_all_evets()
        elif choice == "4":
            cancel_event()
        elif choice == "5":
            reschedule_event()
        elif choice == "0":
            say_goodbye()
        else:
            view.print_msg("Wrong option!")

        events.Checkpoint.save_events()
        events.PrivateMentoring.save_events()
예제 #9
0
def choice_preffered_mentor():
    """
    Call functions to diplay manu and choose preferred mentor
    """

    AVAIALBLE_OPTIONS_LIST = ["0", "1", "2", "3", "4", "5"]

    choice = None
    preffered_mentor = None

    head = "Chose option:"
    options_list = [
        "Mateusz Ostafi", "Agnieszka Koszany", "Dominik Starzyk",
        "Mateusz Steliga", "Marcin Izworski"
    ]
    exit_msg = "Exit booking provate mentoring"

    while choice not in AVAIALBLE_OPTIONS_LIST:
        view.print_menu(head, options_list, exit_msg)
        choice = view.get_choice()
        if choice == "1":
            preffered_mentor = "Mateusz Ostafi"
        elif choice == "2":
            preffered_mentor = "Agnieszka Koszany"
        elif choice == "3":
            preffered_mentor = "Dominik Starzyk"
        elif choice == "4":
            preffered_mentor = "Mateusz Steliga"
        elif choice == "5":
            preffered_mentor = "Marcin Izworski"
        elif choice == "0":
            view.print_msg("End of booking")
        else:
            view.print_msg("Wrong option!")

    return preffered_mentor