Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edc-model-wrapper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edc-model-wrapper

Model wrappers that add dashboard methods for clinicedc/edc projects

  • 0.3.13
  • PyPI
  • Socket score

Maintainers
1

|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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc