You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: forms/data-sources.md
+15-7
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
For `Choice` and `MultipleChoice` questions it's sometimes necessary to populate the choices with calculated data or data from external sources.
4
4
5
-
For this you can use the data\_source extension point.
5
+
For this you can use the data_source extension point.
6
6
7
-
An example data\_source looks like this:
7
+
An example data_source looks like this:
8
8
9
9
```python
10
10
from caluma.caluma_data_source.data_sources import BaseDataSource
@@ -26,8 +26,8 @@ This class needs also to be added to the `DATA_SOURCE_CLASSES` environment varia
26
26
27
27
### Properties
28
28
29
-
*`info`: Descriptive text for the data source (can also be a multilingual dict)
30
-
*`default`: The default value to be returned if execution of `get_data()` fails. If this is `None`, the Exception won't be handled. Defaults to `None`.
29
+
-`info`: Descriptive text for the data source (can also be a multilingual dict)
30
+
-`default`: The default value to be returned if execution of `get_data()` fails. If this is `None`, the Exception won't be handled. Defaults to `None`.
31
31
32
32
### `get_data`-method
33
33
@@ -37,11 +37,19 @@ For the label, it's possible to use a dict with translated values.
37
37
38
38
Note: If the labels returned from`get_data()` depend on the current user's language, you need to return a `dict` with the language code as keys instead of translating the value yourself. Returning already translated values is not supported, as it would break caching and validation.
39
39
40
+
### `on_copy`-method
41
+
42
+
When a an answer of type TYPE_DYNAMIC_CHOICE or TYPE_DYNAMIC_MULTIPLE_CHOICE gets copied the meaning of the slug and label of the dynamic option could potentially be changed when the datasource it's data changes. During the answer copy process the linked datasource it's on_copy method will be called to decide the desired result.
43
+
44
+
- return the same slug,label tuple to not perform any change (default behavior)
45
+
- return an altered slug or(/and) label to change the answer value
46
+
- return a None value for the slug, to discard the answer value
47
+
40
48
#### Arguments
41
49
42
-
*`user`: The OIDC user object for the request
43
-
*`question`: The question on which the data source was called upon. Defaults to `None` if the data source was called outside of question context.
44
-
*`context`: A `dict` containing additional information from the frontend. Defaults to `None`. This can be used to pass application specific information (such as the current case for example) to the data sources. To use it in the frontend, pass the needed data into the `@context` argument of the `<CfContent />` component.
50
+
-`user`: The OIDC user object for the request
51
+
-`question`: The question on which the data source was called upon. Defaults to `None` if the data source was called outside of question context.
52
+
-`context`: A `dict` containing additional information from the frontend. Defaults to `None`. This can be used to pass application specific information (such as the current case for example) to the data sources. To use it in the frontend, pass the needed data into the `@context` argument of the `<CfContent />` component.
0 commit comments