예제 #1
0
    def create_project(self):
        """
          this method is used to create project for current bdo.
        """
        try:
            print("choose gpm for project\n")
            gpm_list = self.get_gpm_list()
            menu = Menu()
            gpm_names = [x for x in gpm_list.keys()]
            gpm_names.extend([str(BackButton.EXIT.name)])
            gpm_name = menu.draw_menu(gpm_names)
            input()
            gpm_id = gpm_list[gpm_name]

            print("choose project type:\n")
            menu2 = Menu()
            project_types = [x.name for x in ProjectType]
            project_types.extend([str(BackButton.EXIT.name)])
            project_type = menu2.draw_menu(project_types)
            input()

            project_id = str(uuid.uuid4())
            project_name = input("enter project name: ")
            labours = input("enter expected labours:  ")
            if not Validation.is_int(labours):
                print("labours count is not valid")
                input()
                sys.exit()
            cost = input("enter estimated project cost: ")
            if not Validation.is_int(cost):
                print("cost is not valid")
                input()
                sys.exit()
            area = input("enter estimated project area: ")
            if not Validation.is_int(area):
                print("area is not valid")
                input()
                sys.exit()
            start_date = input("enter estimated start date: ")
            if not Validation.is_date(start_date):
                print("start date is not valid")
                input()
                sys.exit()
            end_date = input("enter estimated end date: ")
            if not Validation.is_date(end_date):
                print("end date is not valid")
                input()
                sys.exit()
            is_deleted = 'False'
            created_by = self.bdo_id
            self.conn.create_project(project_id, project_name, labours, cost,
                                     area, start_date, end_date, gpm_id,
                                     created_by, project_type, is_deleted)
            self.conn.commit_data()
            print("\n" + Color.F_Green + "project created" + Base.END)
        except Exception as e:
            print(e)
            self.conn.rollback_data()
예제 #2
0
    def update_gpm(self):
        """
          this method is used to update gpm for current bdo.
        """
        try:
            gpm_list = self.get_gpm_list()
            menu = Menu()
            gpm_names = [x for x in gpm_list.keys()]
            gpm_names.extend(
                [str(BackButton.EXIT.name),
                 str(BackButton.BACK.name)])
            gpm_name = menu.draw_menu(gpm_names)
            input()
            if str(BackButton.BACK.name) == gpm_name:
                return
            gpm_id = gpm_list[gpm_name]
            print("select the field to update: \n")
            menu = Menu()
            details = [x.name for x in GpmUpdateFields]
            details.extend([str(BackButton.EXIT.name)])
            field = menu.draw_menu(details)
            input()
            user_input = input("enter new value for " + str(field) + " ")
            user_table_fields = [1, 2, 3]
            # validating field
            if field == str(GpmUpdateFields.AGE.name):
                if not Validation.is_int(user_input):
                    print("age is not valid")
                    input()
                    sys.exit()
            if field == str(GpmUpdateFields.PINCODE.name):
                if not Validation.pincode(user_input):
                    print("pincode is not valid")
                    input()
                    sys.exit()
            if field == str(GpmUpdateFields.GENDER.name):
                if not Validation.gender(user_input):
                    print("gender is not valid")
                    input()
                    sys.exit()

            query = ""
            # if field belong to user table
            if user_table_fields.count(GpmUpdateFields[field].value) == 1:
                self.conn.update_user(str(field), gpm_id, user_input)
            else:
                self.conn.update_personal_details(str(field), gpm_id,
                                                  user_input)
            self.conn.commit_data()
            print("\n" + Color.F_Green + "record updated" + Base.END)
        except Exception as e:
            print(e)
            self.conn.rollback_data()
예제 #3
0
    def show_requests(self):
        """
            this method is used show request and resolve request of current gpm.
        """
        try:
            projects = self.conn.get_requests(self.gpm_id)
            result = projects.fetchall()
            counter = 0
            # getting columns for showing requests and adding index column at first in list
            projects_fields = (('index'),) + projects.description
            # request is empty then returning early with a message
            if len(result) == 0:
                print(Color.F_Red + "there is no pending request" + Base.END)
                return
            temp = result
            # converting list of tuples into list of list
            temp = [list(elem) for elem in temp]
            print("write index of request to manage:\n")
            for request in temp:
                request.insert(0, counter)
                counter += 1
            table = PrettyTable()
            table.field_names = [column[0] for column in projects_fields[:-1]]
            for row in temp:
                table.add_row(row[:-1])
            print(table)
            row_number = input("enter index number: ")
            if not Validation.is_int(row_number):
                print("row number is not valid")
                input()
                return
            menu = Menu()
            result_names = [x.name for x in RequestResult]
            result_names.extend([str(BackButton.EXIT.name)])
            result_name = menu.draw_menu(result_names)
            input()
            status = "NULL"
            if str(result_name) == str(RequestResult.APPROVED.name):
                status = "'True'"
            elif str(result_name) == str(RequestResult.REJECTED.name):
                status = "'False'"

            self.conn.resolve_request(status, result[int(row_number)][4])
            self.conn.commit_data()
            print(Color.F_Green + "Request completed successfully" + Base.END)
        except Exception as e:
            print(e)
            self.conn.rollback_data()
