def get_edit_company_service(self, page_settings, company_sn=0): self.__reset_return_value() html = "" if company_sn > 0: vcms_db_agent = VcmsDbAgent() page_settings["company_sn"] = company_sn system_service = vcms_db_agent._get_system_service_data() company_service = vcms_db_agent._get_company_service_data( company_sn) service = {} for k, v in company_service.items(): service[int(v["service_sn"])] = int(v["service_sn"]) return_data = collections.OrderedDict() for k, v in system_service.items(): if k not in service: return_data[k] = v page_settings["per_product_image_cnt_list"] = reversed( range( 1, (int(page_settings["per_product_image_cnt_setting"]) + 1))) page_settings["service_list"] = return_data page_settings[ "company_name"] = vcms_db_agent._get_all_company_data( )[company_sn]["company_name"] html = render_template("tab_ui/vcms_edit_company_service.tpl", data=page_settings) return html
def get_edit_company_license_request(self, page_settings, company_sn=0): self.__reset_return_value() html = "" page_settings["company_license_request_tab"] = 13 page_settings["add_company_license_request"] = 14 if company_sn > 0: vcms_db_agent = VcmsDbAgent() vcms_license_db_agent = VcmsLicenseDbAgent() page_settings["company_sn"] = company_sn system_service = vcms_db_agent._get_system_service_data() company_service = vcms_db_agent._get_company_service_data( company_sn) license_encrypt_types = vcms_license_db_agent._get_all_license_encrypt_type_data( ) license_trial_types = vcms_license_db_agent._get_all_license_trial_type_data( ) license_id_types = vcms_license_db_agent._get_all_license_id_type_data( ) # company bind service list service = {} for k, v in company_service.items(): service[int(v["service_sn"])] = int(v["service_sn"]) return_data = collections.OrderedDict() for k, v in system_service.items(): if k in service: return_data[k] = v page_settings["service_list"] = return_data # all license encrypt types license_encrypt_list = {} for k, v in license_encrypt_types.items(): license_encrypt_list[str(v["sn"])] = v page_settings["license_encrypt_list"] = license_encrypt_list # all license trial types license_trial_list = {} for k, v in license_trial_types.items(): license_trial_list[str(v["sn"])] = v page_settings["license_trial_list"] = license_trial_list # all license id types license_id_type_list = {} for k, v in license_id_types.items(): license_id_type_list[str(v["sn"])] = v page_settings["license_id_type_list"] = license_id_type_list # set default start date , expire date _today = datetime.datetime.today().strftime("%Y-%m-%d") page_settings["version"] = "1.0.0" page_settings["start_date"] = _today page_settings["expire_date"] = _today page_settings["batch_license_count"] = 0 page_settings[ "company_name"] = vcms_db_agent._get_all_company_data( )[company_sn]["company_name"] html = render_template( "tab_ui/vcms_edit_company_license_request.tpl", data=page_settings) return html
def set_company_license_request_data(self, page_settings, parameter_dict): self.__reset_return_value() data_check = {"company_name_error": ""} vcms_db_agent = VcmsDbAgent() vcms_license_db_agent = VcmsLicenseDbAgent() data_parameter = {} data_parameter["company_sn"] = int(parameter_dict.get("company_sn")) data_parameter[ "company_name"] = vcms_db_agent._get_company_profile_data( data_parameter["company_sn"])["company_name"] data_parameter["encrypt_sn"] = int(parameter_dict.get("encrypt_sn")) data_parameter[ "encrypt_type"] = vcms_license_db_agent._get_all_license_encrypt_type_data( )[data_parameter["encrypt_sn"]]["encrypt_type"] data_parameter["service_sn"] = int(parameter_dict.get("service_sn")) data_parameter[ "service_name"] = vcms_db_agent._get_system_service_data()[ data_parameter["service_sn"]]["service_name"] data_parameter[ "service_type"] = vcms_db_agent._get_system_service_data()[ data_parameter["service_sn"]]["service_type"] data_parameter["license_feature"] = data_parameter["service_sn"] data_parameter["version"] = parameter_dict.get("version") data_parameter["trial_sn"] = int(parameter_dict.get("trial_sn")) data_parameter[ "trial_type"] = vcms_license_db_agent._get_all_license_trial_type_data( )[data_parameter["trial_sn"]]["trial_type"] data_parameter["trial_days"] = int( vcms_license_db_agent._get_all_license_trial_type_data()[ data_parameter["trial_sn"]]["trial_days"]) data_parameter["id_sn"] = int(parameter_dict.get("id_sn")) data_parameter[ "id_type"] = vcms_license_db_agent._get_all_license_id_type_data()[ data_parameter["id_sn"]]["id_type"] data_parameter["hostid"] = parameter_dict.get("hostid") data_parameter["start_date"] = parameter_dict.get("start_date")[0:10] data_parameter["expire_date"] = parameter_dict.get("expire_date")[0:10] data_parameter["connect_count"] = parameter_dict.get("connect_count") data_parameter["server"] = parameter_dict.get("server") data_parameter["port"] = parameter_dict.get("port") data_parameter["license_count"] = int( parameter_dict.get("license_count")) data_parameter["batch_license_count"] = int( parameter_dict.get("batch_license_count")) # trial process if (data_parameter["trial_sn"] != 1): data_parameter["hostid"] = data_parameter["trial_type"] data_parameter["expire_date"] = str( datetime.datetime.strptime(data_parameter["start_date"], '%Y-%m-%d') + datetime.timedelta(data_parameter["trial_days"] - 1))[0:10] # id_type = 1 and hostid process if (data_parameter["id_sn"] == 1 and data_parameter["hostid"] == ''): data_parameter["hostid"] = uuid.uuid5(uuid.NAMESPACE_DNS, str(datetime.datetime.now())) request_sn = vcms_license_db_agent._add_company_license_request_data( data_parameter) if request_sn > 0: # commit success self.return_value["data"] = self.get_company_license_request_list( page_settings, int(parameter_dict.get("company_sn"))) self.return_value["message"] = page_settings["success_text"] self.return_value["code"] = 1 return self.return_value else: data_check["company_name_error"] = page_settings[ "commit_error_text"] self.return_value["data"] = data_check return self.return_value
def set_company_service(self, page_settings, parameter_dict): self.__reset_return_value() data_check = { "service_sn_error": page_settings["empty_cnt_error"], "per_product_image_cnt_error": page_settings["empty_cnt_error"], "max_user_cnt_error": page_settings["empty_cnt_error"], "max_product_cnt_error": page_settings["empty_cnt_error"], "min_training_cnt_error": page_settings["empty_cnt_error"], "detection_api_ip_error": page_settings["empty_error"], "feature_api_ip_error": page_settings["empty_error"], "pkl_update_api_ip_error": page_settings["empty_error"] } company_sn = parameter_dict.get("company_sn") if company_sn is not None and int(company_sn) > 0: vcms_db_agent = VcmsDbAgent() error_data = 0 service_sn = parameter_dict.get("service_sn") if service_sn is not None and service_sn != "": system_service = vcms_db_agent._get_system_service_data() data_check["service_sn_error"] = "" if int(service_sn) not in system_service: error_data += 1 data_check["service_sn_error"] = page_settings[ "service_error_text"] company_service = vcms_db_agent._get_company_service_data( company_sn) if int(service_sn) in company_service: error_data += 1 data_check["service_sn_error"] = page_settings[ "same_as_service_error"] else: error_data += 1 per_product_image_cnt = parameter_dict.get("per_product_image_cnt") if per_product_image_cnt is not None and per_product_image_cnt != "": data_check["per_product_image_cnt_error"] = "" if int(per_product_image_cnt) <= 0 or int( per_product_image_cnt) > int( page_settings["per_product_image_cnt_setting"]): error_data += 1 data_check["per_product_image_cnt_error"] = page_settings["invalid_per_product_image_cnt_error"] + \ page_settings["per_product_image_cnt_setting"] else: error_data += 1 max_product_cnt = parameter_dict.get("max_product_cnt") if max_product_cnt is not None and max_product_cnt != "": data_check["max_product_cnt_error"] = "" if re.compile("^[+]?\\d+$").match(max_product_cnt) is None: error_data += 1 data_check["max_product_cnt_error"] = page_settings[ "invalid_cnt_error"] else: if int(max_product_cnt) <= 0 or int(max_product_cnt) > int( page_settings["max_product_cnt_setting"]): error_data += 1 data_check["max_product_cnt_error"] = page_settings["invalid_product_cnt_error"] + \ page_settings["max_product_cnt_setting"] else: error_data += 1 min_training_cnt = parameter_dict.get("min_training_cnt") if min_training_cnt is not None and min_training_cnt != "": data_check["min_training_cnt_error"] = "" if re.compile("^[+]?\\d+$").match(min_training_cnt) is None: error_data += 1 data_check["min_training_cnt_error"] = page_settings[ "invalid_cnt_error"] else: if int(min_training_cnt) <= 0 or int( min_training_cnt) < int( page_settings["min_training_cnt_setting"]): error_data += 1 data_check["min_training_cnt_error"] = page_settings["invalid_training_cnt_error"] + \ page_settings["min_training_cnt_setting"] else: error_data += 1 detection_api = parameter_dict.get("detection_api") if detection_api is not None and detection_api != "": data_check["detection_api_ip_error"] = "" if re.compile( "^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$" ).match(detection_api) is None: error_data += 1 data_check["feature_api_ip_error"] = page_settings[ "empty_error"] else: error_data += 1 feature_api = parameter_dict.get("feature_api") if feature_api is not None and feature_api != "": data_check["feature_api_ip_error"] = "" if re.compile( "^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$" ).match(feature_api) is None: error_data += 1 data_check["feature_api_ip_error"] = page_settings[ "empty_error"] else: error_data += 1 pkl_update_api = parameter_dict.get("pkl_update_api") if pkl_update_api is not None and pkl_update_api != "": data_check["pkl_update_api_ip_error"] = "" if re.compile( "^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$" ).match(pkl_update_api) is None: error_data += 1 data_check["pkl_update_api_ip_error"] = page_settings[ "empty_error"] self.return_value["data"] = data_check if error_data == 0: detection_real_api = str( detection_api) + self.detection_api_suffix feature_real_api = str(feature_api) + self.feature_api_suffix pkl_update_real_api = None if pkl_update_api is not None and pkl_update_api != "": pkl_update_real_api = str( pkl_update_api) + self.pkl_update_api_suffix if vcms_db_agent._add_company_service_data( company_sn, per_product_image_cnt, service_sn, max_product_cnt, min_training_cnt, detection_real_api, feature_real_api, pkl_update_real_api) > 0: self.return_value["data"] = self.get_company_service_list( page_settings, int(company_sn)) self.return_value["message"] = page_settings[ "success_text"] self.return_value["code"] = 1 return self.return_value