def list_donation_events(cursor_object):
        cursor_object.execute(QUERY_EVENTS_FROM_SQLDB)
        event_list = cursor_object.fetchall()
        if len(event_list) < 1:
            print("\n No entry found\n")
            input("\n Press (ENTER) to go back")
            clear()
            return None
        else:
            donation_object_list = []
            for entry in event_list:
                next_event = Event()
                next_event.id = str(entry[0])
                next_event.date_of_event = entry[1].strftime('%Y.%m.%d')
                delta_to_time_obj = (datetime.min + entry[2]).time()
                next_event.start_time = delta_to_time_obj.strftime('%H:%M')
                delta_to_time_obj2 = (datetime.min + entry[3]).time()
                next_event.end_time = delta_to_time_obj2.strftime('%H:%M')
                next_event.zip_code = str(entry[4])
                next_event.city = entry[5]
                next_event.address = entry[6]
                next_event.available_beds = str(entry[7])
                next_event.planned_donor_number = str(entry[8])
                next_event.successfull = str(entry[9])
                donation_object_list.append(next_event)
            #
            # EVENT SORT BY MENU
            #
            print(
                "Please type the criteria by which you would like to sort the list"
            )
            print(
                "\n(1) Date of Event\n(2) Start Time\n(3) End Time\n(4) Zip code\n"
                "(5) City\n(6) Address\n(7) Available beds\n(8) Planned donor number\n"
                "(9) Final donor number\n(0) Cancel")
            user_input = input("\n> ")
            clear()

            if user_input == "":
                user_input = "1"
            if user_input.isdigit() and int(user_input) in range(1, 10):
                EventManagerDB.print_sorted_donation_list(
                    donation_object_list, user_input)
                return None
            elif user_input == "0":
                clear()
                return None
            else:
                print("Please choose from the given numbers")
                time.sleep(1)
                clear()
    def list_donation_events():
        with open("Data/donations.csv", "r") as f:
            event_list = list(csv.reader(f))
        del (event_list[0])
        if len(event_list) < 1:
            print("\n No entry found\n")
            input("\n Press (ENTER) to go back")
            clear()
            return None
        else:
            donation_object_list = []
            for i in event_list:
                next_event = Event()
                next_event.id = i[0]
                next_event.date_of_event = i[1]
                next_event.start_time = i[2]
                next_event.end_time = i[3]
                next_event.zip_code = i[4]
                next_event.city = i[5]
                next_event.address = i[6]
                next_event.available_beds = i[7]
                next_event.planned_donor_number = i[8]
                next_event.successfull = i[9]
                donation_object_list.append(next_event)
            #
            # EVENT SORT BY MENU
            #
            print(
                "Please type the criteria by which you would like to sort the list"
            )
            print(
                "\n(1) Date of Event\n(2) Start Time\n(3) End Time\n(4) Zip code\n"
                "(5) City\n(6) Address\n(7) Available beds\n(8) Planned donor number\n"
                "(9) Final donor number\n(0) Cancel")
            user_input = input("\n> ")
            clear()

            if user_input == "":
                user_input = "1"
            if user_input.isdigit() and int(user_input) in range(1, 10):
                EventManagerCSV.print_sorted_donation_list(
                    donation_object_list, user_input)
                return None
            elif user_input == "0":
                clear()
                return None
            else:
                print("Please choose from the given numbers")
                time.sleep(1)
                clear()
    def list_donation_events(cursor_object):
        cursor_object.execute(QUERY_EVENTS_FROM_SQLDB)
        event_list = cursor_object.fetchall()
        if len(event_list) < 1:
            print("\n No entry found\n")
            input("\n Press (ENTER) to go back")
            clear()
            return None
        else:
            donation_object_list = []
            for entry in event_list:
                next_event = Event()
                next_event.id = str(entry[0])
                next_event.date_of_event = entry[1].strftime('%Y.%m.%d')
                delta_to_time_obj = (datetime.min + entry[2]).time()
                next_event.start_time = delta_to_time_obj.strftime('%H:%M')
                delta_to_time_obj2 = (datetime.min + entry[3]).time()
                next_event.end_time = delta_to_time_obj2.strftime('%H:%M')
                next_event.zip_code = str(entry[4])
                next_event.city = entry[5]
                next_event.address = entry[6]
                next_event.available_beds = str(entry[7])
                next_event.planned_donor_number = str(entry[8])
                next_event.successfull = str(entry[9])
                donation_object_list.append(next_event)
            #
            # EVENT SORT BY MENU
            #
            print("Please type the criteria by which you would like to sort the list")
            print("\n(1) Date of Event\n(2) Start Time\n(3) End Time\n(4) Zip code\n"
                  "(5) City\n(6) Address\n(7) Available beds\n(8) Planned donor number\n"
                  "(9) Final donor number\n(0) Cancel")
            user_input = input("\n> ")
            clear()

            if user_input == "":
                user_input = "1"
            if user_input.isdigit() and int(user_input) in range(1, 10):
                EventManagerDB.print_sorted_donation_list(donation_object_list, user_input)
                return None
            elif user_input == "0":
                clear()
                return None
            else:
                print("Please choose from the given numbers")
                time.sleep(1)
                clear()
    def add_new_donation_event(cursor_object):
        print("Adding new event...\n")
        time.sleep(1)
        clear()
        e1 = Event()
        while True:
            e1.date_of_event = input("Date of Event: ")
            if Validate.validate_date(e1.date_of_event) and e1.registration_in_tendays():
                pass
            else:
                print("\n\t ! The registration should be at least 10 days from now. ! ")
                print("\t   ! Use this format to enter date: 'YYYY.MM.DD' ! \n")
                time.sleep(2)
                clear()
                continue

            e1.start_time = EventManagerDB.data_into_event_object(e1, Validate.validate_time, "Start Time: ", TIME_ERR)
            e1.end_time = EventManagerDB.data_into_event_object(e1, Validate.validate_time, "End Time: ", TIME_ERR)
            while not e1.is_starttime_before_endtime():
                print("\n\t ! The starting time should be before the ending time. ! ")
                time.sleep(2)
                clear()
                e1.end_time = ""
                e1.end_time = EventManagerDB.data_into_event_object(e1, Validate.validate_time, "End Time: ", TIME_ERR)

            e1.zip_code = EventManagerDB.data_into_event_object(e1, Validate.validate_zipcode, "ZIP code: ", ZIP_ERR)
            e1.city = EventManagerDB.data_into_event_object(e1, Validate.validate_city_name, "City: ", CITY_ERR)
            e1.address = EventManagerDB.data_into_event_object(e1, Validate.validate_address, "Address of event: ", ADDRESS_ERR)
            e1.available_beds = EventManagerDB.data_into_event_object(e1, Validate.validate_positive_int, "Available beds: ", POSINT_ERR)
            e1.planned_donor_number = EventManagerDB.data_into_event_object(e1, Validate.validate_positive_int, "Planned donor number: ", POSINT_ERR)

            e1.successfull = EventManagerDB.data_into_event_object(e1, Validate.validate_positive_int, "\n How many successfull donation was on the event?\n > ", POSINT_ERR)

            print("\nThe required functions: \n")

            print("Weekday :", e1.is_weekday())
            e1.duration = e1.calculate_duration()
            print("Duration: {} min  --  {} hours ".format(e1.duration, round(e1.duration/60, 1)))
            print("Maximum donor number:", e1.max_donor_number())
            print("Success rate: {}".format(e1.success_rate()))
            input("\n\n (Press ENTER to go BACK)")
            EventManagerDB.store_donation_data(e1, cursor_object)
            clear()
            break
 def test_sunday(self):
     vampireparty = Event()
     vampireparty.date_of_event = '2015.11.08'
     self.assertFalse(vampireparty.is_weekday())
 def test_friday(self):
     vampireparty = Event()
     vampireparty.date_of_event = '2015.11.06'
     self.assertTrue(vampireparty.is_weekday())
 def test_less_than_ten_days(self):
     vampireparty = Event()
     vampireparty.date_of_event = (datetime.datetime.today() + datetime.timedelta(days=9)).strftime("%Y.%m.%d")
     self.assertFalse(vampireparty.registration_in_tendays())
    def change_event(input_id_string, cursor_object):
        event_to_change = []
        cursor_object.execute(QUERY_EVENTS_FROM_SQLDB)
        event_list = cursor_object.fetchall()
        for event in event_list:
            if int(input_id_string) == event[0]:
                event_to_change = list(event)
        if not event_to_change:
            print("\n No entry found with this ID.\n")
            time.sleep(1)
            clear()
            return None

        input_object_data_pairs = {
            0: "DateOfEvent", 1: "StartTime", 2: "EndTime", 3: "ZipCode", 4: "City", 5: "Address",
            6: "AvailableBeds", 7: "PlannedDonorNumber", 8: "Successfull"
        }
        validators_for_data_to_change = {
            0: Validate.validate_date, 1: Validate.validate_time, 2: Validate.validate_time,
            3: Validate.validate_zipcode, 4: Validate.validate_city_name, 5: Validate.validate_address,
            6: Validate.validate_positive_int, 7: Validate.validate_positive_int,
            8: Validate.validate_positive_int
        }
        event_object_for_printing = Event()
        event_object_for_printing.id = str(event_to_change[0])
        event_object_for_printing.date_of_event = event_to_change[1].strftime('%Y.%m.%d')
        delta_to_time_obj = (datetime.min + event_to_change[2]).time()
        event_object_for_printing.start_time = delta_to_time_obj.strftime('%H:%M')
        delta_to_time_obj2 = (datetime.min + event_to_change[3]).time()
        event_object_for_printing.end_time = delta_to_time_obj2.strftime('%H:%M')
        event_object_for_printing.zip_code = str(event_to_change[4])
        event_object_for_printing.city = event_to_change[5]
        event_object_for_printing.address = event_to_change[6]
        event_object_for_printing.available_beds = str(event_to_change[7])
        event_object_for_printing.planned_donor_number = str(event_to_change[8])
        event_object_for_printing.successfull = str(event_to_change[9])

        actv_selection = 0
        while True:
            MenuManager.change_event_submenu(actv_selection, event_object_for_printing)

            key = ord(getch())
            if key == ESC:
                user_input = 9
                clear()
            elif key == ENTER:
                user_input = actv_selection
                clear()
            elif key == SPECIALKEYSELECTOR:
                key = ord(getch())
                if key == DOWNARROW:
                    if actv_selection < 9:
                        actv_selection += 1
                    continue
                elif key == UPARROW:
                    if actv_selection > 0:
                        actv_selection -= 1
                    continue
                else:
                    print("\n! Wrong key !")
                    time.sleep(1)
                    continue
            else:
                print("\n! Wrong key !")
                time.sleep(1)
                continue

            if user_input in range(9):
                data_to_change = ""
                while data_to_change == "":
                    print(event_object_for_printing)
                    print("------------------------------\n")
                    print("\n(0) Cancel\nChanging {} to: ".format(input_object_data_pairs[user_input]))
                    data_to_change = input("\n> ")
                    data_to_change = data_to_change.upper()
                    if data_to_change == "0":
                        return None
                    elif validators_for_data_to_change[user_input](data_to_change):
                        CHANGE_DATA = "UPDATE event SET {} = '{}' WHERE Id = {}".format(input_object_data_pairs[user_input], data_to_change, event_object_for_printing.id)
                        cursor_object.execute(CHANGE_DATA)
                        clear()
                        print("...Done!")
                        time.sleep(1)
                        return None
                    else:
                        print("Wrong {}.".format(input_object_data_pairs[user_input]))
                        data_to_change = ""
                        time.sleep(1)
                        clear()
            elif user_input == 9:
                clear()
                actv_selection = 0
                return None
    def add_new_donation_event():
        print("Adding new event...\n")
        time.sleep(1)
        clear()
        e1 = Event()
        while True:
            e1.date_of_event = input("Date of Event: ")
            if Validate.validate_date(
                    e1.date_of_event) and e1.registration_in_tendays():
                pass
            else:
                print(
                    "\n\t ! The registration should be at least 10 days from now. ! "
                )
                print(
                    "\t   ! Use this format to enter date: 'YYYY.MM.DD' ! \n")
                time.sleep(2)
                clear()
                continue

            e1.start_time = EventManagerCSV.data_in_e(e1,
                                                      Validate.validate_time,
                                                      "Start Time: ", TIME_ERR)
            e1.end_time = EventManagerCSV.data_in_e(e1, Validate.validate_time,
                                                    "End Time: ", TIME_ERR)
            while not e1.is_starttime_before_endtime():
                print(
                    "\n\t ! The starting time should be before the ending time. ! "
                )
                time.sleep(2)
                clear()
                e1.end_time = ""
                e1.end_time = EventManagerCSV.data_in_e(
                    e1, Validate.validate_time, "End Time: ", TIME_ERR)

            e1.zip_code = EventManagerCSV.data_in_e(e1,
                                                    Validate.validate_zipcode,
                                                    "ZIP code: ", ZIP_ERR)
            e1.city = EventManagerCSV.data_in_e(e1,
                                                Validate.validate_city_name,
                                                "City: ", CITY_ERR)
            e1.address = EventManagerCSV.data_in_e(e1,
                                                   Validate.validate_address,
                                                   "Address of event: ",
                                                   ADDRESS_ERR)
            e1.available_beds = EventManagerCSV.data_in_e(
                e1, Validate.validate_positive_int, "Available beds: ",
                POSINT_ERR)
            e1.planned_donor_number = EventManagerCSV.data_in_e(
                e1, Validate.validate_positive_int, "Planned donor number: ",
                POSINT_ERR)

            e1.successfull = EventManagerCSV.data_in_e(
                e1, Validate.validate_positive_int,
                "\n How many successfull donation was on the event?\n > ",
                POSINT_ERR)

            print("\nThe required functions: \n")

            print("Weekday :", e1.is_weekday())
            e1.duration = e1.calculate_duration()
            print("Duration: {} min  --  {} hours ".format(
                e1.duration, round(e1.duration / 60, 1)))
            print("Maximum donor number:", e1.max_donor_number())
            print("Success rate: {}".format(e1.success_rate()))
            input("\n\n (Press ENTER to go BACK)")
            EventManagerCSV.store_donation_data(e1)
            clear()
            break
    def change_event(input_id_string):
        event_to_change = []
        with open("Data/donations.csv", "r") as f:
            event_list = list(csv.reader(f))
        for event in event_list:
            if input_id_string == event[0]:
                event_to_change = list(event)
        if not event_to_change:
            print("\n No entry found with this ID.\n")
            time.sleep(1)
            clear()
            return None

        input_object_data_pairs = {
            0: "Date of Event",
            1: "Start Time",
            2: "End Time",
            3: "Zip Code",
            4: "City",
            5: "Address",
            6: "Available Beds",
            7: "Planned Donor Number",
            8: "Number of Successful Donations"
        }
        validators_for_data_to_change = {
            0: Validate.validate_date,
            1: Validate.validate_time,
            2: Validate.validate_time,
            3: Validate.validate_zipcode,
            4: Validate.validate_city_name,
            5: Validate.validate_address,
            6: Validate.validate_positive_int,
            7: Validate.validate_positive_int,
            8: Validate.validate_positive_int
        }
        event_object_for_printing = Event()
        event_object_for_printing.id = event_to_change[0]
        event_object_for_printing.date_of_event = event_to_change[1]
        event_object_for_printing.start_time = event_to_change[2]
        event_object_for_printing.end_time = event_to_change[3]
        event_object_for_printing.zip_code = event_to_change[4]
        event_object_for_printing.city = event_to_change[5]
        event_object_for_printing.address = event_to_change[6]
        event_object_for_printing.available_beds = event_to_change[7]
        event_object_for_printing.planned_donor_number = event_to_change[8]
        event_object_for_printing.successfull = event_to_change[9]

        actv_selection = 0
        while True:
            MenuManager.change_event_submenu(actv_selection,
                                             event_object_for_printing)

            key = ord(getch())
            if key == ESC:
                user_input = 9
                clear()
            elif key == ENTER:
                user_input = actv_selection
                clear()
            elif key == SPECIALKEYSELECTOR:
                key = ord(getch())
                if key == DOWNARROW:
                    if actv_selection < 9:
                        actv_selection += 1
                    continue
                elif key == UPARROW:
                    if actv_selection > 0:
                        actv_selection -= 1
                    continue
                else:
                    print("\n! Wrong key !")
                    time.sleep(1)
                    continue
            else:
                print("\n! Wrong key !")
                time.sleep(1)
                continue

            if user_input in range(9):
                data_to_change = ""
                while data_to_change == "":
                    print(event_object_for_printing)
                    print("------------------------------\n")
                    print("\n(0) Cancel\nChanging {} to: ".format(
                        input_object_data_pairs[user_input]))
                    data_to_change = input("\n> ")
                    data_to_change = data_to_change.upper()
                    if data_to_change == "0":
                        return None
                    elif validators_for_data_to_change[user_input](
                            data_to_change):
                        event_to_change[user_input + 1] = data_to_change
                        for number in range(len(event_list)):
                            if event_list[number][0] == event_to_change[0]:
                                event_list[number] = event_to_change
                        with open("Data/donations.csv", "w") as f:
                            donation_database = csv.writer(f,
                                                           delimiter=',',
                                                           lineterminator="\n")
                            donation_database.writerows(event_list)
                        clear()
                        print("...Done!")
                        time.sleep(1)
                        return None
                    else:
                        print("Wrong {}.".format(
                            input_object_data_pairs[user_input]))
                        data_to_change = ""
                        time.sleep(1)
                        clear()
            elif user_input == 9:
                clear()
                actv_selection = 0
                return None
    def change_event(input_id_string, cursor_object):
        event_to_change = []
        cursor_object.execute(QUERY_EVENTS_FROM_SQLDB)
        event_list = cursor_object.fetchall()
        for event in event_list:
            if int(input_id_string) == event[0]:
                event_to_change = list(event)
        if not event_to_change:
            print("\n No entry found with this ID.\n")
            time.sleep(1)
            clear()
            return None

        input_object_data_pairs = {
            0: "DateOfEvent",
            1: "StartTime",
            2: "EndTime",
            3: "ZipCode",
            4: "City",
            5: "Address",
            6: "AvailableBeds",
            7: "PlannedDonorNumber",
            8: "Successfull"
        }
        validators_for_data_to_change = {
            0: Validate.validate_date,
            1: Validate.validate_time,
            2: Validate.validate_time,
            3: Validate.validate_zipcode,
            4: Validate.validate_city_name,
            5: Validate.validate_address,
            6: Validate.validate_positive_int,
            7: Validate.validate_positive_int,
            8: Validate.validate_positive_int
        }
        event_object_for_printing = Event()
        event_object_for_printing.id = str(event_to_change[0])
        event_object_for_printing.date_of_event = event_to_change[1].strftime(
            '%Y.%m.%d')
        delta_to_time_obj = (datetime.min + event_to_change[2]).time()
        event_object_for_printing.start_time = delta_to_time_obj.strftime(
            '%H:%M')
        delta_to_time_obj2 = (datetime.min + event_to_change[3]).time()
        event_object_for_printing.end_time = delta_to_time_obj2.strftime(
            '%H:%M')
        event_object_for_printing.zip_code = str(event_to_change[4])
        event_object_for_printing.city = event_to_change[5]
        event_object_for_printing.address = event_to_change[6]
        event_object_for_printing.available_beds = str(event_to_change[7])
        event_object_for_printing.planned_donor_number = str(
            event_to_change[8])
        event_object_for_printing.successfull = str(event_to_change[9])

        actv_selection = 0
        while True:
            MenuManager.change_event_submenu(actv_selection,
                                             event_object_for_printing)

            key = ord(getch())
            if key == ESC:
                user_input = 9
                clear()
            elif key == ENTER:
                user_input = actv_selection
                clear()
            elif key == SPECIALKEYSELECTOR:
                key = ord(getch())
                if key == DOWNARROW:
                    if actv_selection < 9:
                        actv_selection += 1
                    continue
                elif key == UPARROW:
                    if actv_selection > 0:
                        actv_selection -= 1
                    continue
                else:
                    print("\n! Wrong key !")
                    time.sleep(1)
                    continue
            else:
                print("\n! Wrong key !")
                time.sleep(1)
                continue

            if user_input in range(9):
                data_to_change = ""
                while data_to_change == "":
                    print(event_object_for_printing)
                    print("------------------------------\n")
                    print("\n(0) Cancel\nChanging {} to: ".format(
                        input_object_data_pairs[user_input]))
                    data_to_change = input("\n> ")
                    data_to_change = data_to_change.upper()
                    if data_to_change == "0":
                        return None
                    elif validators_for_data_to_change[user_input](
                            data_to_change):
                        CHANGE_DATA = "UPDATE event SET {} = '{}' WHERE Id = {}".format(
                            input_object_data_pairs[user_input],
                            data_to_change, event_object_for_printing.id)
                        cursor_object.execute(CHANGE_DATA)
                        clear()
                        print("...Done!")
                        time.sleep(1)
                        return None
                    else:
                        print("Wrong {}.".format(
                            input_object_data_pairs[user_input]))
                        data_to_change = ""
                        time.sleep(1)
                        clear()
            elif user_input == 9:
                clear()
                actv_selection = 0
                return None