예제 #4
0
    def update_members(self):
        """
           this method is used to update member details of current gpm.
        """
        members_list = self.get_members_list()
        menu = Menu()
        members_names = [x for x in members_list.keys()]
        members_names.extend(
            [str(BackButton.EXIT.name),
             str(BackButton.BACK.name)])
        members_name = menu.draw_menu(members_names)
        input()
        if str(BackButton.BACK.name) == members_name:
            return
        members_id = members_list[members_name]
        print("select the field to update: \n")
        menu = Menu()
        details = [x.name for x in GpmUpdateFields]
        details.extend([str(BackButton.EXIT.name)])
        field = menu.draw_menu(details)
        input()
        user_input = input("enter new value for " + str(field) + " ")
        user_table_fields = [1, 2, 3]

        # validations
        if field == str(GpmUpdateFields.GENDER.name):
            if not Validation.gender(user_input):
                print("gender is not valid")
                input()
                sys.exit()
        if field == str(GpmUpdateFields.PINCODE.name):
            if not Validation.pincode(user_input):
                print("pincode is not valid")
                input()
                sys.exit()
        if field == str(GpmUpdateFields.AGE.name):
            if not Validation.is_int(user_input):
                print("age is not valid")
                input()
                sys.exit()
        # if field belong to user table
        if user_table_fields.count(GpmUpdateFields[field].value) == 1:
            self.conn.update_user(str(field), members_id, user_input)
        else:
            self.conn.update_personal_details(str(field), members_id,
                                              user_input)
        self.conn.commit_data()
        print("\n" + Color.F_Green + "record updated" + Base.END)
예제 #5
0
파일: bdo.py 프로젝트: riyaz489/mnrega
    def create_gpm(self):
        """
        this method is used to create gpm for current bdo.
        """
        try:
            name = input("enter gpm name ")
            id = str(uuid.uuid4())
            password = input("enter password for gpm ")
            if not Validation.password(password):
                print("weak password")
                input()
                return
            user_name = input("enter user name for gpm ")
            role_id = int(Role.GPM.value)
            created_at = datetime.datetime.now().date()
            updated_at = datetime.datetime.now().date()
            is_deleted = 'False'
            state = input("enter state ")
            district = input("enter district ")
            pincode = input("enter pincode ")
            if not Validation.pincode(pincode):
                print("pin code is not valid")
                input()
                return

            age = input("enter age ")
            if not Validation.is_int(age):
                print("age is not valid")
                input()
                return
            gender = input("enter gender ")
            if not Validation.gender(gender):
                print("gender is not valid")
                input()
                return
            created_by = self.bdo_id
            encrypted_pass = encrypt_pass(password)
            self.conn.add_user(id, encrypted_pass, user_name, role_id,
                               created_at, updated_at, name, is_deleted)
            self.conn.add_personal_details(id, state, district, pincode, age,
                                           gender, created_by)
            self.conn.commit_data()
            print("\n" + Color.F_Green + "record inserted" + Base.END)
        except Exception as e:
            print(e)
            self.conn.rollback_data()
