|pypi| |actions| |codecov| |downloads|
edc-model-wrapper
-----------------
Wrap a model instance with a custom wrapper to add methods needed for Edc Dashboards and Listboards.
.. code-block:: python
class ExampleModelWrapper(ModelWrapper):
model = 'edc_model_wrapper.example'
next_url_name = 'edc-model-wrapper:listboard_url'
next_url_attrs = ['f1']
querystring_attrs = ['f2', 'f3']
def hello(self):
return 'hello'
def goodbye(self):
return 'goodbye'
Instantiate with a model instance, persisted or not:
.. code-block:: python
model_obj = Example(f1=1, f2=2, f3=3)
wrapper = ExampleExampleModelWrapper(model_obj=model_obj)
Get the "admin" url with "next" for model objects in a Listboard, Dabsboard, etc,
.. code-block:: python
>>> wrapper.href
'/admin/edc_model_wrapper/example/add/?next=edc-model-wrapper:listboard_url,f1&f1=1&f2=2&f3=3'
Get the admin url without the "next" querystring data:
.. code-block:: python
>>> wrapper.admin_url_name
'/admin/edc_model_wrapper/example/add/'
Reverse the next_url:
.. code-block:: python
>>> wrapper.reverse()
'/listboard/1/'
Attribute `model` is a model class regardless of how it was declared:
.. code-block:: python
>>> assert wrapper.model == Example
True
All field attributes are converted to string and added to the wrapper, except foreign keys:
.. code-block:: python
>>> wrapper.f1
1
>>> wrapper.f2
2
Custom methods/properties are, of course, available:
.. code-block:: python
>>> wrapper.hello()
'hello'
>>> wrapper.goodbye()
'goodbye'
The original object is accessible, if needed:
.. code-block:: python
>>> wrapper.object
<Example>
for example to access original field values:
.. code-block:: python
>>> wrapper.report_datetime
'2017-06-01 15:04:41.760296'
>>> wrapper.object.report_datetime
datetime.datetime(2017, 6, 1, 15, 4, 55, 594512)
.. |pypi| image:: https://img.shields.io/pypi/v/edc-model-wrapper.svg
:target: https://pypi.python.org/pypi/edc-model-wrapper
.. |actions| image:: https://github.com/clinicedc/edc-model-wrapper/actions/workflows/build.yml/badge.svg
:target: https://github.com/clinicedc/edc-model-wrapper/actions/workflows/build.yml
.. |codecov| image:: https://codecov.io/gh/clinicedc/edc-model-wrapper/branch/develop/graph/badge.svg
:target: https://codecov.io/gh/clinicedc/edc-model-wrapper
.. |downloads| image:: https://pepy.tech/badge/edc-model-wrapper
:target: https://pepy.tech/project/edc-model-wrapper
Raw data
{
"_id": null,
"home_page": "https://github.com/clinicedc/edc-model-wrapper",
"name": "edc-model-wrapper",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "",
"keywords": "django model wrapper dashboard edc clinicedc clinical trials",
"author": "Erik van Widenfelt",
"author_email": "ew2789@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c6/f0/1cc317e9e4bfe38d8fb91df4a9cbe0b96f7a57678ef37965bd2a6ee58345/edc-model-wrapper-0.3.13.tar.gz",
"platform": null,
"description": "|pypi| |actions| |codecov| |downloads|\n\n\nedc-model-wrapper\n-----------------\n\nWrap a model instance with a custom wrapper to add methods needed for Edc Dashboards and Listboards.\n\n.. code-block:: python\n\n class ExampleModelWrapper(ModelWrapper):\n model = 'edc_model_wrapper.example'\n next_url_name = 'edc-model-wrapper:listboard_url'\n next_url_attrs = ['f1']\n querystring_attrs = ['f2', 'f3']\n\n def hello(self):\n return 'hello'\n\n def goodbye(self):\n return 'goodbye'\n\nInstantiate with a model instance, persisted or not:\n\n.. code-block:: python\n\n model_obj = Example(f1=1, f2=2, f3=3)\n wrapper = ExampleExampleModelWrapper(model_obj=model_obj)\n\nGet the \"admin\" url with \"next\" for model objects in a Listboard, Dabsboard, etc,\n\n.. code-block:: python\n\n >>> wrapper.href\n '/admin/edc_model_wrapper/example/add/?next=edc-model-wrapper:listboard_url,f1&f1=1&f2=2&f3=3'\n\nGet the admin url without the \"next\" querystring data:\n\n.. code-block:: python\n\n >>> wrapper.admin_url_name\n '/admin/edc_model_wrapper/example/add/'\n\nReverse the next_url:\n\n.. code-block:: python\n\n >>> wrapper.reverse()\n '/listboard/1/'\n\n\nAttribute `model` is a model class regardless of how it was declared:\n\n.. code-block:: python\n\n >>> assert wrapper.model == Example\n True\n\n\nAll field attributes are converted to string and added to the wrapper, except foreign keys:\n\n.. code-block:: python\n\n >>> wrapper.f1\n 1\n >>> wrapper.f2\n 2\n\n\nCustom methods/properties are, of course, available:\n\n.. code-block:: python\n\n >>> wrapper.hello()\n 'hello'\n >>> wrapper.goodbye()\n 'goodbye'\n\n\nThe original object is accessible, if needed:\n\n.. code-block:: python\n\n >>> wrapper.object\n <Example>\n\nfor example to access original field values:\n\n.. code-block:: python\n\n >>> wrapper.report_datetime\n '2017-06-01 15:04:41.760296'\n\n >>> wrapper.object.report_datetime\n datetime.datetime(2017, 6, 1, 15, 4, 55, 594512)\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/edc-model-wrapper.svg\n :target: https://pypi.python.org/pypi/edc-model-wrapper\n\n.. |actions| image:: https://github.com/clinicedc/edc-model-wrapper/actions/workflows/build.yml/badge.svg\n :target: https://github.com/clinicedc/edc-model-wrapper/actions/workflows/build.yml\n\n.. |codecov| image:: https://codecov.io/gh/clinicedc/edc-model-wrapper/branch/develop/graph/badge.svg\n :target: https://codecov.io/gh/clinicedc/edc-model-wrapper\n\n.. |downloads| image:: https://pepy.tech/badge/edc-model-wrapper\n :target: https://pepy.tech/project/edc-model-wrapper\n",
"bugtrack_url": null,
"license": "GPL license, see LICENSE",
"summary": "Model wrappers that add dashboard methods for clinicedc/edc projects",
"version": "0.3.13",
"project_urls": {
"Homepage": "https://github.com/clinicedc/edc-model-wrapper"
},
"split_keywords": [
"django",
"model",
"wrapper",
"dashboard",
"edc",
"clinicedc",
"clinical",
"trials"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "22bdffbaf446646ea3395c6373d4a0a705c615269f56775d84f198bf3c05889d",
"md5": "1e3eda0d42cee8464c8a25c670409140",
"sha256": "5746650d2d3f187cb891366679216d88e56b23b480d887f4814db707b2359d19"
},
"downloads": -1,
"filename": "edc_model_wrapper-0.3.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1e3eda0d42cee8464c8a25c670409140",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 36241,
"upload_time": "2024-01-06T15:30:51",
"upload_time_iso_8601": "2024-01-06T15:30:51.289620Z",
"url": "https://files.pythonhosted.org/packages/22/bd/ffbaf446646ea3395c6373d4a0a705c615269f56775d84f198bf3c05889d/edc_model_wrapper-0.3.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c6f01cc317e9e4bfe38d8fb91df4a9cbe0b96f7a57678ef37965bd2a6ee58345",
"md5": "2db6a5f0049b2a9f994708c6705ca4ec",
"sha256": "ab3c9efe54f720cb5c9075eac0e0d3746641569688e3a494d5b483fea09566c7"
},
"downloads": -1,
"filename": "edc-model-wrapper-0.3.13.tar.gz",
"has_sig": false,
"md5_digest": "2db6a5f0049b2a9f994708c6705ca4ec",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 34621,
"upload_time": "2024-01-06T15:30:53",
"upload_time_iso_8601": "2024-01-06T15:30:53.200634Z",
"url": "https://files.pythonhosted.org/packages/c6/f0/1cc317e9e4bfe38d8fb91df4a9cbe0b96f7a57678ef37965bd2a6ee58345/edc-model-wrapper-0.3.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-06 15:30:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "clinicedc",
"github_project": "edc-model-wrapper",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "edc-model-wrapper"
}