Model wrappers that add dashboard methods for clinicedc/edc projects
Project description
edc-model-wrapper
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
'/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:
>>> wrapper.admin_url_name
'/admin/edc_model_wrapper/example/add/'
Reverse the next_url:
>>> wrapper.reverse()
'/listboard/1/'
Attribute model is a model class regardless of how it was declared:
>>> assert wrapper.model == Example
True
All field attributes are converted to string and added to the wrapper, except foreign keys:
>>> wrapper.f1
1
>>> wrapper.f2
2
Custom methods/properties are, of course, available:
>>> wrapper.hello()
'hello'
>>> wrapper.goodbye()
'goodbye'
The original object is accessible, if needed:
>>> wrapper.object
<Example>
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file edc-model-wrapper-0.3.13.tar.gz.
File metadata
- Download URL: edc-model-wrapper-0.3.13.tar.gz
- Upload date:
- Size: 34.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab3c9efe54f720cb5c9075eac0e0d3746641569688e3a494d5b483fea09566c7
|
|
| MD5 |
2db6a5f0049b2a9f994708c6705ca4ec
|
|
| BLAKE2b-256 |
c6f01cc317e9e4bfe38d8fb91df4a9cbe0b96f7a57678ef37965bd2a6ee58345
|
File details
Details for the file edc_model_wrapper-0.3.13-py3-none-any.whl.
File metadata
- Download URL: edc_model_wrapper-0.3.13-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5746650d2d3f187cb891366679216d88e56b23b480d887f4814db707b2359d19
|
|
| MD5 |
1e3eda0d42cee8464c8a25c670409140
|
|
| BLAKE2b-256 |
22bdffbaf446646ea3395c6373d4a0a705c615269f56775d84f198bf3c05889d
|