dyn-libs


Namedyn-libs JSON
Version 0.2.10 PyPI version JSON
download
home_pagehttps://github.com/mobiovn
SummaryMobio Dynamic Fields
upload_time2024-04-11 13:48:09
maintainerNone
docs_urlNone
authorMOBIO
requires_python>=3
licenseMIT
keywords mobio dyn_libs
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # install_requires
<pre>
m-singleton==0.3 
pymongo==3.7.2
requests==2.25.1
unidecode==1.1.1
elasticsearch==7.17.4
</pre>
# 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

```python
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

```python
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
```python
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

```python
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
```python
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
```python
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.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 <b>add_els_config</b>
    <pre>
    def add_els_config(self, index, doc_type):
        self.index = index
        self.doc_type = doc_type
    </pre>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mobiovn",
    "name": "dyn-libs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": null,
    "keywords": "mobio, dyn_libs",
    "author": "MOBIO",
    "author_email": "contact@mobio.vn",
    "download_url": "https://files.pythonhosted.org/packages/4e/80/4498406d19c0e249ac8207b0b2a69ddfba48f8c7f7a460a35ba812cf2296/dyn_libs-0.2.10.tar.gz",
    "platform": null,
    "description": "# install_requires\n<pre>\nm-singleton==0.3 \npymongo==3.7.2\nrequests==2.25.1\nunidecode==1.1.1\nelasticsearch==7.17.4\n</pre>\n# Description\nVersion 0.2.x h\u1ed7 tr\u1ee3 vi\u1ec7c t\u1ea1o, ch\u1ec9nh s\u1eeda, x\u00f3a dynamic field. B\u1ea1n c\u00f3 th\u1ec3 ch\u1ee7 \u0111\u1ed9ng extend l\u1ea1i c\u00e1c BaseClass v\u00e0 th\u00eam c\u00e1c gi\u00e1 tr\u1ecb.\n\n* Ki\u1ebfn tr\u00fac ch\u00ednh c\u1ee7a dynamic field  g\u1ed3m 3 class ch\u00ednh\n\n1) BaseHistory\n2) BaseDataSelected\n3) BaseField\n\n# Examples\n\n* BaseHistory\n\n```python\nfrom mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseHistory\nfrom datetime import datetime\n\nfield_history = BaseHistory()\nfield_history.set_staff_id(\"GiangNTH\")\nfield_history.set_created_time(datetime.utcnow())\nfield_history.set_fullname(\"GiangNTH\")\nfield_history.set_username(\"giangnth\")\nprint(field_history.to_json())\n```\nHo\u1eb7c extend\n\n```python\nfrom mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseHistory\nfrom datetime import datetime\nclass ProfilingFieldHistory(BaseHistory):\n    LAST_PREVIEW = \"last_preview\"\n\n    def set_last_preview(self, last_preview: datetime):\n        self.result[self.LAST_PREVIEW] = last_preview\n\n    def get_last_preview(self):\n        return self.result.get(self.LAST_PREVIEW)\n\nfield_history = ProfilingFieldHistory()\nfield_history.set_staff_id(\"GiangNTH\")\nfield_history.set_created_time(datetime.utcnow())\nfield_history.set_fullname(\"GiangNTH\")\nfield_history.set_username(\"giangnth\")\nfield_history.set_last_preview(datetime.utcnow())\nprint(field_history.to_json())\n```\n* BaseDataSelected\n```python\nfrom mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseDataSelected\n\ndata_1 = BaseDataSelected()\ndata_1.set_id(1)\ndata_1.set_color(\"c1\")\ndata_1.set_enable(True)\ndata_1.set_value(\"value 1\")\nprint(data_1.to_json())\n```\nHo\u1eb7c extend\n\n```python\nfrom mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseDataSelected\n\nclass ProfilingDataSelectedTest(BaseDataSelected):\n    IMAGE = \"image\"\n\n    def set_image(self, image: str):\n        if not image or (3 > len(image) or len(image) > 1000):\n            raise Exception(\n                \"{}: must be between 3 and 1000 in length\".format(self.IMAGE)\n            )\n        self.result[self.IMAGE] = image\n\n    def get_image(self):\n        return self.result.get(self.IMAGE)\n\ndata_1 = ProfilingDataSelectedTest()\ndata_1.set_id(1)\ndata_1.set_color(\"c1\")\ndata_1.set_image(\"image1\")\ndata_1.set_enable(True)\ndata_1.set_value(\"value 1\")\n\ndata_2 = ProfilingDataSelectedTest()\ndata_2.set_all_data(id=2, image=\"image2\", enable=False, value=\"value 2\", color=\"c2\")\n```\n\n* BaseField\n\nBaseField class ch\u1ee9a c\u00e1c configs c\u1ee7a field, vd nh\u01b0 c\u1ea5u h\u00ecnh m\u00e0n h\u00ecnh hi\u1ec3n th\u1ecb, \u0111\u1ecbnh d\u1ea1ng d\u1eef li\u1ec7u, nh\u00f3m hi\u1ec3n th\u1ecb c\u1ee7a field... etc\nNote: Field c\u0169ng c\u00f3 th\u1ec3 extend. :)\n    \nVD: \n>> add/update field\n```python\nfrom mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseField, BaseDataSelected, BaseHistory\nfrom flask import request\nfrom mobio.libs.dynamic_field.helpers import (\n    DynamicFieldStatus\n)\nfrom datetime import datetime\nfrom mobio.libs.dynamic_field.controllers.i_base_dyn_controller import (\n    IBaseDynController,\n)\n\n\njson_data = request.get_json() \n\n# SET FIELD PROPERTIES\ndyn_field = BaseField()\ndyn_field.set_field_name(json_data.get(BaseField.FIELD_NAME))\ndyn_field.set_field_property(json_data.get(BaseField.FIELD_PROPERTY))\ndyn_field.set_display_type(json_data.get(BaseField.DISPLAY_TYPE))\ndyn_field.set_group(json_data.get(BaseField.GROUP))\ndyn_field.set_is_base(False)\ndyn_field.set_status(DynamicFieldStatus.ENABLE)\ndyn_field.set_support_sort(True)\ndyn_field.set_enable_data_color(json_data.get(BaseField.ENABLE_DATA_COLOR))\n\ndata_1 = BaseDataSelected()\ndata_1.set_id(1)\ndata_1.set_color(\"c1\")\ndata_1.set_enable(True)\ndata_1.set_value(\"value 1\")\ndyn_field.set_data_selected([data_1])\n\n# SET FIELD HISTORY\nfield_history = BaseHistory()\nfield_history.set_staff_id(\"GiangNTH\")\nfield_history.set_created_time(datetime.utcnow())\nfield_history.set_fullname(\"GiangNTH\")\nfield_history.set_username(\"giangnth\")\n# SAVE TO DB and push ELS mapping. This function can detect add/update field \nIBaseDynController(\n            mongo_url_connection=\"mongodb://test_user:test_pass@0.0.0.0:27017/test_db\"\n        ).save_field(\n            merchant_id=\"uuid\",\n            field_class=dyn_field,\n            updated_by=field_history,\n            els_index=\"mobio-profiling\",\n        )\n```\n\n>> Remove field\n```python\nfrom mobio.libs.dynamic_field.helpers.field_helper.base_field import BaseHistory\nfrom datetime import datetime\nfrom mobio.libs.dynamic_field.controllers.i_base_dyn_controller import (\n    IBaseDynController,\n)\n\nfield_key = \"_dyn_giang_test_v2_p2_1645462060103\"\nfield_history = BaseHistory()\nfield_history.set_staff_id(\"GiangNTH\")\nfield_history.set_created_time(datetime.utcnow())\nfield_history.set_fullname(\"GiangNTH\")\nfield_history.set_username(\"giangnth\")\n\nresult = IBaseDynController(\n    mongo_url_connection=\"mongodb://test_user:test_pass@0.0.0.0:27017/test_db\"\n).remove_field(\n    merchant_id=\"uuid\",\n    field_key=field_key,\n    updated_by=field_history,\n)\nprint(\"result remove field: {}: {}\".format(field_key, result))\n```\n\n# Example config\n```\n[Elastic]\nindex = dyn_test\ndoc_type = df\n```\n\n\n# Change logs\n* 0.2.9\n    - Th\u00eam index cho thu\u1ed9c t\u00ednh field m\u1edbi\n* 0.2.8\n    - Thay \u0111\u1ed5i thu\u1ed9c t\u00ednh field l\u00e0 ti\u1ec1n t\u1ec7 sang 88 \n* 0.2.7\n    - Th\u00eam thu\u1ed9c t\u00ednh field l\u00e0 ti\u1ec1n t\u1ec7 \n\n* 0.2.6\n    - upgrade requests library\n* 0.2.5.1\n    1) fix issue remove doc_type\n    2) fix issue missing after_token\n* 0.2.5\n    1) remove doc_type\n* 0.2.4\n    1) upgrade elasticsearch_client to 7.17.4\n* 0.2.3\n    1) remove flask, flask-cors in install_requires\n* 0.2.2\n    1) Everything can be extend\n    2) Logging field change model\n* 0.1.3\n    1) remove some print\n    2) fix create mapping integer to long\n* 0.1.2\n    1) fix missing model elastic\n*  0.1.1\n    1) add singleton to ElasticSearchBaseModel\n\n*  0.1.0\n    1) use elastic base model\n    2) change function args <b>add_els_config</b>\n    <pre>\n    def add_els_config(self, index, doc_type):\n        self.index = index\n        self.doc_type = doc_type\n    </pre>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Mobio Dynamic Fields",
    "version": "0.2.10",
    "project_urls": {
        "Homepage": "https://github.com/mobiovn",
        "Source": "https://github.com/mobiovn"
    },
    "split_keywords": [
        "mobio",
        " dyn_libs"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e804498406d19c0e249ac8207b0b2a69ddfba48f8c7f7a460a35ba812cf2296",
                "md5": "4a89eef1da96bf7a075f73338a2500f1",
                "sha256": "38c0e022971820a8deca683c39f35ee1356d307169f2ce1faabe68e33bdfffad"
            },
            "downloads": -1,
            "filename": "dyn_libs-0.2.10.tar.gz",
            "has_sig": false,
            "md5_digest": "4a89eef1da96bf7a075f73338a2500f1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 20371,
            "upload_time": "2024-04-11T13:48:09",
            "upload_time_iso_8601": "2024-04-11T13:48:09.249768Z",
            "url": "https://files.pythonhosted.org/packages/4e/80/4498406d19c0e249ac8207b0b2a69ddfba48f8c7f7a460a35ba812cf2296/dyn_libs-0.2.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-11 13:48:09",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "dyn-libs"
}
        
Elapsed time: 4.86072s