squirrels 0.3.1__py3-none-any.whl → 0.3.3__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 +1 -1
- squirrels/_api_response_models.py +1 -2
- squirrels/_api_server.py +3 -7
- squirrels/_authenticator.py +2 -2
- squirrels/_connection_set.py +5 -2
- squirrels/_models.py +11 -11
- squirrels/_parameter_configs.py +49 -34
- squirrels/_py_module.py +1 -1
- squirrels/arguments/run_time_args.py +4 -3
- squirrels/data_sources.py +23 -15
- squirrels/package_data/assets/index.css +1 -1
- squirrels/package_data/assets/index.js +13 -13
- squirrels/package_data/base_project/parameters.yml +16 -16
- squirrels/package_data/base_project/pyconfigs/parameters.py +16 -16
- squirrels/parameter_options.py +5 -4
- squirrels/parameters.py +179 -62
- {squirrels-0.3.1.dist-info → squirrels-0.3.3.dist-info}/METADATA +4 -3
- {squirrels-0.3.1.dist-info → squirrels-0.3.3.dist-info}/RECORD +21 -21
- {squirrels-0.3.1.dist-info → squirrels-0.3.3.dist-info}/LICENSE +0 -0
- {squirrels-0.3.1.dist-info → squirrels-0.3.3.dist-info}/WHEEL +0 -0
- {squirrels-0.3.1.dist-info → squirrels-0.3.3.dist-info}/entry_points.txt +0 -0
squirrels/parameters.py
CHANGED
|
@@ -26,7 +26,7 @@ class Parameter(metaclass=ABCMeta):
|
|
|
26
26
|
pass
|
|
27
27
|
|
|
28
28
|
@classmethod
|
|
29
|
-
def
|
|
29
|
+
def CreateWithOptions(
|
|
30
30
|
cls, name: str, label: str, all_options: Sequence[Union[po.ParameterOption, dict]], *, description: str = "",
|
|
31
31
|
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
32
32
|
) -> None:
|
|
@@ -45,6 +45,16 @@ class Parameter(metaclass=ABCMeta):
|
|
|
45
45
|
param_config = param_config_type(name, label, all_options, description=description, user_attribute=user_attribute,
|
|
46
46
|
parent_name=parent_name)
|
|
47
47
|
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def Create(
|
|
51
|
+
cls, name: str, label: str, all_options: Sequence[Union[po.ParameterOption, dict]], *, description: str = "",
|
|
52
|
+
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
53
|
+
) -> None:
|
|
54
|
+
"""
|
|
55
|
+
DEPRECATED. Use CreateWithOptions instead
|
|
56
|
+
"""
|
|
57
|
+
cls.CreateWithOptions(name, label, all_options, description=description, user_attribute=user_attribute, parent_name=parent_name)
|
|
48
58
|
|
|
49
59
|
@classmethod
|
|
50
60
|
@abstractmethod
|
|
@@ -79,7 +89,7 @@ class Parameter(metaclass=ABCMeta):
|
|
|
79
89
|
try:
|
|
80
90
|
return datetime.strptime(input_date.strip(), "%Y-%m-%d").date() if isinstance(input_date, str) else input_date
|
|
81
91
|
except ValueError as e:
|
|
82
|
-
self._config._raise_invalid_input_error(input_date,
|
|
92
|
+
self._config._raise_invalid_input_error(input_date, "Must be a date in YYYY-MM-DD format.", e)
|
|
83
93
|
|
|
84
94
|
def _validate_number(self, input_number: po.Number, curr_option: po._NumericParameterOption) -> Decimal:
|
|
85
95
|
try:
|
|
@@ -88,11 +98,14 @@ class Parameter(metaclass=ABCMeta):
|
|
|
88
98
|
self._config._raise_invalid_input_error(input_number, str(e), e)
|
|
89
99
|
|
|
90
100
|
@abstractmethod
|
|
91
|
-
def
|
|
101
|
+
def _to_json_dict0(self) -> dict:
|
|
92
102
|
"""
|
|
93
103
|
Helper method to convert the derived Parameter class into a JSON dictionary
|
|
94
104
|
"""
|
|
95
|
-
output =
|
|
105
|
+
output = {
|
|
106
|
+
"widget_type": self._config.widget_type, "name": self._config.name,
|
|
107
|
+
"label": self._config.label, "description": self._config.description
|
|
108
|
+
}
|
|
96
109
|
if not self.is_enabled():
|
|
97
110
|
output["widget_type"] = "disabled"
|
|
98
111
|
return output
|
|
@@ -101,8 +114,8 @@ class Parameter(metaclass=ABCMeta):
|
|
|
101
114
|
def _get_response_model0(self) -> type[arm.ParameterModelBase]:
|
|
102
115
|
pass
|
|
103
116
|
|
|
104
|
-
def _to_api_response_model0(self) -> arm.
|
|
105
|
-
return self._get_response_model0().model_validate(self.
|
|
117
|
+
def _to_api_response_model0(self) -> arm.ParameterModelBase:
|
|
118
|
+
return self._get_response_model0().model_validate(self._to_json_dict0())
|
|
106
119
|
|
|
107
120
|
|
|
108
121
|
@dataclass
|
|
@@ -125,11 +138,12 @@ class _SelectionParameter(Parameter):
|
|
|
125
138
|
self._config._raise_invalid_input_error(selected_id, f"The selected id {selected_id} does not exist in available options.")
|
|
126
139
|
|
|
127
140
|
@abstractmethod
|
|
128
|
-
def
|
|
141
|
+
def _to_json_dict0(self) -> dict:
|
|
129
142
|
"""
|
|
130
143
|
Helper method to convert the derived selection parameter class into a JSON object
|
|
131
144
|
"""
|
|
132
|
-
output = super().
|
|
145
|
+
output = super()._to_json_dict0()
|
|
146
|
+
output['trigger_refresh'] = self._config.trigger_refresh
|
|
133
147
|
output['options'] = [x._to_json_dict() for x in self._options]
|
|
134
148
|
return output
|
|
135
149
|
|
|
@@ -172,7 +186,7 @@ class SingleSelectParameter(_SelectionParameter):
|
|
|
172
186
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
173
187
|
description: Explains the meaning of the parameter
|
|
174
188
|
"""
|
|
175
|
-
cls.
|
|
189
|
+
cls.CreateWithOptions(name, label, all_options, description=description)
|
|
176
190
|
|
|
177
191
|
def get_selected(
|
|
178
192
|
self, field: Optional[str] = None, *, default_field: Optional[str] = None, default: Any = None, **kwargs
|
|
@@ -243,14 +257,14 @@ class SingleSelectParameter(_SelectionParameter):
|
|
|
243
257
|
else:
|
|
244
258
|
return tuple()
|
|
245
259
|
|
|
246
|
-
def
|
|
260
|
+
def _to_json_dict0(self) -> dict:
|
|
247
261
|
"""
|
|
248
262
|
Converts this parameter as a JSON object for the parameters API response
|
|
249
263
|
|
|
250
264
|
Returns:
|
|
251
265
|
A dictionary for the JSON object
|
|
252
266
|
"""
|
|
253
|
-
output = super().
|
|
267
|
+
output = super()._to_json_dict0()
|
|
254
268
|
output['selected_id'] = self._selected_id
|
|
255
269
|
return output
|
|
256
270
|
|
|
@@ -282,9 +296,9 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
282
296
|
return pc.MultiSelectParameterConfig
|
|
283
297
|
|
|
284
298
|
@classmethod
|
|
285
|
-
def
|
|
299
|
+
def CreateWithOptions(
|
|
286
300
|
cls, name: str, label: str, all_options: Sequence[Union[po.SelectParameterOption, dict]], *, description: str = "",
|
|
287
|
-
show_select_all: bool = True,
|
|
301
|
+
show_select_all: bool = True, order_matters: bool = False, none_is_all: bool = True,
|
|
288
302
|
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
289
303
|
) -> None:
|
|
290
304
|
"""
|
|
@@ -296,23 +310,35 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
296
310
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
297
311
|
description: Explains the meaning of the parameter
|
|
298
312
|
show_select_all: Communicate to front-end whether to include a "select all" option
|
|
299
|
-
is_dropdown: Communicate to front-end whether the widget should be a dropdown with checkboxes
|
|
300
313
|
order_matters: Communicate to front-end whether the order of the selections made matter
|
|
301
314
|
none_is_all: Whether having no options selected is equivalent to all selectable options selected
|
|
302
315
|
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
303
316
|
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
304
317
|
"""
|
|
305
318
|
param_config = pc.MultiSelectParameterConfig(
|
|
306
|
-
name, label, all_options,
|
|
307
|
-
show_select_all=show_select_all,
|
|
308
|
-
description=description, user_attribute=user_attribute, parent_name=parent_name
|
|
319
|
+
name, label, all_options, description=description, user_attribute=user_attribute, parent_name=parent_name,
|
|
320
|
+
show_select_all=show_select_all, order_matters=order_matters, none_is_all=none_is_all
|
|
309
321
|
)
|
|
310
322
|
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
323
|
+
|
|
324
|
+
@classmethod
|
|
325
|
+
def Create(
|
|
326
|
+
cls, name: str, label: str, all_options: Sequence[Union[po.SelectParameterOption, dict]], *, description: str = "",
|
|
327
|
+
show_select_all: bool = True, order_matters: bool = False, none_is_all: bool = True,
|
|
328
|
+
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
329
|
+
) -> None:
|
|
330
|
+
"""
|
|
331
|
+
DEPRECATED. Use CreateWithOptions instead
|
|
332
|
+
"""
|
|
333
|
+
cls.CreateWithOptions(
|
|
334
|
+
name, label, all_options, description=description, show_select_all=show_select_all,
|
|
335
|
+
order_matters=order_matters, none_is_all=none_is_all, user_attribute=user_attribute, parent_name=parent_name
|
|
336
|
+
)
|
|
311
337
|
|
|
312
338
|
@classmethod
|
|
313
339
|
def CreateSimple(
|
|
314
340
|
cls, name: str, label: str, all_options: Sequence[po.SelectParameterOption], *, description: str = "",
|
|
315
|
-
show_select_all: bool = True,
|
|
341
|
+
show_select_all: bool = True, order_matters: bool = False, none_is_all: bool = True, **kwargs
|
|
316
342
|
) -> None:
|
|
317
343
|
"""
|
|
318
344
|
Method for creating the configurations for a MultiSelectParameter that doesn't involve user attributes or parent parameters
|
|
@@ -323,19 +349,18 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
323
349
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
324
350
|
description: Explains the meaning of the parameter
|
|
325
351
|
show_select_all: Communicate to front-end whether to include a "select all" option
|
|
326
|
-
is_dropdown: Communicate to front-end whether the widget should be a dropdown with checkboxes
|
|
327
352
|
order_matters: Communicate to front-end whether the order of the selections made matter
|
|
328
353
|
none_is_all: Whether having no options selected is equivalent to all selectable options selected
|
|
329
354
|
"""
|
|
330
|
-
cls.
|
|
355
|
+
cls.CreateWithOptions(
|
|
331
356
|
name, label, all_options, description=description,
|
|
332
|
-
show_select_all=show_select_all,
|
|
357
|
+
show_select_all=show_select_all, order_matters=order_matters, none_is_all=none_is_all
|
|
333
358
|
)
|
|
334
359
|
|
|
335
360
|
@classmethod
|
|
336
361
|
def CreateFromSource(
|
|
337
362
|
cls, name: str, label: str, data_source: Union[d.SelectDataSource, dict], *, description: str = "",
|
|
338
|
-
show_select_all: bool = True,
|
|
363
|
+
show_select_all: bool = True, order_matters: bool = False, none_is_all: bool = True,
|
|
339
364
|
user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
340
365
|
) -> None:
|
|
341
366
|
"""
|
|
@@ -347,15 +372,13 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
347
372
|
data_source: The lookup table to use for this parameter
|
|
348
373
|
description: Explains the meaning of the parameter
|
|
349
374
|
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
375
|
order_matters: Communicate to front-end whether the order of the selections made matter
|
|
352
376
|
none_is_all: Whether having no options selected is equivalent to all selectable options selected
|
|
353
377
|
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
354
378
|
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
355
379
|
"""
|
|
356
380
|
extra_args = {
|
|
357
|
-
"show_select_all": show_select_all, "
|
|
358
|
-
"order_matters": order_matters, "none_is_all": none_is_all
|
|
381
|
+
"show_select_all": show_select_all, "order_matters": order_matters, "none_is_all": none_is_all
|
|
359
382
|
}
|
|
360
383
|
param_config = pc.DataSourceParameterConfig(
|
|
361
384
|
pc.MultiSelectParameterConfig, name, label, data_source, extra_args=extra_args, description=description,
|
|
@@ -477,14 +500,16 @@ class MultiSelectParameter(_SelectionParameter):
|
|
|
477
500
|
def _get_selected_ids_as_list(self, **kwargs) -> Sequence[str]:
|
|
478
501
|
return self.get_selected_ids_as_list()
|
|
479
502
|
|
|
480
|
-
def
|
|
503
|
+
def _to_json_dict0(self):
|
|
481
504
|
"""
|
|
482
505
|
Converts this parameter as a JSON object for the parameters API response
|
|
483
506
|
|
|
484
507
|
Returns:
|
|
485
508
|
A dictionary for the JSON object
|
|
486
509
|
"""
|
|
487
|
-
output = super().
|
|
510
|
+
output = super()._to_json_dict0()
|
|
511
|
+
output['show_select_all'] = self._config.show_select_all
|
|
512
|
+
output['order_matters'] = self._config.order_matters
|
|
488
513
|
output['selected_ids'] = list(self._selected_ids)
|
|
489
514
|
return output
|
|
490
515
|
|
|
@@ -502,6 +527,7 @@ class DateParameter(Parameter):
|
|
|
502
527
|
curr_option: The current option showing for defaults based on user attribute and selection of parent
|
|
503
528
|
selected_date: The selected date
|
|
504
529
|
"""
|
|
530
|
+
_config: pc.DateParameterConfig
|
|
505
531
|
_curr_option: Optional[po.DateParameterOption]
|
|
506
532
|
_selected_date: Union[date, str]
|
|
507
533
|
|
|
@@ -531,7 +557,7 @@ class DateParameter(Parameter):
|
|
|
531
557
|
date_format: Format of the default date, default is '%Y-%m-%d'
|
|
532
558
|
"""
|
|
533
559
|
single_param_option = po.DateParameterOption(default_date, date_format=date_format)
|
|
534
|
-
cls.
|
|
560
|
+
cls.CreateWithOptions(name, label, (single_param_option,), description=description)
|
|
535
561
|
|
|
536
562
|
def get_selected_date(self, *, date_format: str = None, **kwargs) -> str:
|
|
537
563
|
"""
|
|
@@ -558,7 +584,7 @@ class DateParameter(Parameter):
|
|
|
558
584
|
"""
|
|
559
585
|
return self._enquote(self.get_selected_date(date_format=date_format))
|
|
560
586
|
|
|
561
|
-
def
|
|
587
|
+
def _to_json_dict0(self):
|
|
562
588
|
"""
|
|
563
589
|
Converts this parameter as a JSON object for the parameters API response
|
|
564
590
|
|
|
@@ -567,7 +593,7 @@ class DateParameter(Parameter):
|
|
|
567
593
|
Returns:
|
|
568
594
|
A dictionary for the JSON object
|
|
569
595
|
"""
|
|
570
|
-
output = super().
|
|
596
|
+
output = super()._to_json_dict0()
|
|
571
597
|
if self.is_enabled():
|
|
572
598
|
output["selected_date"] = self.get_selected_date(date_format="%Y-%m-%d")
|
|
573
599
|
else:
|
|
@@ -589,6 +615,7 @@ class DateRangeParameter(Parameter):
|
|
|
589
615
|
selected_start_date: The selected start date
|
|
590
616
|
selected_end_date: The selected end date
|
|
591
617
|
"""
|
|
618
|
+
_config: pc.DateRangeParameterConfig
|
|
592
619
|
_curr_option: Optional[po.DateRangeParameterOption]
|
|
593
620
|
_selected_start_date: Union[date, str]
|
|
594
621
|
_selected_end_date: Union[date, str]
|
|
@@ -621,7 +648,7 @@ class DateRangeParameter(Parameter):
|
|
|
621
648
|
date_format: Format of the default date, default is '%Y-%m-%d'
|
|
622
649
|
"""
|
|
623
650
|
single_param_option = po.DateRangeParameterOption(default_start_date, default_end_date, date_format=date_format)
|
|
624
|
-
cls.
|
|
651
|
+
cls.CreateWithOptions(name, label, (single_param_option,), description=description)
|
|
625
652
|
|
|
626
653
|
def get_selected_start_date(self, *, date_format: str = None, **kwargs) -> str:
|
|
627
654
|
"""
|
|
@@ -673,7 +700,7 @@ class DateRangeParameter(Parameter):
|
|
|
673
700
|
"""
|
|
674
701
|
return self._enquote(self.get_selected_end_date(date_format=date_format))
|
|
675
702
|
|
|
676
|
-
def
|
|
703
|
+
def _to_json_dict0(self):
|
|
677
704
|
"""
|
|
678
705
|
Converts this parameter as a JSON object for the parameters API response
|
|
679
706
|
|
|
@@ -682,7 +709,7 @@ class DateRangeParameter(Parameter):
|
|
|
682
709
|
Returns:
|
|
683
710
|
A dictionary for the JSON object
|
|
684
711
|
"""
|
|
685
|
-
output = super().
|
|
712
|
+
output = super()._to_json_dict0()
|
|
686
713
|
if self.is_enabled():
|
|
687
714
|
output["selected_start_date"] = self.get_selected_start_date(date_format="%Y-%m-%d")
|
|
688
715
|
output["selected_end_date"] = self.get_selected_end_date(date_format="%Y-%m-%d")
|
|
@@ -702,6 +729,7 @@ class NumberParameter(Parameter):
|
|
|
702
729
|
curr_option: The current option showing for defaults based on user attribute and selection of parent
|
|
703
730
|
selected_value: The selected integer or decimal number
|
|
704
731
|
"""
|
|
732
|
+
_config: pc.NumberParameterConfig
|
|
705
733
|
_curr_option: Optional[po.NumberParameterOption]
|
|
706
734
|
_selected_value: po.Number
|
|
707
735
|
|
|
@@ -735,7 +763,7 @@ class NumberParameter(Parameter):
|
|
|
735
763
|
default_value: Default value for this option, and must be selectable based on min_value, max_value, and increment
|
|
736
764
|
"""
|
|
737
765
|
single_param_option = po.NumberParameterOption(min_value, max_value, increment=increment, default_value=default_value)
|
|
738
|
-
cls.
|
|
766
|
+
cls.CreateWithOptions(name, label, (single_param_option,), description=description)
|
|
739
767
|
|
|
740
768
|
def get_selected_value(self, **kwargs) -> float:
|
|
741
769
|
"""
|
|
@@ -746,14 +774,14 @@ class NumberParameter(Parameter):
|
|
|
746
774
|
"""
|
|
747
775
|
return float(self._selected_value)
|
|
748
776
|
|
|
749
|
-
def
|
|
777
|
+
def _to_json_dict0(self):
|
|
750
778
|
"""
|
|
751
779
|
Converts this parameter as a JSON object for the parameters API response
|
|
752
780
|
|
|
753
781
|
Returns:
|
|
754
782
|
A dictionary for the JSON object
|
|
755
783
|
"""
|
|
756
|
-
output = super().
|
|
784
|
+
output = super()._to_json_dict0()
|
|
757
785
|
if self.is_enabled():
|
|
758
786
|
output.update(self._curr_option._to_json_dict())
|
|
759
787
|
output["selected_value"] = self.get_selected_value()
|
|
@@ -774,6 +802,7 @@ class NumberRangeParameter(Parameter):
|
|
|
774
802
|
selected_lower_value: The selected lower integer or decimal number
|
|
775
803
|
selected_upper_value: The selected upper integer or decimal number
|
|
776
804
|
"""
|
|
805
|
+
_config: pc.NumberRangeParameterConfig
|
|
777
806
|
_curr_option: Optional[po.NumberRangeParameterOption]
|
|
778
807
|
_selected_lower_value: po.Number
|
|
779
808
|
_selected_upper_value: po.Number
|
|
@@ -814,7 +843,7 @@ class NumberRangeParameter(Parameter):
|
|
|
814
843
|
single_param_option = po.NumberRangeParameterOption(
|
|
815
844
|
min_value, max_value, increment=increment, default_lower_value=default_lower_value, default_upper_value=default_upper_value
|
|
816
845
|
)
|
|
817
|
-
cls.
|
|
846
|
+
cls.CreateWithOptions(name, label, (single_param_option,), description=description)
|
|
818
847
|
|
|
819
848
|
def get_selected_lower_value(self, **kwargs) -> float:
|
|
820
849
|
"""
|
|
@@ -834,14 +863,14 @@ class NumberRangeParameter(Parameter):
|
|
|
834
863
|
"""
|
|
835
864
|
return float(self._selected_upper_value)
|
|
836
865
|
|
|
837
|
-
def
|
|
866
|
+
def _to_json_dict0(self):
|
|
838
867
|
"""
|
|
839
868
|
Converts this parameter as a JSON object for the parameters API response
|
|
840
869
|
|
|
841
870
|
Returns:
|
|
842
871
|
A dictionary for the JSON object
|
|
843
872
|
"""
|
|
844
|
-
output = super().
|
|
873
|
+
output = super()._to_json_dict0()
|
|
845
874
|
if self._curr_option is not None:
|
|
846
875
|
output.update(self._curr_option._to_json_dict())
|
|
847
876
|
output['selected_lower_value'] = self.get_selected_lower_value()
|
|
@@ -853,15 +882,15 @@ class NumberRangeParameter(Parameter):
|
|
|
853
882
|
|
|
854
883
|
|
|
855
884
|
@dataclass
|
|
856
|
-
class
|
|
885
|
+
class TextValue:
|
|
857
886
|
_value_do_not_touch: str
|
|
858
887
|
|
|
859
888
|
def __repr__(self):
|
|
860
889
|
raise u.ConfigurationError(
|
|
861
|
-
"Cannot convert
|
|
890
|
+
"Cannot convert TextValue directly to string (to avoid SQL injection). Try using it through placeholders instead"
|
|
862
891
|
)
|
|
863
892
|
|
|
864
|
-
def apply(self, str_to_str_function: Callable[[str], str]) ->
|
|
893
|
+
def apply(self, str_to_str_function: Callable[[str], str]) -> TextValue:
|
|
865
894
|
"""
|
|
866
895
|
Transforms the entered text with a function that takes a string and returns a string.
|
|
867
896
|
|
|
@@ -874,10 +903,11 @@ class _TextValue:
|
|
|
874
903
|
A new TextValue with the transformed entered text
|
|
875
904
|
"""
|
|
876
905
|
new_value = str_to_str_function(self._value_do_not_touch)
|
|
877
|
-
|
|
878
|
-
|
|
906
|
+
if not isinstance(new_value, str):
|
|
907
|
+
raise u.ConfigurationError("Function provided must return string")
|
|
908
|
+
return TextValue(new_value)
|
|
879
909
|
|
|
880
|
-
def apply_percent_wrap(self) ->
|
|
910
|
+
def apply_percent_wrap(self) -> TextValue:
|
|
881
911
|
"""
|
|
882
912
|
Adds percent signs before and after the entered text, and returns a new object, leaving the original the same.
|
|
883
913
|
|
|
@@ -897,7 +927,8 @@ class _TextValue:
|
|
|
897
927
|
A boolean for the transformed value
|
|
898
928
|
"""
|
|
899
929
|
new_value = str_to_bool_function(self._value_do_not_touch)
|
|
900
|
-
|
|
930
|
+
if not isinstance(new_value, bool):
|
|
931
|
+
raise u.ConfigurationError("Function provided must return bool")
|
|
901
932
|
return new_value
|
|
902
933
|
|
|
903
934
|
def apply_as_number(self, str_to_num_function: Callable[[str], Union[int, float]]) -> Union[int, float]:
|
|
@@ -911,7 +942,23 @@ class _TextValue:
|
|
|
911
942
|
An int or float for the transformed value
|
|
912
943
|
"""
|
|
913
944
|
new_value = str_to_num_function(self._value_do_not_touch)
|
|
914
|
-
|
|
945
|
+
if not isinstance(new_value, (int, float)):
|
|
946
|
+
raise u.ConfigurationError("Function provided must return a number")
|
|
947
|
+
return new_value
|
|
948
|
+
|
|
949
|
+
def apply_as_datetime(self, str_to_datetime_function: Callable[[str], datetime]) -> datetime:
|
|
950
|
+
"""
|
|
951
|
+
Transforms the entered text with a function that takes a string and returns a datetime object.
|
|
952
|
+
|
|
953
|
+
Parameters:
|
|
954
|
+
str_to_datetime_function: A function that accepts a string and returns a datetime object.
|
|
955
|
+
|
|
956
|
+
Returns:
|
|
957
|
+
A datetime object for the transformed value
|
|
958
|
+
"""
|
|
959
|
+
new_value = str_to_datetime_function(self._value_do_not_touch)
|
|
960
|
+
if not isinstance(new_value, datetime):
|
|
961
|
+
raise u.ConfigurationError("Function provided must return datetime")
|
|
915
962
|
return new_value
|
|
916
963
|
|
|
917
964
|
|
|
@@ -920,8 +967,16 @@ class TextParameter(Parameter):
|
|
|
920
967
|
"""
|
|
921
968
|
Class for text parameter widgets.
|
|
922
969
|
"""
|
|
970
|
+
_config: pc.TextParameterConfig
|
|
923
971
|
_curr_option: Optional[po.TextParameterOption]
|
|
924
972
|
_entered_text: str
|
|
973
|
+
|
|
974
|
+
def __post_init__(self):
|
|
975
|
+
try:
|
|
976
|
+
if self.is_enabled():
|
|
977
|
+
self._entered_text = self._config.validate_entered_text(self._entered_text)
|
|
978
|
+
except u.ConfigurationError as e:
|
|
979
|
+
self._config._raise_invalid_input_error(self._entered_text, str(e), e)
|
|
925
980
|
|
|
926
981
|
def is_enabled(self) -> bool:
|
|
927
982
|
return self._curr_option is not None
|
|
@@ -931,9 +986,9 @@ class TextParameter(Parameter):
|
|
|
931
986
|
return pc.TextParameterConfig
|
|
932
987
|
|
|
933
988
|
@classmethod
|
|
934
|
-
def
|
|
989
|
+
def CreateWithOptions(
|
|
935
990
|
cls, name: str, label: str, all_options: Sequence[Union[po.TextParameterOption, dict]], *, description: str = "",
|
|
936
|
-
|
|
991
|
+
input_type: str = "text", user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
937
992
|
) -> None:
|
|
938
993
|
"""
|
|
939
994
|
Method for creating the configurations for a MultiSelectParameter that may include user attribute or parent
|
|
@@ -943,52 +998,114 @@ class TextParameter(Parameter):
|
|
|
943
998
|
label: The display label for the parameter
|
|
944
999
|
all_options: All options associated to this parameter regardless of the user group or parent parameter option they depend on
|
|
945
1000
|
description: Explains the meaning of the parameter
|
|
946
|
-
|
|
1001
|
+
input_type: The type of input field to use. Must be one of "text", "textarea", "number", "color", "date", "datetime-local", "month", "time", and "password". Optional, default is "text". More information on input types other than "textarea" can be found at https://www.w3schools.com/html/html_form_input_types.asp. More information on "textarea" can be found at https://www.w3schools.com/tags/tag_textarea.asp
|
|
947
1002
|
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
948
1003
|
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
949
1004
|
"""
|
|
950
1005
|
param_config = pc.TextParameterConfig(
|
|
951
|
-
name, label, all_options, description=description,
|
|
1006
|
+
name, label, all_options, description=description, input_type=input_type, user_attribute=user_attribute,
|
|
952
1007
|
parent_name=parent_name
|
|
953
1008
|
)
|
|
954
1009
|
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
1010
|
+
|
|
1011
|
+
@classmethod
|
|
1012
|
+
def Create(
|
|
1013
|
+
cls, name: str, label: str, all_options: Sequence[Union[po.SelectParameterOption, dict]], *, description: str = "",
|
|
1014
|
+
input_type: str = "text", user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
1015
|
+
) -> None:
|
|
1016
|
+
"""
|
|
1017
|
+
DEPRECATED. Use CreateWithOptions instead
|
|
1018
|
+
"""
|
|
1019
|
+
cls.CreateWithOptions(
|
|
1020
|
+
name, label, all_options, description=description, input_type=input_type, user_attribute=user_attribute, parent_name=parent_name
|
|
1021
|
+
)
|
|
955
1022
|
|
|
956
1023
|
@classmethod
|
|
957
1024
|
def CreateSimple(
|
|
958
|
-
cls, name: str, label: str, *, description: str = "", default_text: str = "",
|
|
1025
|
+
cls, name: str, label: str, *, description: str = "", default_text: str = "", input_type: str = "text", **kwargs
|
|
959
1026
|
) -> None:
|
|
960
1027
|
"""
|
|
961
1028
|
Method for creating the configurations for a Parameter that doesn't involve user attributes or parent parameters
|
|
962
1029
|
|
|
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
1030
|
Parameters:
|
|
966
1031
|
name: The name of the parameter
|
|
967
1032
|
label: The display label for the parameter
|
|
968
1033
|
description: Explains the meaning of the parameter
|
|
969
1034
|
default_text: Default input text for this option. Optional, default is empty string.
|
|
970
|
-
|
|
1035
|
+
input_type: The type of input field to use. Must be one of "text", "textarea", "number", "color", "date", "datetime-local", "month", "time", and "password". Optional, default is "text". More information on input types other than "textarea" can be found at https://www.w3schools.com/html/html_form_input_types.asp. More information on "textarea" can be found at https://www.w3schools.com/tags/tag_textarea.asp
|
|
971
1036
|
"""
|
|
972
1037
|
single_param_option = po.TextParameterOption(default_text=default_text)
|
|
973
|
-
cls.
|
|
1038
|
+
cls.CreateWithOptions(name, label, (single_param_option,), description=description, input_type=input_type)
|
|
1039
|
+
|
|
1040
|
+
@classmethod
|
|
1041
|
+
def CreateFromSource(
|
|
1042
|
+
cls, name: str, label: str, data_source: Union[d.TextDataSource, dict], *, description: str = "",
|
|
1043
|
+
input_type: str = "text", user_attribute: Optional[str] = None, parent_name: Optional[str] = None, **kwargs
|
|
1044
|
+
) -> None:
|
|
1045
|
+
"""
|
|
1046
|
+
Method for creating the configurations for a MultiSelectParameter that uses a SelectDataSource to receive the options
|
|
1047
|
+
|
|
1048
|
+
Parameters:
|
|
1049
|
+
name: The name of the parameter
|
|
1050
|
+
label: The display label for the parameter
|
|
1051
|
+
data_source: The lookup table to use for this parameter
|
|
1052
|
+
description: Explains the meaning of the parameter
|
|
1053
|
+
input_type: The type of input field to use. Options are one of "text", "textarea", "number", "color", "date", "datetime-local", "month", "time", and "password". Optional, default is "text". More information on input types other than "textarea" can be found at https://www.w3schools.com/html/html_form_input_types.asp. More information on "textarea" can be found at https://www.w3schools.com/tags/tag_textarea.asp
|
|
1054
|
+
user_attribute: The user attribute that may cascade the options for this parameter. Default is None
|
|
1055
|
+
parent_name: Name of parent parameter that may cascade the options for this parameter. Default is None (no parent)
|
|
1056
|
+
"""
|
|
1057
|
+
extra_args = {
|
|
1058
|
+
"input_type": input_type
|
|
1059
|
+
}
|
|
1060
|
+
param_config = pc.DataSourceParameterConfig(
|
|
1061
|
+
pc.TextParameterConfig, name, label, data_source, extra_args=extra_args, description=description,
|
|
1062
|
+
user_attribute=user_attribute, parent_name=parent_name
|
|
1063
|
+
)
|
|
1064
|
+
ps.ParameterConfigsSetIO.obj.add(param_config)
|
|
974
1065
|
|
|
975
|
-
def get_entered_text(self, **kwargs) ->
|
|
1066
|
+
def get_entered_text(self, **kwargs) -> TextValue:
|
|
976
1067
|
"""
|
|
977
|
-
Get the
|
|
1068
|
+
Get the entered text. Returns a TextValue object that cannot be converted to string except through placeholders.
|
|
978
1069
|
|
|
979
1070
|
Returns:
|
|
980
|
-
A
|
|
1071
|
+
A TextValue object
|
|
981
1072
|
"""
|
|
982
|
-
return
|
|
1073
|
+
return TextValue(self._entered_text)
|
|
1074
|
+
|
|
1075
|
+
def get_entered_int(self, **kwargs) -> int:
|
|
1076
|
+
"""
|
|
1077
|
+
Get the entered integer. The TextParameter must be a "number" input type
|
|
1078
|
+
|
|
1079
|
+
Returns: int
|
|
1080
|
+
"""
|
|
1081
|
+
if self._config.input_type != "number":
|
|
1082
|
+
raise u.ConfigurationError("Method 'get_entered_int' requires TextParameter to have input type 'number'")
|
|
1083
|
+
text = self.get_entered_text()
|
|
1084
|
+
return text.apply_as_number(int)
|
|
1085
|
+
|
|
1086
|
+
def get_entered_datetime(self, **kwargs) -> datetime:
|
|
1087
|
+
"""
|
|
1088
|
+
Get the entered datetime. The TextParameter input type must be one of ["date", "datetime-local", "month", "time"]
|
|
1089
|
+
|
|
1090
|
+
Returns: datetime
|
|
1091
|
+
"""
|
|
1092
|
+
applicable_input_types = ["date", "datetime-local", "month", "time"]
|
|
1093
|
+
if self._config.input_type not in applicable_input_types:
|
|
1094
|
+
raise u.ConfigurationError(f"Method 'get_entered_datetime' requires TextParameter to have one of these input types: {applicable_input_types}")
|
|
1095
|
+
text = self.get_entered_text()
|
|
1096
|
+
|
|
1097
|
+
date_formats = { "date": "%Y-%m-%d", "datetime-local": "%Y-%m-%dT%H:%M", "month": "%Y-%m", "time": "%H:%M" }
|
|
1098
|
+
return text.apply_as_datetime(lambda x: datetime.strptime(x, date_formats[self._config.input_type]))
|
|
983
1099
|
|
|
984
|
-
def
|
|
1100
|
+
def _to_json_dict0(self):
|
|
985
1101
|
"""
|
|
986
1102
|
Converts this parameter as a JSON object for the parameters API response
|
|
987
1103
|
|
|
988
1104
|
Returns:
|
|
989
1105
|
A dictionary for the JSON object
|
|
990
1106
|
"""
|
|
991
|
-
output = super().
|
|
1107
|
+
output = super()._to_json_dict0()
|
|
1108
|
+
output['input_type'] = self._config.input_type
|
|
992
1109
|
if self._curr_option is not None:
|
|
993
1110
|
output['entered_text'] = self._entered_text
|
|
994
1111
|
return output
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: squirrels
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Squirrels - API Framework for Data Analytics
|
|
5
5
|
Home-page: https://squirrels-analytics.github.io
|
|
6
6
|
License: Apache-2.0
|
|
@@ -20,7 +20,7 @@ Classifier: Typing :: Typed
|
|
|
20
20
|
Provides-Extra: duckdb
|
|
21
21
|
Requires-Dist: cachetools (>=5.3.2,<6.0.0)
|
|
22
22
|
Requires-Dist: duckdb-engine (>=0.13.0,<1.0.0) ; extra == "duckdb"
|
|
23
|
-
Requires-Dist: fastapi (>=0.
|
|
23
|
+
Requires-Dist: fastapi (>=0.112.1,<0.113.0)
|
|
24
24
|
Requires-Dist: gitpython (>=3.1.41,<4.0.0)
|
|
25
25
|
Requires-Dist: inquirer (>=3.2.1,<4.0.0)
|
|
26
26
|
Requires-Dist: jinja2 (>=3.1.3,<4.0.0)
|
|
@@ -28,9 +28,10 @@ Requires-Dist: matplotlib (>=3.8.3,<4.0.0)
|
|
|
28
28
|
Requires-Dist: networkx (>=3.2.1,<4.0.0)
|
|
29
29
|
Requires-Dist: pandas (>=2.1.4,<3.0.0)
|
|
30
30
|
Requires-Dist: pyjwt (>=2.8.0,<3.0.0)
|
|
31
|
+
Requires-Dist: python-multipart (>=0.0.9,<0.0.10)
|
|
31
32
|
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
|
|
32
33
|
Requires-Dist: sqlalchemy (>=2.0.25,<3.0.0)
|
|
33
|
-
Requires-Dist: uvicorn (>=0.
|
|
34
|
+
Requires-Dist: uvicorn (>=0.30.6,<0.31.0)
|
|
34
35
|
Project-URL: Documentation, https://squirrels-analytics.github.io
|
|
35
36
|
Project-URL: Repository, https://github.com/squirrels-analytics/squirrels
|
|
36
37
|
Description-Content-Type: text/markdown
|