squirrels 0.2.1__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of squirrels might be problematic. Click here for more details.
- squirrels/__init__.py +11 -4
- squirrels/_api_response_models.py +118 -0
- squirrels/_api_server.py +140 -75
- squirrels/_authenticator.py +10 -8
- squirrels/_command_line.py +17 -11
- squirrels/_connection_set.py +2 -2
- squirrels/_constants.py +13 -5
- squirrels/_initializer.py +23 -13
- squirrels/_manifest.py +20 -10
- squirrels/_models.py +303 -148
- squirrels/_parameter_configs.py +195 -57
- squirrels/_parameter_sets.py +14 -17
- squirrels/_py_module.py +2 -4
- squirrels/_seeds.py +38 -0
- squirrels/_utils.py +41 -33
- squirrels/arguments/run_time_args.py +76 -34
- squirrels/data_sources.py +172 -51
- squirrels/dateutils.py +3 -3
- squirrels/package_data/assets/index.js +14 -14
- squirrels/package_data/base_project/connections.yml +1 -1
- squirrels/package_data/base_project/database/expenses.db +0 -0
- squirrels/package_data/base_project/docker/Dockerfile +1 -1
- squirrels/package_data/base_project/environcfg.yml +7 -7
- squirrels/package_data/base_project/models/dbviews/database_view1.py +25 -14
- squirrels/package_data/base_project/models/dbviews/database_view1.sql +21 -14
- squirrels/package_data/base_project/models/federates/dataset_example.py +6 -5
- squirrels/package_data/base_project/models/federates/dataset_example.sql +1 -1
- squirrels/package_data/base_project/parameters.yml +57 -28
- squirrels/package_data/base_project/pyconfigs/auth.py +11 -10
- squirrels/package_data/base_project/pyconfigs/connections.py +6 -8
- squirrels/package_data/base_project/pyconfigs/context.py +49 -33
- squirrels/package_data/base_project/pyconfigs/parameters.py +62 -30
- squirrels/package_data/base_project/seeds/seed_categories.csv +6 -0
- squirrels/package_data/base_project/seeds/seed_subcategories.csv +15 -0
- squirrels/package_data/base_project/squirrels.yml.j2 +37 -20
- squirrels/parameter_options.py +30 -10
- squirrels/parameters.py +300 -70
- squirrels/user_base.py +3 -13
- squirrels-0.3.0.dist-info/LICENSE +201 -0
- {squirrels-0.2.1.dist-info → squirrels-0.3.0.dist-info}/METADATA +15 -15
- squirrels-0.3.0.dist-info/RECORD +56 -0
- {squirrels-0.2.1.dist-info → squirrels-0.3.0.dist-info}/WHEEL +1 -1
- squirrels/package_data/base_project/seeds/mocks/category.csv +0 -3
- squirrels/package_data/base_project/seeds/mocks/max_filter.csv +0 -2
- squirrels/package_data/base_project/seeds/mocks/subcategory.csv +0 -6
- squirrels-0.2.1.dist-info/LICENSE +0 -22
- squirrels-0.2.1.dist-info/RECORD +0 -55
- {squirrels-0.2.1.dist-info → squirrels-0.3.0.dist-info}/entry_points.txt +0 -0
squirrels/parameters.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
from typing import Type, Sequence, Optional, Union, Any
|
|
2
|
+
from typing import Callable, Type, Sequence, Optional, Union, Any
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from datetime import datetime, date
|
|
5
5
|
from decimal import Decimal
|
|
6
6
|
from abc import ABCMeta, abstractmethod
|
|
7
7
|
|
|
8
|
-
from . import _parameter_configs as pc, _parameter_sets as ps, parameter_options as po, data_sources as d
|
|
8
|
+
from . import _parameter_configs as pc, _parameter_sets as ps, parameter_options as po, data_sources as d
|
|
9
|
+
from . import _api_response_models as arm, _utils as u
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
@dataclass
|
|
@@ -15,6 +16,10 @@ class Parameter(metaclass=ABCMeta):
|
|
|
15
16
|
"""
|
|
16
17
|
_config: pc.ParameterConfig
|
|
17
18
|
|
|
19
|
+
@abstractmethod
|
|
20
|
+
def is_enabled(self) -> bool:
|
|
21
|
+
return True
|
|
22
|
+
|
|
18
23
|
@staticmethod
|
|
19
24
|
@abstractmethod
|
|
20
25
|
def _ParameterConfigType() -> Type:
|
|
@@ -22,7 +27,7 @@ class Parameter(metaclass=ABCMeta):
|
|
|
22
27
|
|
|
23
28
|
@classmethod
|
|
24
29
|
def Create(
|
|
25
|
-
cls, name: str, label: str, all_options: Sequence[Union[po.ParameterOption, dict]], *,
|
|
30
|
+
cls, name: str, label: str, all_options: Sequence[Union[po.ParameterOption, dict]], *, description: str = "",
|
|
26
31
|
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
27
32
|
) -> None:
|
|
28
33
|
"""
|
|
@@ -32,38 +37,38 @@ class Parameter(metaclass=ABCMeta):
|
|
|
32
37
|
name: The name of the parameter
|
|
33
38
|
label: The display label for the parameter
|
|
34
39
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
35
|
-
|
|
40
|
+
description: Explains the meaning of the parameter
|
|
36
41
|
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
37
42
|
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
38
43
|
"""
|
|
39
44
|
param_config_type = cls._ParameterConfigType()
|
|
40
|
-
param_config = param_config_type(name, label, all_options,
|
|
45
|
+
param_config = param_config_type(name, label, all_options, description=description, user_attribute=user_attribute,
|
|
41
46
|
parent_name=parent_name)
|
|
42
47
|
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
43
48
|
|
|
44
49
|
@classmethod
|
|
45
50
|
@abstractmethod
|
|
46
|
-
def CreateSimple(cls, name: str, label: str, *args,
|
|
51
|
+
def CreateSimple(cls, name: str, label: str, *args, description: str = "", **kwargs) -> None:
|
|
47
52
|
pass
|
|
48
53
|
|
|
49
54
|
@classmethod
|
|
50
55
|
def CreateFromSource(
|
|
51
|
-
cls, name: str, label: str, data_source: Union[d.DataSource , dict], *,
|
|
56
|
+
cls, name: str, label: str, data_source: Union[d.DataSource , dict], *, description: str = "",
|
|
52
57
|
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
53
58
|
) -> None:
|
|
54
59
|
"""
|
|
55
|
-
Method for creating the configurations for any Parameter that uses a DataSource to
|
|
60
|
+
Method for creating the configurations for any Parameter that uses a DataSource to receive the options
|
|
56
61
|
|
|
57
62
|
Parameters:
|
|
58
63
|
name: The name of the parameter
|
|
59
64
|
label: The display label for the parameter
|
|
60
65
|
data_source: The lookup table to use for this parameter
|
|
61
|
-
|
|
66
|
+
description: Explains the meaning of the parameter
|
|
62
67
|
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
63
68
|
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
64
69
|
"""
|
|
65
70
|
param_config_type = cls._ParameterConfigType()
|
|
66
|
-
param_config = pc.DataSourceParameterConfig(param_config_type, name, label, data_source,
|
|
71
|
+
param_config = pc.DataSourceParameterConfig(param_config_type, name, label, data_source, description=description,
|
|
67
72
|
user_attribute=user_attribute, parent_name=parent_name)
|
|
68
73
|
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
69
74
|
|
|
@@ -87,7 +92,17 @@ class Parameter(metaclass=ABCMeta):
|
|
|
87
92
|
"""
|
|
88
93
|
Helper method to convert the derived Parameter class into a JSON dictionary
|
|
89
94
|
"""
|
|
90
|
-
|
|
95
|
+
output = self._config.to_json_dict0()
|
|
96
|
+
if not self.is_enabled():
|
|
97
|
+
output["widget_type"] = "disabled"
|
|
98
|
+
return output
|
|
99
|
+
|
|
100
|
+
@abstractmethod
|
|
101
|
+
def _get_response_model0(self) -> type[arm.ParameterModelBase]:
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
def _to_api_response_model0(self) -> arm.ParameterModel:
|
|
105
|
+
return self._get_response_model0().model_validate(self.to_json_dict0())
|
|
91
106
|
|
|
92
107
|
|
|
93
108
|
@dataclass
|
|
@@ -98,6 +113,9 @@ class _SelectionParameter(Parameter):
|
|
|
98
113
|
def __post_init__(self):
|
|
99
114
|
self._options = tuple(self._options)
|
|
100
115
|
|
|
116
|
+
def is_enabled(self) -> bool:
|
|
117
|
+
return len(self._options) > 0
|
|
118
|
+
|
|
101
119
|
@abstractmethod
|
|
102
120
|
def _get_selected_ids_as_list(self) -> Sequence[str]:
|
|
103
121
|
pass
|
|
@@ -107,7 +125,7 @@ class _SelectionParameter(Parameter):
|
|
|
107
125
|
self._config._raise_invalid_input_error(selected_id, f"The selected id {selected_id} does not exist in available options.")
|
|
108
126
|
|
|
109
127
|
@abstractmethod
|
|
110
|
-
def to_json_dict0(self):
|
|
128
|
+
def to_json_dict0(self) -> dict:
|
|
111
129
|
"""
|
|
112
130
|
Helper method to convert the derived selection parameter class into a JSON object
|
|
113
131
|
"""
|
|
@@ -143,7 +161,7 @@ class SingleSelectParameter(_SelectionParameter):
|
|
|
143
161
|
|
|
144
162
|
@classmethod
|
|
145
163
|
def CreateSimple(
|
|
146
|
-
cls, name: str, label: str, all_options: Sequence[po.SelectParameterOption], *,
|
|
164
|
+
cls, name: str, label: str, all_options: Sequence[po.SelectParameterOption], *, description: str = "", **kwargs
|
|
147
165
|
) -> None:
|
|
148
166
|
"""
|
|
149
167
|
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
@@ -152,9 +170,9 @@ class SingleSelectParameter(_SelectionParameter):
|
|
|
152
170
|
name: The name of the parameter
|
|
153
171
|
label: The display label for the parameter
|
|
154
172
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
155
|
-
|
|
173
|
+
description: Explains the meaning of the parameter
|
|
156
174
|
"""
|
|
157
|
-
cls.Create(name, label, all_options,
|
|
175
|
+
cls.Create(name, label, all_options, description=description)
|
|
158
176
|
|
|
159
177
|
def get_selected(
|
|
160
178
|
self, field: Optional[str] = None, *, default_field: Optional[str] = None, default: Any = None, **kwargs
|
|
@@ -235,6 +253,9 @@ class SingleSelectParameter(_SelectionParameter):
|
|
|
235
253
|
output = super().to_json_dict0()
|
|
236
254
|
output['selected_id'] = self._selected_id
|
|
237
255
|
return output
|
|
256
|
+
|
|
257
|
+
def _get_response_model0(self):
|
|
258
|
+
return arm.SingleSelectParameterModel
|
|
238
259
|
|
|
239
260
|
|
|
240
261
|
@dataclass
|
|
@@ -262,55 +283,85 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
262
283
|
|
|
263
284
|
@classmethod
|
|
264
285
|
def Create(
|
|
265
|
-
cls, name: str, label: str, all_options: Sequence[Union[po.SelectParameterOption, dict]], *,
|
|
266
|
-
|
|
286
|
+
cls, name: str, label: str, all_options: Sequence[Union[po.SelectParameterOption, dict]], *, description: str = "",
|
|
287
|
+
show_select_all: bool = True, is_dropdown: bool = True, order_matters: bool = False, none_is_all: bool = True,
|
|
267
288
|
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
268
289
|
) -> None:
|
|
269
290
|
"""
|
|
270
|
-
Method for creating the configurations for a
|
|
291
|
+
Method for creating the configurations for a MultiSelectParameter that may include user attribute or parent
|
|
271
292
|
|
|
272
293
|
Parameters:
|
|
273
294
|
name: The name of the parameter
|
|
274
295
|
label: The display label for the parameter
|
|
275
296
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
297
|
+
description: Explains the meaning of the parameter
|
|
276
298
|
show_select_all: Communicate to front-end whether to include a "select all" option
|
|
277
299
|
is_dropdown: Communicate to front-end whether the widget should be a dropdown with checkboxes
|
|
278
300
|
order_matters: Communicate to front-end whether the order of the selections made matter
|
|
279
301
|
none_is_all: Whether having no options selected is equivalent to all selectable options selected
|
|
280
|
-
is_hidden: Whether the parameter is hidden in the parameters API response. Default is False
|
|
281
302
|
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
282
303
|
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
283
304
|
"""
|
|
284
305
|
param_config = pc.MultiSelectParameterConfig(
|
|
285
306
|
name, label, all_options,
|
|
286
307
|
show_select_all=show_select_all, is_dropdown=is_dropdown, order_matters=order_matters, none_is_all=none_is_all,
|
|
287
|
-
|
|
308
|
+
description=description, user_attribute=user_attribute, parent_name=parent_name
|
|
288
309
|
)
|
|
289
310
|
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
290
311
|
|
|
291
312
|
@classmethod
|
|
292
313
|
def CreateSimple(
|
|
293
|
-
cls, name: str, label: str, all_options: Sequence[po.SelectParameterOption], *,
|
|
294
|
-
|
|
314
|
+
cls, name: str, label: str, all_options: Sequence[po.SelectParameterOption], *, description: str = "",
|
|
315
|
+
show_select_all: bool = True, is_dropdown: bool = True, order_matters: bool = False, none_is_all: bool = True, **kwargs
|
|
295
316
|
) -> None:
|
|
296
317
|
"""
|
|
297
|
-
Method for creating the configurations for a
|
|
318
|
+
Method for creating the configurations for a MultiSelectParameter that doesn't involve user attributes or parent parameters
|
|
298
319
|
|
|
299
320
|
Parameters:
|
|
300
321
|
name: The name of the parameter
|
|
301
322
|
label: The display label for the parameter
|
|
302
323
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
324
|
+
description: Explains the meaning of the parameter
|
|
303
325
|
show_select_all: Communicate to front-end whether to include a "select all" option
|
|
304
326
|
is_dropdown: Communicate to front-end whether the widget should be a dropdown with checkboxes
|
|
305
327
|
order_matters: Communicate to front-end whether the order of the selections made matter
|
|
306
328
|
none_is_all: Whether having no options selected is equivalent to all selectable options selected
|
|
307
|
-
is_hidden: Whether the parameter is hidden in the parameters API response. Default is False
|
|
308
329
|
"""
|
|
309
330
|
cls.Create(
|
|
310
|
-
name, label, all_options,
|
|
311
|
-
show_select_all=show_select_all, s_dropdown=is_dropdown, order_matters=order_matters, none_is_all=none_is_all
|
|
312
|
-
|
|
331
|
+
name, label, all_options, description=description,
|
|
332
|
+
show_select_all=show_select_all, s_dropdown=is_dropdown, order_matters=order_matters, none_is_all=none_is_all
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
@classmethod
|
|
336
|
+
def CreateFromSource(
|
|
337
|
+
cls, name: str, label: str, data_source: Union[d.SelectDataSource, dict], *, description: str = "",
|
|
338
|
+
show_select_all: bool = True, is_dropdown: bool = True, order_matters: bool = False, none_is_all: bool = True,
|
|
339
|
+
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
340
|
+
) -> None:
|
|
341
|
+
"""
|
|
342
|
+
Method for creating the configurations for a MultiSelectParameter that uses a SelectDataSource to receive the options
|
|
343
|
+
|
|
344
|
+
Parameters:
|
|
345
|
+
name: The name of the parameter
|
|
346
|
+
label: The display label for the parameter
|
|
347
|
+
data_source: The lookup table to use for this parameter
|
|
348
|
+
description: Explains the meaning of the parameter
|
|
349
|
+
show_select_all: Communicate to front-end whether to include a "select all" option
|
|
350
|
+
is_dropdown: Communicate to front-end whether the widget should be a dropdown with checkboxes
|
|
351
|
+
order_matters: Communicate to front-end whether the order of the selections made matter
|
|
352
|
+
none_is_all: Whether having no options selected is equivalent to all selectable options selected
|
|
353
|
+
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
354
|
+
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
355
|
+
"""
|
|
356
|
+
extra_args = {
|
|
357
|
+
"show_select_all": show_select_all, "is_dropdown": is_dropdown,
|
|
358
|
+
"order_matters": order_matters, "none_is_all": none_is_all
|
|
359
|
+
}
|
|
360
|
+
param_config = pc.DataSourceParameterConfig(
|
|
361
|
+
pc.MultiSelectParameterConfig, name, label, data_source, extra_args=extra_args, description=description,
|
|
362
|
+
user_attribute=user_attribute, parent_name=parent_name
|
|
313
363
|
)
|
|
364
|
+
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
314
365
|
|
|
315
366
|
def has_non_empty_selection(self) -> bool:
|
|
316
367
|
"""
|
|
@@ -436,6 +487,9 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
436
487
|
output = super().to_json_dict0()
|
|
437
488
|
output['selected_ids'] = list(self._selected_ids)
|
|
438
489
|
return output
|
|
490
|
+
|
|
491
|
+
def _get_response_model0(self):
|
|
492
|
+
return arm.MultiSelectParameterModel
|
|
439
493
|
|
|
440
494
|
|
|
441
495
|
@dataclass
|
|
@@ -448,19 +502,23 @@ class DateParameter(Parameter):
|
|
|
448
502
|
curr_option: The current option showing for defaults based on user attribute and selection of parent
|
|
449
503
|
selected_date: The selected date
|
|
450
504
|
"""
|
|
451
|
-
_curr_option: po.DateParameterOption
|
|
505
|
+
_curr_option: Optional[po.DateParameterOption]
|
|
452
506
|
_selected_date: Union[date, str]
|
|
453
507
|
|
|
454
508
|
def __post_init__(self):
|
|
455
509
|
self._selected_date: date = self._validate_date(self._selected_date)
|
|
456
510
|
|
|
511
|
+
def is_enabled(self) -> bool:
|
|
512
|
+
return self._curr_option is not None
|
|
513
|
+
|
|
457
514
|
@staticmethod
|
|
458
515
|
def _ParameterConfigType():
|
|
459
516
|
return pc.DateParameterConfig
|
|
460
517
|
|
|
461
518
|
@classmethod
|
|
462
519
|
def CreateSimple(
|
|
463
|
-
cls, name: str, label: str, default_date: Union[str, date], *,
|
|
520
|
+
cls, name: str, label: str, default_date: Union[str, date], *, description: str = "",
|
|
521
|
+
date_format: str = '%Y-%m-%d', **kwargs
|
|
464
522
|
) -> None:
|
|
465
523
|
"""
|
|
466
524
|
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
@@ -469,11 +527,11 @@ class DateParameter(Parameter):
|
|
|
469
527
|
name: The name of the parameter
|
|
470
528
|
label: The display label for the parameter
|
|
471
529
|
default_date: Default date for this option
|
|
530
|
+
description: Explains the meaning of the parameter
|
|
472
531
|
date_format: Format of the default date, default is '%Y-%m-%d'
|
|
473
|
-
is_hidden: Whether the parameter is hidden in the parameters API response. Default is False
|
|
474
532
|
"""
|
|
475
533
|
single_param_option = po.DateParameterOption(default_date, date_format=date_format)
|
|
476
|
-
cls.Create(name, label, (single_param_option,),
|
|
534
|
+
cls.Create(name, label, (single_param_option,), description=description)
|
|
477
535
|
|
|
478
536
|
def get_selected_date(self, *, date_format: str = None, **kwargs) -> str:
|
|
479
537
|
"""
|
|
@@ -510,9 +568,14 @@ class DateParameter(Parameter):
|
|
|
510
568
|
A dictionary for the JSON object
|
|
511
569
|
"""
|
|
512
570
|
output = super().to_json_dict0()
|
|
513
|
-
|
|
514
|
-
|
|
571
|
+
if self.is_enabled():
|
|
572
|
+
output["selected_date"] = self.get_selected_date(date_format="%Y-%m-%d")
|
|
573
|
+
else:
|
|
574
|
+
output["selected_date"] = ""
|
|
515
575
|
return output
|
|
576
|
+
|
|
577
|
+
def _get_response_model0(self):
|
|
578
|
+
return arm.DateParameterModel if self.is_enabled() else arm.ParameterModelBase
|
|
516
579
|
|
|
517
580
|
|
|
518
581
|
@dataclass
|
|
@@ -526,7 +589,7 @@ class DateRangeParameter(Parameter):
|
|
|
526
589
|
selected_start_date: The selected start date
|
|
527
590
|
selected_end_date: The selected end date
|
|
528
591
|
"""
|
|
529
|
-
_curr_option: po.DateRangeParameterOption
|
|
592
|
+
_curr_option: Optional[po.DateRangeParameterOption]
|
|
530
593
|
_selected_start_date: Union[date, str]
|
|
531
594
|
_selected_end_date: Union[date, str]
|
|
532
595
|
|
|
@@ -534,14 +597,17 @@ class DateRangeParameter(Parameter):
|
|
|
534
597
|
self._selected_start_date: date = self._validate_date(self._selected_start_date)
|
|
535
598
|
self._selected_end_date: date = self._validate_date(self._selected_end_date)
|
|
536
599
|
|
|
600
|
+
def is_enabled(self) -> bool:
|
|
601
|
+
return self._curr_option is not None
|
|
602
|
+
|
|
537
603
|
@staticmethod
|
|
538
604
|
def _ParameterConfigType():
|
|
539
605
|
return pc.DateRangeParameterConfig
|
|
540
606
|
|
|
541
607
|
@classmethod
|
|
542
608
|
def CreateSimple(
|
|
543
|
-
cls, name: str, label: str, default_start_date: Union[str, date], default_end_date: Union[str, date],
|
|
544
|
-
|
|
609
|
+
cls, name: str, label: str, default_start_date: Union[str, date], default_end_date: Union[str, date], *,
|
|
610
|
+
description: str = "", date_format: str = '%Y-%m-%d', **kwargs
|
|
545
611
|
) -> None:
|
|
546
612
|
"""
|
|
547
613
|
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
@@ -551,11 +617,11 @@ class DateRangeParameter(Parameter):
|
|
|
551
617
|
label: The display label for the parameter
|
|
552
618
|
default_start_date: Default start date for this option
|
|
553
619
|
default_end_date: Default end date for this option
|
|
620
|
+
description: Explains the meaning of the parameter
|
|
554
621
|
date_format: Format of the default date, default is '%Y-%m-%d'
|
|
555
|
-
is_hidden: Whether the parameter is hidden in the parameters API response. Default is False
|
|
556
622
|
"""
|
|
557
623
|
single_param_option = po.DateRangeParameterOption(default_start_date, default_end_date, date_format=date_format)
|
|
558
|
-
cls.Create(name, label, (single_param_option,),
|
|
624
|
+
cls.Create(name, label, (single_param_option,), description=description)
|
|
559
625
|
|
|
560
626
|
def get_selected_start_date(self, *, date_format: str = None, **kwargs) -> str:
|
|
561
627
|
"""
|
|
@@ -617,10 +683,13 @@ class DateRangeParameter(Parameter):
|
|
|
617
683
|
A dictionary for the JSON object
|
|
618
684
|
"""
|
|
619
685
|
output = super().to_json_dict0()
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
686
|
+
if self.is_enabled():
|
|
687
|
+
output["selected_start_date"] = self.get_selected_start_date(date_format="%Y-%m-%d")
|
|
688
|
+
output["selected_end_date"] = self.get_selected_end_date(date_format="%Y-%m-%d")
|
|
623
689
|
return output
|
|
690
|
+
|
|
691
|
+
def _get_response_model0(self):
|
|
692
|
+
return arm.DateRangeParameterModel if self.is_enabled() else arm.ParameterModelBase
|
|
624
693
|
|
|
625
694
|
|
|
626
695
|
@dataclass
|
|
@@ -633,20 +702,23 @@ class NumberParameter(Parameter):
|
|
|
633
702
|
curr_option: The current option showing for defaults based on user attribute and selection of parent
|
|
634
703
|
selected_value: The selected integer or decimal number
|
|
635
704
|
"""
|
|
636
|
-
_curr_option: po.NumberParameterOption
|
|
705
|
+
_curr_option: Optional[po.NumberParameterOption]
|
|
637
706
|
_selected_value: po.Number
|
|
638
707
|
|
|
639
708
|
def __post_init__(self):
|
|
640
709
|
self._selected_value: Decimal = self._validate_number(self._selected_value, self._curr_option)
|
|
641
710
|
|
|
711
|
+
def is_enabled(self) -> bool:
|
|
712
|
+
return self._curr_option is not None
|
|
713
|
+
|
|
642
714
|
@staticmethod
|
|
643
715
|
def _ParameterConfigType():
|
|
644
716
|
return pc.NumberParameterConfig
|
|
645
717
|
|
|
646
718
|
@classmethod
|
|
647
719
|
def CreateSimple(
|
|
648
|
-
cls, name: str, label: str, min_value: po.Number, max_value: po.Number, *,
|
|
649
|
-
|
|
720
|
+
cls, name: str, label: str, min_value: po.Number, max_value: po.Number, *, description: str = "",
|
|
721
|
+
increment: po.Number = 1, default_value: Optional[po.Number] = None, **kwargs
|
|
650
722
|
) -> None:
|
|
651
723
|
"""
|
|
652
724
|
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
@@ -658,21 +730,21 @@ class NumberParameter(Parameter):
|
|
|
658
730
|
label: The display label for the parameter
|
|
659
731
|
min_value: Minimum selectable value
|
|
660
732
|
max_value: Maximum selectable value
|
|
733
|
+
description: Explains the meaning of the parameter
|
|
661
734
|
increment: Increment of selectable values, and must fit evenly between min_value and max_value
|
|
662
735
|
default_value: Default value for this option, and must be selectable based on min_value, max_value, and increment
|
|
663
|
-
is_hidden: Whether the parameter is hidden in the parameters API response. Default is False
|
|
664
736
|
"""
|
|
665
737
|
single_param_option = po.NumberParameterOption(min_value, max_value, increment=increment, default_value=default_value)
|
|
666
|
-
cls.Create(name, label, (single_param_option,),
|
|
738
|
+
cls.Create(name, label, (single_param_option,), description=description)
|
|
667
739
|
|
|
668
|
-
def get_selected_value(self, **kwargs) ->
|
|
740
|
+
def get_selected_value(self, **kwargs) -> float:
|
|
669
741
|
"""
|
|
670
|
-
Get the selected number
|
|
742
|
+
Get the selected number (converted from Decimal to float)
|
|
671
743
|
|
|
672
744
|
Returns:
|
|
673
|
-
|
|
745
|
+
float
|
|
674
746
|
"""
|
|
675
|
-
return
|
|
747
|
+
return float(self._selected_value)
|
|
676
748
|
|
|
677
749
|
def to_json_dict0(self):
|
|
678
750
|
"""
|
|
@@ -682,9 +754,13 @@ class NumberParameter(Parameter):
|
|
|
682
754
|
A dictionary for the JSON object
|
|
683
755
|
"""
|
|
684
756
|
output = super().to_json_dict0()
|
|
685
|
-
|
|
686
|
-
|
|
757
|
+
if self.is_enabled():
|
|
758
|
+
output.update(self._curr_option._to_json_dict())
|
|
759
|
+
output["selected_value"] = self.get_selected_value()
|
|
687
760
|
return output
|
|
761
|
+
|
|
762
|
+
def _get_response_model0(self):
|
|
763
|
+
return arm.NumberParameterModel if self.is_enabled() else arm.ParameterModelBase
|
|
688
764
|
|
|
689
765
|
|
|
690
766
|
@dataclass
|
|
@@ -698,7 +774,7 @@ class NumberRangeParameter(Parameter):
|
|
|
698
774
|
selected_lower_value: The selected lower integer or decimal number
|
|
699
775
|
selected_upper_value: The selected upper integer or decimal number
|
|
700
776
|
"""
|
|
701
|
-
_curr_option: po.NumberRangeParameterOption
|
|
777
|
+
_curr_option: Optional[po.NumberRangeParameterOption]
|
|
702
778
|
_selected_lower_value: po.Number
|
|
703
779
|
_selected_upper_value: po.Number
|
|
704
780
|
|
|
@@ -706,14 +782,18 @@ class NumberRangeParameter(Parameter):
|
|
|
706
782
|
self._selected_lower_value: Decimal = self._validate_number(self._selected_lower_value, self._curr_option)
|
|
707
783
|
self._selected_upper_value: Decimal = self._validate_number(self._selected_upper_value, self._curr_option)
|
|
708
784
|
|
|
785
|
+
def is_enabled(self) -> bool:
|
|
786
|
+
return self._curr_option is not None
|
|
787
|
+
|
|
709
788
|
@staticmethod
|
|
710
789
|
def _ParameterConfigType():
|
|
711
790
|
return pc.NumberRangeParameterConfig
|
|
712
791
|
|
|
713
792
|
@classmethod
|
|
714
793
|
def CreateSimple(
|
|
715
|
-
cls, name: str, label: str, min_value: po.Number, max_value: po.Number, *,
|
|
716
|
-
|
|
794
|
+
cls, name: str, label: str, min_value: po.Number, max_value: po.Number, *, description: str = "",
|
|
795
|
+
increment: po.Number = 1, default_lower_value: Optional[po.Number] = None, default_upper_value: Optional[po.Number] = None,
|
|
796
|
+
**kwargs
|
|
717
797
|
) -> None:
|
|
718
798
|
"""
|
|
719
799
|
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
@@ -725,34 +805,182 @@ class NumberRangeParameter(Parameter):
|
|
|
725
805
|
label: The display label for the parameter
|
|
726
806
|
min_value: Minimum selectable value
|
|
727
807
|
max_value: Maximum selectable value
|
|
808
|
+
description: Explains the meaning of the parameter
|
|
728
809
|
increment: Increment of selectable values, and must fit evenly between min_value and max_value
|
|
729
810
|
default_lower_value: Default lower value for this option, and must be selectable based on min_value, max_value, and increment
|
|
730
811
|
default_upper_value: Default upper value for this option, and must be selectable based on min_value, max_value, and increment.
|
|
731
812
|
Must also be greater than default_lower_value
|
|
732
|
-
is_hidden: Whether the parameter is hidden in the parameters API response. Default is False
|
|
733
813
|
"""
|
|
734
|
-
single_param_option = po.NumberRangeParameterOption(
|
|
735
|
-
|
|
736
|
-
|
|
814
|
+
single_param_option = po.NumberRangeParameterOption(
|
|
815
|
+
min_value, max_value, increment=increment, default_lower_value=default_lower_value, default_upper_value=default_upper_value
|
|
816
|
+
)
|
|
817
|
+
cls.Create(name, label, (single_param_option,), description=description)
|
|
737
818
|
|
|
738
|
-
def get_selected_lower_value(self, **kwargs) ->
|
|
819
|
+
def get_selected_lower_value(self, **kwargs) -> float:
|
|
739
820
|
"""
|
|
740
|
-
Get the selected lower value number
|
|
821
|
+
Get the selected lower value number (converted from Decimal to float)
|
|
741
822
|
|
|
742
823
|
Returns:
|
|
743
|
-
|
|
824
|
+
float
|
|
744
825
|
"""
|
|
745
|
-
return
|
|
826
|
+
return float(self._selected_lower_value)
|
|
746
827
|
|
|
747
|
-
def get_selected_upper_value(self, **kwargs) ->
|
|
828
|
+
def get_selected_upper_value(self, **kwargs) -> float:
|
|
748
829
|
"""
|
|
749
|
-
Get the selected upper value number
|
|
830
|
+
Get the selected upper value number (converted from Decimal to float)
|
|
750
831
|
|
|
751
832
|
Returns:
|
|
752
|
-
|
|
833
|
+
float
|
|
834
|
+
"""
|
|
835
|
+
return float(self._selected_upper_value)
|
|
836
|
+
|
|
837
|
+
def to_json_dict0(self):
|
|
838
|
+
"""
|
|
839
|
+
Converts this parameter as a JSON object for the parameters API response
|
|
840
|
+
|
|
841
|
+
Returns:
|
|
842
|
+
A dictionary for the JSON object
|
|
843
|
+
"""
|
|
844
|
+
output = super().to_json_dict0()
|
|
845
|
+
if self._curr_option is not None:
|
|
846
|
+
output.update(self._curr_option._to_json_dict())
|
|
847
|
+
output['selected_lower_value'] = self.get_selected_lower_value()
|
|
848
|
+
output['selected_upper_value'] = self.get_selected_upper_value()
|
|
849
|
+
return output
|
|
850
|
+
|
|
851
|
+
def _get_response_model0(self):
|
|
852
|
+
return arm.NumberRangeParameterModel if self.is_enabled() else arm.ParameterModelBase
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
@dataclass
|
|
856
|
+
class _TextValue:
|
|
857
|
+
_value_do_not_touch: str
|
|
858
|
+
|
|
859
|
+
def __repr__(self):
|
|
860
|
+
raise u.ConfigurationError(
|
|
861
|
+
"Cannot convert the entered text of TextParameter directly to string type. Try using it through placeholders instead"
|
|
862
|
+
)
|
|
863
|
+
|
|
864
|
+
def apply(self, str_to_str_function: Callable[[str], str]) -> _TextValue:
|
|
865
|
+
"""
|
|
866
|
+
Transforms the entered text with a function that takes a string and returns a string.
|
|
867
|
+
|
|
868
|
+
This method returns a new object and leaves the original the same.
|
|
869
|
+
|
|
870
|
+
Parameters:
|
|
871
|
+
str_to_str_function: A function that accepts a string and returns a string
|
|
872
|
+
|
|
873
|
+
Returns:
|
|
874
|
+
A new TextValue with the transformed entered text
|
|
875
|
+
"""
|
|
876
|
+
new_value = str_to_str_function(self._value_do_not_touch)
|
|
877
|
+
assert isinstance(new_value, str), "Function provided must return string"
|
|
878
|
+
return _TextValue(new_value)
|
|
879
|
+
|
|
880
|
+
def apply_percent_wrap(self) -> _TextValue:
|
|
881
|
+
"""
|
|
882
|
+
Adds percent signs before and after the entered text, and returns a new object, leaving the original the same.
|
|
883
|
+
|
|
884
|
+
Returns:
|
|
885
|
+
A new TextValue with the transformed entered text
|
|
886
|
+
"""
|
|
887
|
+
return self.apply(lambda x: "%"+x+"%")
|
|
888
|
+
|
|
889
|
+
def apply_as_bool(self, str_to_bool_function: Callable[[str], bool]) -> bool:
|
|
890
|
+
"""
|
|
891
|
+
Transforms the entered text with a function that takes a string and returns a boolean.
|
|
892
|
+
|
|
893
|
+
Parameters:
|
|
894
|
+
str_to_bool_function: A function that accepts a string and returns a boolean.
|
|
895
|
+
|
|
896
|
+
Returns:
|
|
897
|
+
A boolean for the transformed value
|
|
898
|
+
"""
|
|
899
|
+
new_value = str_to_bool_function(self._value_do_not_touch)
|
|
900
|
+
assert isinstance(new_value, bool), "Function provided must return bool"
|
|
901
|
+
return new_value
|
|
902
|
+
|
|
903
|
+
def apply_as_number(self, str_to_num_function: Callable[[str], Union[int, float]]) -> Union[int, float]:
|
|
904
|
+
"""
|
|
905
|
+
Transforms the entered text with a function that takes a string and returns an int or float.
|
|
906
|
+
|
|
907
|
+
Parameters:
|
|
908
|
+
str_to_num_function: A function that accepts a string and returns an int or float.
|
|
909
|
+
|
|
910
|
+
Returns:
|
|
911
|
+
An int or float for the transformed value
|
|
912
|
+
"""
|
|
913
|
+
new_value = str_to_num_function(self._value_do_not_touch)
|
|
914
|
+
assert isinstance(new_value, (int, float)), "Function provided must return a number"
|
|
915
|
+
return new_value
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
@dataclass
|
|
919
|
+
class TextParameter(Parameter):
|
|
920
|
+
"""
|
|
921
|
+
Class for text parameter widgets.
|
|
922
|
+
"""
|
|
923
|
+
_curr_option: Optional[po.TextParameterOption]
|
|
924
|
+
_entered_text: str
|
|
925
|
+
|
|
926
|
+
def is_enabled(self) -> bool:
|
|
927
|
+
return self._curr_option is not None
|
|
928
|
+
|
|
929
|
+
@staticmethod
|
|
930
|
+
def _ParameterConfigType():
|
|
931
|
+
return pc.TextParameterConfig
|
|
932
|
+
|
|
933
|
+
@classmethod
|
|
934
|
+
def Create(
|
|
935
|
+
cls, name: str, label: str, all_options: Sequence[Union[po.TextParameterOption, dict]], *, description: str = "",
|
|
936
|
+
is_textarea: bool = False, user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
937
|
+
) -> None:
|
|
938
|
+
"""
|
|
939
|
+
Method for creating the configurations for a MultiSelectParameter that may include user attribute or parent
|
|
940
|
+
|
|
941
|
+
Parameters:
|
|
942
|
+
name: The name of the parameter
|
|
943
|
+
label: The display label for the parameter
|
|
944
|
+
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
945
|
+
description: Explains the meaning of the parameter
|
|
946
|
+
is_textarea: Whether the textbox field should be big. Optional, default is False.
|
|
947
|
+
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
948
|
+
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
949
|
+
"""
|
|
950
|
+
param_config = pc.TextParameterConfig(
|
|
951
|
+
name, label, all_options, description=description, is_textarea=is_textarea, user_attribute=user_attribute,
|
|
952
|
+
parent_name=parent_name
|
|
953
|
+
)
|
|
954
|
+
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
955
|
+
|
|
956
|
+
@classmethod
|
|
957
|
+
def CreateSimple(
|
|
958
|
+
cls, name: str, label: str, *, description: str = "", default_text: str = "", is_textarea: bool = False, **kwargs
|
|
959
|
+
) -> None:
|
|
960
|
+
"""
|
|
961
|
+
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
962
|
+
|
|
963
|
+
* Note that the "Number" type denotes an int, a Decimal (from decimal module), or a string that can be parsed to Decimal
|
|
964
|
+
|
|
965
|
+
Parameters:
|
|
966
|
+
name: The name of the parameter
|
|
967
|
+
label: The display label for the parameter
|
|
968
|
+
description: Explains the meaning of the parameter
|
|
969
|
+
default_text: Default input text for this option. Optional, default is empty string.
|
|
970
|
+
is_textarea: Whether the textbox field should be big. Optional, default is False.
|
|
753
971
|
"""
|
|
754
|
-
|
|
972
|
+
single_param_option = po.TextParameterOption(default_text=default_text)
|
|
973
|
+
cls.Create(name, label, (single_param_option,), description=description, is_textarea=is_textarea)
|
|
974
|
+
|
|
975
|
+
def get_entered_text(self, **kwargs) -> _TextValue:
|
|
976
|
+
"""
|
|
977
|
+
Get the selected number
|
|
755
978
|
|
|
979
|
+
Returns:
|
|
980
|
+
A number parsable string of the selected number
|
|
981
|
+
"""
|
|
982
|
+
return _TextValue(self._entered_text)
|
|
983
|
+
|
|
756
984
|
def to_json_dict0(self):
|
|
757
985
|
"""
|
|
758
986
|
Converts this parameter as a JSON object for the parameters API response
|
|
@@ -761,7 +989,9 @@ class NumberRangeParameter(Parameter):
|
|
|
761
989
|
A dictionary for the JSON object
|
|
762
990
|
"""
|
|
763
991
|
output = super().to_json_dict0()
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
output['selected_upper_value'] = self.get_selected_upper_value()
|
|
992
|
+
if self._curr_option is not None:
|
|
993
|
+
output['entered_text'] = self._entered_text
|
|
767
994
|
return output
|
|
995
|
+
|
|
996
|
+
def _get_response_model0(self):
|
|
997
|
+
return arm.TextParameterModel if self.is_enabled() else arm.ParameterModelBase
|