Пример #1
0
    def update_entity_key_list_value_column(self, company, column, value: dict, action="add"):

        if value is None:
            return False

        print("Start update_entity_profile_key_list_value_column")
        print(locals())

        existing_key_value = list(self.df.loc[self.df.company == company, column])[0]
        print("existing_key_value from df: " + str(existing_key_value))
        if existing_key_value is None:
            existing_key_value = {}
        else:
            existing_key_value = eval(existing_key_value)
        print("existing_key_value from df: " + str(existing_key_value))
        for ex_key, ex_value in existing_key_value.items():
            existing_key_value[ex_key] = utilities.str_to_list(str(ex_value))
        print("existing_key_value_list: " + str(existing_key_value))

        print("value to process: " + str(value))
        (to_key, to_value), = dict(value).items()

        if existing_key_value == {}:
            if action == "add":
                dest_key_value = dict(value)
            if action == "remove":
                dest_key_value = existing_key_value

        if (existing_key_value != {}) and (to_key not in existing_key_value.keys()):
            if action == "add":
                dest_key_value = {**existing_key_value, **dict(value)}
            if action == "remove":
                dest_key_value = existing_key_value

        if (existing_key_value != {}) and (to_key in existing_key_value.keys()):
            for ex_key, ex_value in existing_key_value.items():
                if ex_key == to_key:
                    if action == "add":
                        ex_value.extend(to_value)
                        existing_key_value[ex_key] = list(set(ex_value))
                    if action == "remove":
                        existing_key_value[ex_key] = list(set(ex_value) - set(to_value))
            dest_key_value = existing_key_value

        print("dest_key_value: " + str(dest_key_value))

        dest_value = utilities.dict_to_str(dest_key_value)
        print("dest_value: " + str(dest_value))

        self.df.loc[self.df.company == company, column] = dest_value
        print(self.df)

        return True
Пример #2
0
    def add_entity(self, company, status=STATUS_ENABLED, site: list = None, camera: dict = None, controller: dict = None):

        print("Start add_entity in Entity.py")
        print(locals())

        #Update existing record
        if company in self.df["company"].tolist():
            print("Update existing company: " + company)
            update_single_value = True
            add_list_value = True
            add_key_list_value = True

            info_dict = {"status": status, "site": site, "camera": camera, "controller": controller}

            for key in list(info_dict.keys()):
                if info_dict[key] is not None:
                    if key in ENTITY_SINGLE_VALUE_COLUMNS:
                        update_single_value = update_single_value and self.update_entity_single_value_column(
                            company=company, column=key, value=info_dict[key])
                    if key in ENTITY_LIST_VALUE_COLUMNS:
                        add_list_value = add_list_value and self.update_entity_list_value_column(
                            company=company, column=key, value=info_dict[key], action="add")
                    if key in ENTITY_KEY_LIST_VALUE_COLUMNS:
                        add_key_list_value = add_key_list_value and self.update_entity_key_list_value_column(company=company, column=key, value=info_dict[key], action="add")


            return update_single_value and add_list_value and add_key_list_value

        #Add new record
        print("Add new company: " + company)

        [status] = list(map(utilities.none_to_blank, [status]))
        [site] = list(
            map(utilities.none_to_blank_list, [site]))
        [camera, controller] = list(
            map(utilities.none_to_blank_dict, [camera, controller]))
        print("status: " + str(status) + " site: " + str(site) + " camera: " + str(camera) + " controller: " + str(controller))

        info_dict = {"company": company, "status": status, "site": utilities.list_to_str(site), "camera": utilities.dict_to_str(camera),
                     "controller": utilities.dict_to_str(controller)}
        print("info to add: " + str(info_dict))

        self.df = self.df.append([info_dict], ignore_index=True)
        print("Added \n" + str(info_dict) + "  \nto entity profile")
        print(self.df)

        return True
