Пример #1
0
    def sport_selected(self, selected_sport):
        PrintGraphicsUI.sport_information(selected_sport)
        subaction = input("{}\n{}\n{}\n".format("1. Select Group",
                                                "2. Add new group to sport",
                                                "0. Exit"))
        if subaction == "1":
            group_list = self.all_groups(selected_sport)
            selected_group = self.pick_a_group(group_list)
            PrintGraphicsUI.group_info(selected_group)

            # # try:
            # sub_selection = int(input("Select group"))
            # selected_group = group_list[sub_selection]
            # bla = input("")

            # except (ValueError, TypeError, IndexError):
            # PrintGraphicsUI.oops()
            # return

        elif subaction == "2":
            self.SportList.new_group(selected_sport)
        else:
            print("Returning to Main Menu")
            time.sleep(0.5)
            return
Пример #2
0
    def new_group(self, selected_sport):
        """Takes in selected sport"""
        name = input("Write name of new group: ")
        try:
            group_size = input("Decide how big the group shall be: (number) ")
            #tuple of two integers, ages from (12,14)
            group_age_range_l = int(input("Ages ranging from: (number) "))
            group_age_range_h = int(input("to: (number) "))

            group_age_range = (group_age_range_l, group_age_range_h)

        except (ValueError, TypeError, IndexError):
            PrintGraphicsUI.oops()

        new_group = Group(name, group_size, group_age_range, 0, [], [])
        self.add_new_group(new_group, selected_sport)

        #== [ UNDO OP ] =============================================
        save_op = OpInfo(OpType.DELETE_GROUP, new_group, selected_sport)
        self.undo_stack.append(save_op)
        for op in self.undo_stack:
            print(f'Op Type: {op.op_type} -> Object pointer: {op}')
        #== [ END UNDO ] ============================================

        return new_group  #for when member makes new group to add to member?
Пример #3
0
 def pick_a_member(self, member_list):
     # try:
     selection = input("Input member's number: ")
     if selection == "0":
         return
     else:
         selected_member = member_list[int(selection) - 1]
         PrintGraphicsUI.member_profile(selected_member)
         self.member_profile_selected(selected_member)
Пример #4
0
 def pick_a_group(self, group_list):
     """Lets you select a group from the list above. Returns: selected group object"""
     try:
         selection = input("Input group number: ")
         if selection == "0":
             return
         else:
             selected_group = group_list[int(selection) - 1]
             return selected_group
     except (ValueError, TypeError, IndexError):
         PrintGraphicsUI.print_sel_error()
Пример #5
0
    def pick_a_sport(self, sport_list):
        """Lets you select a sport from the list above. Returns: selected sport object"""
        try:
            selection = input("Input sport number: ")
            if selection == "0":
                pass
            else:
                selected_sport = sport_list[int(selection) - 1]
                return selected_sport

        except (ValueError, TypeError, IndexError):
            PrintGraphicsUI.print_sel_error()
Пример #6
0
    def print_all_members(self):

        all_members = self.MemberList.get_members_ordered_by_name()
        lower = 0
        upper = 8
        action = ""
        highest = len(all_members)
        action = ""

        while action != 0:
            os.system('cls' if os.name == 'nt' else 'clear')
            if all_members == []: print("No members have been registered!")
            else:
                print("-" * 106)
                print("{:>2}".format("Members:"))
                print("-" * 106)
                print()
                print("{:>10} {:>25s} {:>20s}{:<12s}{}{:>4}".format(
                    "Name:", "Age:", "Phone No:", "Email:", "Unique ID:",
                    "Sports"))
                print("-" * 106)

            for idx, item in enumerate(all_members):
                if idx in range(lower, upper):
                    print("{:4s} {:}".format(str(idx + 1).zfill(3), item))
            print()
            print("-" * 106)

            action = input("\n{}\n{}\n{}\n{}\n{}\n".format(
                "1. Pick from list", "2. Up list", "3. Down list",
                "4. Print all members", "0. Exit"))

            if action == "1":  #Choose to pick a member by nr
                self.pick_a_member(all_members)
                return

            elif action == "2":  #Go up
                if lower > 0: lower -= 8
                if upper > 8: upper -= 8
            elif action == "3":  #Go down
                if upper >= highest:
                    print("There are no more members!")
                    time.sleep(1.0)
                else:
                    lower += 8
                    upper += 8
            elif action == "4":  #Show all
                lower = 0
                upper = highest
            elif action == "0":  #Exit
                return
            else:
                PrintGraphicsUI.print_sel_error()
Пример #7
0
 def __str__(self):
     
     try:
         sport_string = PrintGraphicsUI.make_string(self.sports)
     except TypeError:
         sport_string = ""
         
     
     return "{:<26s} {:12s} {:12s}{:<12s}{:6s}{:>4}".format(
         self.name,
         str(self.age),
         self.phone,
         self.email,
         str(self.unique_id),
         sport_string)
