Metadata-Version: 2.1
Name: edc-model-wrapper
Version: 0.3.8
Summary: Model wrappers that add dashboard methods for clinicedc/edc projects
Home-page: https://github.com/clinicedc/edc-model-wrapper
Author: Erik van Widenfelt
Author-email: ew2789@gmail.com
License: GPL license, see LICENSE
Keywords: django model wrapper dashboard edc clinicedc clinical trials
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Requires-Python: >=3.9
Description-Content-Type: text/x-rst
License-File: LICENSE
License-File: AUTHORS

|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/workflows/build/badge.svg?branch=develop
  :target: https://github.com/clinicedc/edc-model-wrapper/actions?query=workflow:build

.. |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
