Package: dyn-libs
install_requiresm-singleton==0.3 
pymongo==3.7.2
requests==2.25.1
unidecode==1.1.1
elasticsearch==7.17.4DescriptionVersion 0.2.x hỗ trợ việc tạo, chỉnh sửa, xóa dynamic field. Bạn có thể chủ động extend lại các BaseClass và thêm các giá trị.Kiến trúc chính của dynamic field  gồm 3 class chínhBaseHistoryBaseDataSelectedBaseFieldExamplesBaseHistoryfrommobio.libs.dynamic_field.helpers.field_helper.base_fieldimportBaseHistoryfromdatetimeimportdatetimefield_history=BaseHistory()field_history.set_staff_id("GiangNTH")field_history.set_created_time(datetime.utcnow())field_history.set_fullname("GiangNTH")field_history.set_username("giangnth")print(field_history.to_json())Hoặc extendfrommobio.libs.dynamic_field.helpers.field_helper.base_fieldimportBaseHistoryfromdatetimeimportdatetimeclassProfilingFieldHistory(BaseHistory):LAST_PREVIEW="last_preview"defset_last_preview(self,last_preview:datetime):self.result[self.LAST_PREVIEW]=last_previewdefget_last_preview(self):returnself.result.get(self.LAST_PREVIEW)field_history=ProfilingFieldHistory()field_history.set_staff_id("GiangNTH")field_history.set_created_time(datetime.utcnow())field_history.set_fullname("GiangNTH")field_history.set_username("giangnth")field_history.set_last_preview(datetime.utcnow())print(field_history.to_json())BaseDataSelectedfrommobio.libs.dynamic_field.helpers.field_helper.base_fieldimportBaseDataSelecteddata_1=BaseDataSelected()data_1.set_id(1)data_1.set_color("c1")data_1.set_enable(True)data_1.set_value("value 1")print(data_1.to_json())Hoặc extendfrommobio.libs.dynamic_field.helpers.field_helper.base_fieldimportBaseDataSelectedclassProfilingDataSelectedTest(BaseDataSelected):IMAGE="image"defset_image(self,image:str):ifnotimageor(3>len(image)orlen(image)>1000):raiseException("{}: must be between 3 and 1000 in length".format(self.IMAGE))self.result[self.IMAGE]=imagedefget_image(self):returnself.result.get(self.IMAGE)data_1=ProfilingDataSelectedTest()data_1.set_id(1)data_1.set_color("c1")data_1.set_image("image1")data_1.set_enable(True)data_1.set_value("value 1")data_2=ProfilingDataSelectedTest()data_2.set_all_data(id=2,image="image2",enable=False,value="value 2",color="c2")BaseFieldBaseField class chứa các configs của field, vd như cấu hình màn hình hiển thị, định dạng dữ liệu, nhóm hiển thị của field... etc
Note: Field cũng có thể extend. :)VD:add/update fieldfrommobio.libs.dynamic_field.helpers.field_helper.base_fieldimportBaseField,BaseDataSelected,BaseHistoryfromflaskimportrequestfrommobio.libs.dynamic_field.helpersimport(DynamicFieldStatus)fromdatetimeimportdatetimefrommobio.libs.dynamic_field.controllers.i_base_dyn_controllerimport(IBaseDynController,)json_data=request.get_json()# SET FIELD PROPERTIESdyn_field=BaseField()dyn_field.set_field_name(json_data.get(BaseField.FIELD_NAME))dyn_field.set_field_property(json_data.get(BaseField.FIELD_PROPERTY))dyn_field.set_display_type(json_data.get(BaseField.DISPLAY_TYPE))dyn_field.set_group(json_data.get(BaseField.GROUP))dyn_field.set_is_base(False)dyn_field.set_status(DynamicFieldStatus.ENABLE)dyn_field.set_support_sort(True)dyn_field.set_enable_data_color(json_data.get(BaseField.ENABLE_DATA_COLOR))data_1=BaseDataSelected()data_1.set_id(1)data_1.set_color("c1")data_1.set_enable(True)data_1.set_value("value 1")dyn_field.set_data_selected([data_1])# SET FIELD HISTORYfield_history=BaseHistory()field_history.set_staff_id("GiangNTH")field_history.set_created_time(datetime.utcnow())field_history.set_fullname("GiangNTH")field_history.set_username("giangnth")# SAVE TO DB and push ELS mapping. This function can detect add/update fieldIBaseDynController(mongo_url_connection="mongodb://test_user:test_pass@0.0.0.0:27017/test_db").save_field(merchant_id="uuid",field_class=dyn_field,updated_by=field_history,els_index="mobio-profiling",)Remove fieldfrommobio.libs.dynamic_field.helpers.field_helper.base_fieldimportBaseHistoryfromdatetimeimportdatetimefrommobio.libs.dynamic_field.controllers.i_base_dyn_controllerimport(IBaseDynController,)field_key="_dyn_giang_test_v2_p2_1645462060103"field_history=BaseHistory()field_history.set_staff_id("GiangNTH")field_history.set_created_time(datetime.utcnow())field_history.set_fullname("GiangNTH")field_history.set_username("giangnth")result=IBaseDynController(mongo_url_connection="mongodb://test_user:test_pass@0.0.0.0:27017/test_db").remove_field(merchant_id="uuid",field_key=field_key,updated_by=field_history,)print("result remove field:{}:{}".format(field_key,result))Example config[Elastic]
index = dyn_test
doc_type = dfChange logs0.2.9Thêm index cho thuộc tính field mới0.2.8Thay đổi thuộc tính field là tiền tệ sang 880.2.7Thêm thuộc tính field là tiền tệ0.2.6upgrade requests library0.2.5.1fix issue remove doc_typefix issue missing after_token0.2.5remove doc_type0.2.4upgrade elasticsearch_client to 7.17.40.2.3remove flask, flask-cors in install_requires0.2.2Everything can be extendLogging field change model0.1.3remove some printfix create mapping integer to long0.1.2fix missing model elastic0.1.1add singleton to ElasticSearchBaseModel0.1.0use elastic base modelchange function argsadd_els_configdef add_els_config(self, index, doc_type):
     self.index = index
     self.doc_type = doc_type