Model wrappers that add dashboard methods for clinic/edc.
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
Hashes for edc-model-wrapper-0.1.11.macosx-10.13-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aad80f03781454f7baecd3afbff03caebc58c11dbfded46a4d1354b5108e52f4 |
|
MD5 | d76f391d3fa5a7e2b4533fd76588d54e |
|
BLAKE2b-256 | b8f65d524dd426ee1265e489cbd1b812d0a26d78ba09bfa53d233e61e3934460 |
Hashes for edc_model_wrapper-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56356a7993e2ca72791fa9ae62bca4a798f867cd52825c76d8bdb41f2648049c |
|
MD5 | 575afca57958ce771588e479af2c056f |
|
BLAKE2b-256 | 36e2e5e9ced236bb9f01ba14fdee739ac367f6d5191adee88f0742d833c5a0eb |