Example #1
0
 def get_bind_service_account_list(self, page_settings, user_sn=0):
     self.__reset_return_value()
     html = ""
     page_settings["user_sn"] = user_sn
     page_settings["bind_service_tab"] = 12
     if int(user_sn) > 0:
         vcms_db_agent = VcmsDbAgent()
         user_info = vcms_db_agent._get_account_data(int(user_sn))
         page_settings["company_sn"] = int(user_info["company_sn"])
         company_service_info = vcms_db_agent._get_company_service_data(
             int(user_info["company_sn"]))
         user_service_info = vcms_db_agent._get_user_service_data(
             int(user_sn))
         enabled_service = {}
         for k1, v1 in user_service_info.items():
             if int(v1["enabled"]) == 1:
                 enabled_service[int(v1["company_service_sn"])] = v1
         for k1, v1 in company_service_info.items():
             if k1 in enabled_service:
                 company_service_info[k1]["user_enabled"] = 1
             else:
                 company_service_info[k1]["user_enabled"] = 0
         page_settings["company_service_list"] = company_service_info
         html = render_template("tab_ui/vcms_bind_service_account.tpl",
                                data=page_settings)
     return html
Example #2
0
 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
Example #3
0
 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
Example #4
0
 def set_bind_service_account(self, page_settings, parameter_dict):
     self.__reset_return_value()
     data_check = {"service_sn_1_error": page_settings["empty_cnt_error"]}
     company_sn = parameter_dict.get("company_sn")
     user_sn = parameter_dict.get("user_sn")
     error_data = 0
     vcms_db_agent = VcmsDbAgent()
     if company_sn is not None and company_sn != "":
         data_check["service_sn_1_error"] = ""
         if re.compile("^[0-9]*$").match(company_sn) is None:
             error_data += 1
             data_check["service_sn_1_error"] = page_settings[
                 "invalid_company_sn_error"]
         else:
             company_info = vcms_db_agent._get_all_company_data()
             if int(company_sn) not in company_info:
                 error_data += 1
                 data_check["service_sn_1_error"] = page_settings[
                     "empty_company_sn_error"]
     else:
         error_data += 1
         data_check["service_sn_1_error"] = page_settings[
             "company_sn_error"]
     if user_sn is not None and user_sn != "":
         if re.compile("^[\d]*$").match(user_sn) is None:
             error_data += 1
             data_check["service_sn_1_error"] = page_settings[
                 "user_sn_format_error"]
         else:
             user_info = vcms_db_agent._get_account_data(user_sn)
             if "admin_id" not in user_info:
                 error_data += 1
                 data_check["service_sn_1_error"] = page_settings[
                     "none_user_sn_error"]
             else:
                 company_sn = int(user_info["company_sn"])
     else:
         error_data += 1
     self.return_value["data"] = data_check
     if error_data == 0:
         if "company_service_sn" in parameter_dict:
             company_service_info = vcms_db_agent._get_company_service_data(
                 int(company_sn))
             user_permission = vcms_db_agent._get_user_service_data(
                 int(user_sn))
             user_permission_list = {}
             for k, v in user_permission.items():
                 user_permission_list[int(v["company_service_sn"])] = v
             vcms_db_agent._upd_all_user_service_permission_data(
                 int(user_sn), 0)
             for row in parameter_dict.getlist("company_service_sn"):
                 if int(row) in user_permission_list:
                     vcms_db_agent._upd_user_service_permission_data(
                         int(user_sn), int(row), 1)
                 else:
                     service_sn = company_service_info[int(
                         row)]["service_sn"]
                     vcms_db_agent._add_user_service_permission_data(
                         int(company_sn), int(user_sn), int(row),
                         int(service_sn))
         else:
             vcms_db_agent._upd_all_user_service_permission_data(
                 int(user_sn), 0)
         self.return_value["data"] = self.get_bind_service_account_list(
             page_settings, int(user_sn))
         self.return_value["message"] = page_settings["success_text"]
         self.return_value["code"] = 1
     return self.return_value
Example #5
0
 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