Skip to main content

install_requires

m-singleton==0.3 
pymongo==3.7.2
requests>=2.32.4
unidecode==1.1.1
mobio-elasticsearch7==1.0.1

Description

Version 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ính
  1. BaseHistory
  2. BaseDataSelected
  3. BaseField

Examples

  • BaseHistory
from mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseHistory
from datetime import datetime

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")
print(field_history.to_json())

Hoặc extend

from mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseHistory
from datetime import datetime
class ProfilingFieldHistory(BaseHistory):
    LAST_PREVIEW = "last_preview"

    def set_last_preview(self, last_preview: datetime):
        self.result[self.LAST_PREVIEW] = last_preview

    def get_last_preview(self):
        return self.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())
  • BaseDataSelected
from mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseDataSelected

data_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 extend

from mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseDataSelected

class ProfilingDataSelectedTest(BaseDataSelected):
    IMAGE = "image"

    def set_image(self, image: str):
        if not image or (3 > len(image) or len(image) > 1000):
            raise Exception(
                "{}: must be between 3 and 1000 in length".format(self.IMAGE)
            )
        self.result[self.IMAGE] = image

    def get_image(self):
        return self.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")
  • BaseField

BaseField 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 field

from mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseField, BaseDataSelected, BaseHistory
from flask import request
from mobio.libs.dynamic_field.helpers import (
    DynamicFieldStatus
)
from datetime import datetime
from mobio.libs.dynamic_field.controllers.i_base_dyn_controller import (
    IBaseDynController,
)


json_data = request.get_json() 

# SET FIELD PROPERTIES
dyn_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 HISTORY
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")
# SAVE TO DB and push ELS mapping. This function can detect add/update field 
IBaseDynController(
            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 field

from mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseHistory
from datetime import datetime
from mobio.libs.dynamic_field.controllers.i_base_dyn_controller import (
    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 = df

Change logs

  • 0.2.12

    • Chuyển đổi thư viện elasticsearch7 sang thư viện mobio-elasticsearch7 để pass scan trivy
  • 0.2.11

    • Cập nhật thư viện elasticsearch từ version7 lên version8 (Không install thư viện này, có lỗi)
  • 0.2.9

    • Thêm index cho thuộc tính field mới
  • 0.2.8

    • Thay đổi thuộc tính field là tiền tệ sang 88
  • 0.2.7

    • Thêm thuộc tính field là tiền tệ
  • 0.2.6

    • upgrade requests library
  • 0.2.5.1

    1. fix issue remove doc_type
    2. fix issue missing after_token
  • 0.2.5

    1. remove doc_type
  • 0.2.4

    1. upgrade elasticsearch_client to 7.17.4
  • 0.2.3

    1. remove flask, flask-cors in install_requires
  • 0.2.2

    1. Everything can be extend
    2. Logging field change model
  • 0.1.3

    1. remove some print
    2. fix create mapping integer to long
  • 0.1.2

    1. fix missing model elastic
  • 0.1.1

    1. add singleton to ElasticSearchBaseModel
  • 0.1.0

    1. use elastic base model
    2. change function args add_els_config
     def add_els_config(self, index, doc_type):
         self.index = index
         self.doc_type = doc_type
     

Metadata

Release files for dyn-libs 0.2.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dyn-libs 0.2.12
File Size Uploaded Provenance
dyn_libs-0.2.12.tar.gz 20.6 kB Without provenance Details

Release files / dyn_libs-0.2.12.tar.gz

Download URL dyn_libs-0.2.12.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
86e85e8fe8a1cc8b8c508af9890c2a8fc214ee8c17b931b13e86c1f429f04053
BLAKE2b-256 checksum
How to use checksums
136a108a073cff9833d53a4e90d9b25f23f8da755c54f0d25377f01082beb435
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.7

Security for dyn-libs 0.2.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page