示例#1
0
文件: bdo.py 项目: riyaz489/mnrega
    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.PASSWORD.name):
                if not Validation.password(user_input):
                    print("password is weak")
                    input()
                    return
                user_input = encrypt_pass(user_input)
            if field == str(GpmUpdateFields.AGE.name):
                if not Validation.age(user_input):
                    print("age is not valid")
                    input()
                    return
            if field == str(GpmUpdateFields.PINCODE.name):
                if not Validation.pincode(user_input):
                    print("pincode is not valid")
                    input()
                    return
            if field == str(GpmUpdateFields.GENDER.name):
                if not Validation.gender(user_input):
                    print("gender is not valid")
                    input()
                    return

            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()
示例#2
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)
示例#3
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()
示例#4
0
 def test_pincode(self):
     inputs = ['452323', '2020', 'invalid_piincode', '-23234']
     self.assertEqual(True, Validation.pincode(inputs[0]))
     self.assertEqual(False, Validation.pincode(inputs[1]))
     self.assertEqual(False, Validation.pincode(inputs[2]))
     self.assertEqual(False, Validation.pincode(inputs[3]))