예제 #6
0
    def show_requests(self):
        """
          this method is used to show and resolve all requests for current bdo.
        """
        try:
            projects = self.conn.get_requests(self.bdo_id)
            # adding index column to given result
            projects_fields = (('index'), ) + projects.description
            result = projects.fetchall()
            counter = 0
            # request is empty then returning early with a message
            if len(result) == 0:
                print(Color.F_Red + "there is no pending request" + Base.END)
                return

            print("write index of request to manage:\n")
            temp = result
            # converting list of tuples into list of list
            temp = [list(elem) for elem in temp]
            for request in temp:
                if str(RequestType.APPROVAL.name) == str(request[0]):
                    temp2 = str(request[2]).split('|')
                    request[2] = temp2[0] + " request for " + temp2[
                        4] + " project for " + temp2[1] + " member"
                # inserting data for index column
                request.insert(0, counter)
                counter += 1
            table = PrettyTable()
            # assigning field names to pretty table object and removing request id column
            table.field_names = [column[0] for column in projects_fields[:-1]]
            for row in temp:
                # removing request id from temp list and adding to table row
                table.add_row(row[:-1])
            print(table)
            row_number = input("enter index number: ")
            if not Validation.is_int(row_number):
                print("index number is not valid")
                input()
                sys.exit()
            menu = Menu()
            result_names = [x.name for x in RequestResult]
            result_names.extend([str(BackButton.EXIT.name)])
            result_name = menu.draw_menu(result_names)
            input()
            status = "NULL"
            if str(RequestType.APPROVAL.name) == str(
                    result[int(row_number)][0]):
                temp = str(result[int(row_number)][2]).split('|')
                req_type = str(temp[0])
                self.project_id = str(temp[3])
                self.member_id = str(temp[2])
                if req_type == str(
                        ApprovalType.WAGE.name) and str(result_name) == str(
                            RequestResult.APPROVED.name):
                    self.delete_project_members()
                    status = "'True'"
                elif req_type == str(
                        ApprovalType.MEMBER.name) and str(result_name) == str(
                            RequestResult.APPROVED.name):
                    project_members_id = self.conn.get_project_members(
                        self.project_id)
                    members_required = self.conn.get_project_members_required(
                        self.project_id)
                    # checking if total number of members in given project are less then actual project requirement
                    if members_required[0] <= len(project_members_id):
                        print(
                            Color.F_Red +
                            "project members limit exceeded can't accept request"
                            + Base.END)
                        return
                    self.conn.assign_project_members(self.project_id,
                                                     self.member_id)
                    status = "'True'"
                elif str(result_name) == str(RequestResult.REJECTED.name):
                    status = "'False'"
            else:
                if str(result_name) == str(RequestResult.APPROVED.name):
                    status = "'True'"
                elif str(result_name) == str(RequestResult.REJECTED.name):
                    status = "'False'"
            self.conn.resolve_request(status, result[int(row_number)][4])
            self.conn.commit_data()
            print(Color.F_Green + "Request completed successfully" + Base.END)
        except Exception as e:
            print(e)
            self.conn.rollback_data()
예제 #7
0
    def update_project(self):
        """
          this method is used to update project for current bdo.
        """
        print("choose project")
        project_list = self.get_project_list()
        menu = Menu()
        project_names = [x for x in project_list.keys()]
        project_names.extend(
            [str(BackButton.EXIT.name),
             str(BackButton.BACK.name)])
        project_name = menu.draw_menu(project_names)
        input()
        if str(BackButton.BACK.name) == project_name:
            return
        project_id = project_list[project_name]

        print("select the field to update: \n")
        menu2 = Menu()
        details = [x.name for x in ProjectsUpdateFields]
        details.extend([str(BackButton.EXIT.name)])
        field = menu2.draw_menu(details)
        input()
        user_input = ""
        if ProjectsUpdateFields[
                field].value == ProjectsUpdateFields.PROJECT_TYPE.value:
            print("choose project type: \n")
            menu3 = Menu()
            project_types = [x.name for x in ProjectType]
            project_types.extend([str(BackButton.EXIT.name)])
            user_input = menu3.draw_menu(project_types)
            input()
        else:
            user_input = input("enter new value for " + str(field) + " ")
            # validations
            if field == str(ProjectsUpdateFields.AREA_OF_PROJECT.name):
                if not Validation.is_int(user_input):
                    print("area is not valid")
                    input()
                    sys.exit()
            if field == str(ProjectsUpdateFields.TOTAL_LABOUR_REQUIRED.name):
                if not Validation.is_int(user_input):
                    print("labour required is not valid")
                    input()
                    sys.exit()

            if field == str(ProjectsUpdateFields.ESTIMATED_START_DATE.name):
                if not Validation.is_date(user_input):
                    print("start date is not valid")
                    input()
                    sys.exit()
            if field == str(ProjectsUpdateFields.ESTIMATED_END_DATE.name):
                if not Validation.is_date(user_input):
                    print("end date is not valid")
                    input()
                    sys.exit()
            if field == str(ProjectsUpdateFields.ESTIMATED_COST.name):
                if not Validation.is_int(user_input):
                    print("cost is not valid")
                    input()
                    sys.exit()
        self.conn.update_project(field, user_input, project_id)
        self.conn.commit_data()
        print("\n" + Color.F_Green + "record updated" + Base.END)
예제 #8
0
 def test_is_int(self):
     inputs = ['2020', 'invalid_int', '-34']
     self.assertEqual(True, Validation.is_int(inputs[0]))
     self.assertEqual(False, Validation.is_int(inputs[1]))
     self.assertEqual(False, Validation.is_int(inputs[2]))