Skip to content

Commit d4b06d1

Browse files
authored
Merge pull request #158 from jverswijver/update_forms
fix filtering
2 parents cbcd156 + cc88326 commit d4b06d1

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
44

5+
## [0.8.2] - 2023-03-23
6+
7+
### Added
8+
- Forms now allow you to specify presets using their schemas and tables to avoid collisions [#158](https://github.com/datajoint/pharus/pull/158)
9+
510
## [0.8.1] - 2023-03-20
611

712
### Added
@@ -275,6 +280,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
275280
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
276281
- Check dependency utility to determine child table references.
277282

283+
[0.8.2]: https://github.com/datajoint/pharus/compare/0.8.1...0.8.2
278284
[0.8.1]: https://github.com/datajoint/pharus/compare/0.8.0...0.8.1
279285
[0.8.0]: https://github.com/datajoint/pharus/compare/0.7.3...0.8.0
280286
[0.7.3]: https://github.com/datajoint/pharus/compare/0.7.2...0.7.3

pharus/component_interface.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,25 @@ def presets_route(self):
353353

354354
# Helper function to filter out fields not in the insert,
355355
# as well as apply the fields_map
356-
def filterPreset(preset: dict):
357-
return {
358-
(self.input_lookup[k] if k in self.input_lookup else k): v
356+
def filter_preset(preset: dict):
357+
# Any key that follows the schema.table.attribute format,
358+
# and its schema.table is not in the forms is filtered out.
359+
360+
preset_with_tables_filtered = {
361+
k: v
359362
for k, v in preset.items()
363+
if (
364+
len(k.split(".")) == 1
365+
or ".".join(k.split(".")[0:2]) in self.component_config["tables"]
366+
)
367+
}
368+
return {
369+
(
370+
self.input_lookup[k.split(".").pop()]
371+
if k.split(".").pop() in self.input_lookup
372+
else k.split(".").pop()
373+
): v
374+
for k, v in preset_with_tables_filtered.items()
360375
}
361376

362377
if "presets" not in self.component_config:
@@ -367,7 +382,7 @@ def filterPreset(preset: dict):
367382
)
368383

369384
filtered_preset_dictionary = {
370-
k: filterPreset(v) for k, v in self.presets_dict.items()
385+
k: filter_preset(v) for k, v in self.presets_dict.items()
371386
}
372387

373388
return (

pharus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Package metadata."""
2-
__version__ = "0.8.1"
2+
__version__ = "0.8.2"

tests/init/test_dynamic_api_spec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SciViz: # top level tab
9696
destination: c_name
9797
presets: >
9898
def presets():
99-
return {'preset 1': {'b_id': 14}}
99+
return {'preset 1': {'b_id': 14, 'someschema.sometable.attributetobefiltered' : 'blabla'}}
100100
insert3:
101101
route: /insert3
102102
x: 1

0 commit comments

Comments
 (0)