Пример #3
0
    def add_authority(self,
                      email,
                      password=None,
                      status=None,
                      company: list = None,
                      site: dict = None,
                      role: dict = None):

        print("Start add_authority in Authority.py")
        print(locals())

        if not utilities.email_is_valid(email):
            print("Invalid email: " + email)
            return False

        #Update existing record
        if email in self.df["email"].tolist():
            print("Update existing user: "******"password": password,
                "status": status,
                "company": company,
                "site": site,
                "role": role
            }

            for key in list(info_dict.keys()):
                if info_dict[key] is not None:
                    if key in AUTHORITY_SINGLE_VALUE_COLUMNS:
                        update_single_value = update_single_value and self.update_authority_single_value_column(
                            email=email, column=key, value=info_dict[key])
                    if key in AUTHORITY_LIST_VALUE_COLUMNS:
                        add_list_value = add_list_value and self.update_authority_list_value_column(
                            email=email,
                            column=key,
                            value=info_dict[key],
                            action="add")
                    if key in AUTHORITY_KEY_LIST_VALUE_COLUMNS:
                        add_key_list_value = add_key_list_value and self.update_authority_key_list_value_column(
                            email=email,
                            column=key,
                            value=info_dict[key],
                            action="add")

            return update_single_value and add_list_value and add_key_list_value

        #Add new record
        print("Add new user: "******"company: " + str(company) + " site: " + str(site) + " role: " +
              str(role))

        info_dict = {}
        info_dict["email"] = email
        info_dict["password"] = password
        info_dict["status"] = status
        info_dict["company"] = utilities.list_to_str(company)
        info_dict["site"] = utilities.dict_to_str(site)
        print(info_dict["site"])
        info_dict["role"] = utilities.dict_to_str(role)
        # info_dict = {"email": email, "password": password, "status": status, "company": utilities.list_to_str(company), "site": utilities.list_to_str(site), "role": utilities.list_to_str(role)}
        print("info to add: " + str(info_dict))

        self.df = self.df.append([info_dict], ignore_index=True)
        print("Added \n" + str(info_dict) + "  \nto user profile")
        print(self.df)

        return True
Пример #4
0
    def add_role(
        self,
        company,
        custome_role: list,
        service: dict,
    ):

        print("Start add_role in Role.py")
        print(locals())

        if company is None or custome_role is None or service is None or company == "" or custome_role == "" or \
                service == "" or custome_role == [] or service == {}:
            return False

        #Update existing record
        if self.db_type == "csv":
            if company in self.df["company"].tolist():
                print("Update existing company: " + company)
                update_single_value = True
                add_list_value = True
                add_key_list_value = True

                info_dict = {"custome_role": custome_role, "service": service}

                for key in list(info_dict.keys()):
                    if info_dict[key] is not None:
                        if key in ROLE_SINGLE_VALUE_COLUMNS:
                            update_single_value = update_single_value and self.update_role_single_value_column(
                                company=company,
                                column=key,
                                value=info_dict[key])
                        if key in ROLE_LIST_VALUE_COLUMNS:
                            add_list_value = add_list_value and self.update_role_list_value_column(
                                company=company,
                                column=key,
                                value=info_dict[key],
                                action="add")
                        if key in ROLE_KEY_LIST_VALUE_COLUMNS:
                            add_key_list_value = add_key_list_value and self.update_role_key_list_value_column(
                                company=company,
                                column=key,
                                value=info_dict[key],
                                action="add")

                return update_single_value and add_list_value and add_key_list_value

        #Add new record
        print("Add new company: " + company)

        info_dict = {
            "company": company,
            "custome_role": utilities.list_to_str(custome_role),
            "service": utilities.dict_to_str(service)
        }
        print("info to add: " + str(info_dict))

        self.df = self.df.append([info_dict], ignore_index=True)
        print("Added \n" + str(info_dict) + "  \nto role profile")
        print(self.df)

        return True