Skip to main content

Model wrappers that add dashboard methods for clinicedc/edc projects

Project description

pypi actions codecov downloads


Wrap a model instance with a custom wrapper to add methods needed for Edc Dashboards and Listboards.

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:

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,

>>> wrapper.href

Get the admin url without the “next” querystring data:

>>> wrapper.admin_url_name

Reverse the next_url:

>>> wrapper.reverse()

Attribute model is a model class regardless of how it was declared:

>>> assert wrapper.model == Example

All field attributes are converted to string and added to the wrapper, except foreign keys:

>>> wrapper.f1
>>> wrapper.f2

Custom methods/properties are, of course, available:

>>> wrapper.hello()
>>> wrapper.goodbye()

The original object is accessible, if needed:

>>> wrapper.object

for example to access original field values:

>>> wrapper.report_datetime
'2017-06-01 15:04:41.760296'

>>> wrapper.object.report_datetime
datetime.datetime(2017, 6, 1, 15, 4, 55, 594512)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edc-model-wrapper-0.3.10.tar.gz (34.9 kB view hashes)

Uploaded source

Built Distribution

edc_model_wrapper-0.3.10-py3-none-any.whl (36.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page