Пример #8
0
    def member_profile_selected(self, found_member):
        action = ""

        while action != 0:
            action = input(
                "\n1. Edit member\n2. Sport registration\n3. Group registration\n9. Remove member from system\n0. Exit\n"
            )

            #1. Member Edit
            if action == "1":
                print("{}\n{}\n{}\n{}\n{}\n".format("1. Name", "2. Phone no",
                                                    "3. Email", "4. Birthyear",
                                                    "0. Exit"))
                print("What would you like to edit?")

                new_info = self.MemberList.member_edit(found_member)
                if new_info != None:
                    print("Info has been changed to {}".format(new_info))
                print("Returning to main menu")
                self.MemberList.save_all_files()
                time.sleep(1)
                return

            #2. Member registration: Sport
            elif action == "2":
                subaction = ""
                sport_list = self.SportList.get_sports()
                # group_list = self.GroupList.get_groups()
                memb_id = found_member.unique_id

                while subaction != 0:
                    subaction = input("\n{}{}\n{}\n{}\n".format(
                        "Sport registration for ", found_member.name,
                        "1. Register", "2. Unregister"))
                    #Register member for sport
                    if subaction == "1":

                        self.sport_registration(found_member)
                        print("Registration complete. Returning to main menu")
                        time.sleep(0.5)
                        return

                    #Unregister member from sport
                    elif subaction == "2":
                        print("Registered sports:\n")
                        for idx, item in enumerate(found_member.sports):
                            print(idx + 1, item.name)
                        try:
                            sport_selected = int(
                                input(
                                    "Which sport would you like to unregister? "
                                ))
                            sport_to_unregister_from = found_member.sports[
                                sport_selected - 1]

                            self.unregister_from_sport(
                                found_member, sport_to_unregister_from)
                            print(
                                "Member has been unregistered. Returning to Main menu."
                            )
                            found_member.sports.remove(
                                sport_to_unregister_from)

                            self.unregister_from_group(
                                found_member, sport_to_unregister_from)
                            self.save_all()
                            return
                        except ValueError:
                            PrintGraphicsUI.print_sel_error()

            elif action == "3":
                self.group_registration(found_member)

            #9. Member DELETE
            elif action == "9":
                #member delete - unregister member from all sports and groups!
                self.unregister_from_sport(found_member)
                #delete member from savefiles
                self.MemberList.member_delete(found_member)

                print("Member has been deleted. Returning to Main menu.")
                self.save_all()
                time.sleep(1)
                return

            elif action == "0":
                return
            else:
                PrintGraphicsUI.print_sel_error()
                PrintGraphicsUI.member_profile(found_member)
Пример #9
0
    def main(self):
        """Main menu"""

        first_action = ""
        self.MemberList.load_all_files()
        if not self.MemberList.name_map:
            print(
                "Would you like to start the program with test cases included?"
            )
            first_action = input("1. Yes 2. No \n")

        #
        #
        # TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE #
        # Test subjects ################################################################################
        if first_action == "1":
            self.SportList.test()
            self.MemberList.test()
            self.MemberList.load_all_files()
            self.SportList.load_all_files()
            self.SportList.group_test()
            self.test()
            self.save_all()

        else:
            pass

        # TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE #
        #
        #
        #
    #                                -----#### MAIN MENU STARTS #### -----------
        action = ""
        while action != "0":
            os.system('cls' if os.name == 'nt' else 'clear')

            print("Loading savefiles....")
            #Use Pickle to load saved data. If No savefile found -> print error.
            self.MemberList.load_all_files()
            self.SportList.load_all_files()

            # self.GroupList.load_all_files()
            time.sleep(0.5)
            #
            #
            #
            # TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE #
            # Register tests for test subjects #############################################################
            # self.test()
            # Register tests for test subjects #############################################################
            # TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE ## TESTCASE #
            #
            #
            #
            PrintGraphicsUI.print_intro()
            action = input("What would you like to do?\n")

            #1. Register new member
            if action == "1":
                """Goes to service->Member class, makes new Member object
                Gives each member a unique ID no for easy listing
                Goes to Registraion and registers member in sport + group"""
                new_member = self.MemberList.new_member()

                subaction = input(
                    "Would you like to register for a sport now?\n1. Yes 2. No, later "
                )
                print()
                if subaction == "1":
                    self.sport_registration(new_member)
                else:
                    pass

            #2. Register new sport
            elif action == "2":
                """Goes to service->Sport class and makes new Sport object
                checks if that Sport already exists"""
                self.SportList.new_sport()

            #3. Register new group
            elif action == "3":
                #first select sport
                try:
                    print("You must first select a sport.")
                    time.sleep(1.5)
                    sport_list = self.print_all_sports()
                    selected_sport = self.pick_a_sport(sport_list)
                    self.SportList.new_group(selected_sport)
                except (ValueError, TypeError, IndexError, AttributeError):
                    PrintGraphicsUI.oops()
                    print("Perhaps sports have been registered!")

            #4. Register member into sport
            elif action == "4":
                self.print_all_members()

            #5. Find member - get data screen up
            elif action == "5":
                """Goes to service -> returns user by input name"""
                found_member = None
                search_term = input(
                    "Please write name, phone no(xxx-xxxx), email or birthyear(xxxx) of member: "
                )

                found_member = self.MemberList.search(search_term)
                if found_member != None:
                    PrintGraphicsUI.member_profile(found_member)
                    self.member_profile_selected(found_member)
                else:
                    PrintGraphicsUI.print_not_found()

            #6. List all members - select member and see info, and all sport
            elif action == "6":
                """Prints list of all members"""
                self.print_all_members()

            #7. List all sports - select sport and see detailed info(list of users)
            elif action == "7":
                """Prints list of all sports"""
                try:
                    sport_list = self.print_all_sports()
                    selected_sport = self.pick_a_sport(sport_list)
                    # if selected_sport:
                    self.sport_selected(selected_sport)
                except (ValueError, TypeError, IndexError, AttributeError):
                    PrintGraphicsUI.oops()
                    print("No sports have been registered!")

            #x. FOR UNDO
            elif action == "x":
                """Press x to undo latest actions for: [member, sport, group]"""
                self.undo_ops()
                self.save_all()

            #0. Save & Exit
            elif action == "0":
                self.save_all()

            else:
                PrintGraphicsUI.print_sel_error()