Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/platform v2.2.0 #43

Merged
merged 76 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7db4eb3
Added function calls to the ktype service
Sep 16, 2024
5b139c0
Added backend check for existing ktypes
Sep 18, 2024
87b27b5
Merge branch 'main' of github.com:MI-FraunhoferIWM/dsms-python-sdk in…
Sep 18, 2024
ed618b5
Added additional methods to support ktype functionalities
Sep 20, 2024
d8d2e67
Example for ktype usage has been added.
Sep 24, 2024
c96381e
Fixed pylint errors
Sep 24, 2024
3d0f850
Fixed pylint errors
Sep 25, 2024
6bd9835
Delete testktype.py
arjungkk Sep 26, 2024
997549d
update ktype retrieval
MBueschelberger Sep 27, 2024
46daa6e
udpate pytests
MBueschelberger Sep 27, 2024
c70ba76
minorly refactor ktype enum for direct retrieval of ktype model
MBueschelberger Oct 1, 2024
5ade860
update ktype validation
MBueschelberger Oct 1, 2024
4284256
update setup.cfg and bring back underscore for private variable
MBueschelberger Oct 2, 2024
9c0b6c4
remove unneeded utils
MBueschelberger Oct 2, 2024
6dc696f
update jupyter notebook for docs
MBueschelberger Oct 2, 2024
a70ad66
update jupyter notebook for docs
MBueschelberger Oct 2, 2024
db4509b
remove unneeded private property assignment
MBueschelberger Oct 2, 2024
ffdac4a
update ktype validator
MBueschelberger Oct 2, 2024
a0e1e69
update jupyter notebooks for docs
MBueschelberger Oct 2, 2024
cffaeb3
bring accidentally deleted ktype.setter
MBueschelberger Oct 2, 2024
23c819f
Merge pull request #37 from MI-FraunhoferIWM/review/ktype-integration
arjungkk Oct 7, 2024
901dc73
Mapped webform to pydantic model
Oct 21, 2024
2b81fae
Delete test.py
arjungkk Oct 24, 2024
2af08a7
Added alias generator to webform inputs
Oct 24, 2024
97ef7e2
Merge branch 'dev/ktype-integration' of github.com:MI-FraunhoferIWM/d…
Oct 24, 2024
d2b4c5f
Updated README and removed duplicate files
Oct 24, 2024
a3b7c2e
Added pylint fixes
Oct 24, 2024
aac1be4
adapt sdk to new platform backend
MBueschelberger Nov 21, 2024
aa4f3e6
Bump version v2.0.4 -> v2.1.0dev0
MBueschelberger Nov 21, 2024
7f4bff9
make upper restriction for pydantic
MBueschelberger Nov 21, 2024
761c3e3
set max length of string-field names
MBueschelberger Nov 27, 2024
8796d2e
bump dev version tag
MBueschelberger Nov 27, 2024
02ab43e
Support for webform changes
Dec 2, 2024
aab928f
Support for webform
Dec 2, 2024
e5b3396
Merge pull request #41 from MI-FraunhoferIWM/dev/webform-support
arjungkk Dec 2, 2024
6efc6e5
add schema transformation function
MBueschelberger Dec 2, 2024
1977ed9
bump dev version
MBueschelberger Dec 2, 2024
63d7be2
make temporary compatibility with old webform model
MBueschelberger Dec 9, 2024
0d06906
temporary fix for custom properties
MBueschelberger Dec 10, 2024
79a7f0d
set upper limit for pydantic
MBueschelberger Dec 10, 2024
b61f472
merge from dev/ktype-integration
MBueschelberger Dec 12, 2024
d6c23b9
update custom properties model
MBueschelberger Dec 12, 2024
c06d45d
update webform kitem assignment and validation
MBueschelberger Dec 13, 2024
ddf2458
fix printing of values
MBueschelberger Dec 16, 2024
78c534b
debug custom properties and dataframe
MBueschelberger Dec 16, 2024
e9f3f58
update config
MBueschelberger Dec 16, 2024
1f60b4d
debug buffer context
MBueschelberger Dec 17, 2024
00999e4
bump dev version
MBueschelberger Dec 17, 2024
3893290
fix minor problems
MBueschelberger Dec 17, 2024
ae25109
remove 'NumericalDatatype', debug unit converion
MBueschelberger Dec 18, 2024
69ba134
bump dev version
MBueschelberger Dec 18, 2024
9738986
debug type check in entry
MBueschelberger Dec 18, 2024
75ff828
bump version
MBueschelberger Dec 18, 2024
0a40c39
debug serialization
MBueschelberger Dec 18, 2024
3cc313a
update webform and custom properties aliases
MBueschelberger Dec 18, 2024
a666346
bump version
MBueschelberger Dec 18, 2024
c2170f6
remove unneeded union
MBueschelberger Dec 18, 2024
7e83491
move function to sectionize metadata to sdk
MBueschelberger Dec 19, 2024
8871d71
bump version
MBueschelberger Dec 19, 2024
5eaf2aa
add pagination for kitem list and search
MBueschelberger Jan 8, 2025
a1db259
support pagination
MBueschelberger Jan 9, 2025
1f76b49
fix pylint
MBueschelberger Jan 9, 2025
02533c1
make relation iri optional
MBueschelberger Jan 9, 2025
8ca1ab8
do validation of kitems in the custom property fields of type kitem
MBueschelberger Jan 13, 2025
c522aa0
debug custom properties validation
MBueschelberger Jan 16, 2025
4434317
udpate comment and remove unneeded pytest
MBueschelberger Jan 16, 2025
8ae52f3
debug provided unit spec from ktype
MBueschelberger Jan 17, 2025
3581927
debug range options
MBueschelberger Jan 17, 2025
2fa9940
update docs
MBueschelberger Jan 17, 2025
7f3ae64
udpate docs
MBueschelberger Jan 17, 2025
74e5a8f
remove unneeded context reference
MBueschelberger Jan 17, 2025
065c356
move cls of properties to self globally
MBueschelberger Jan 20, 2025
d584b83
make ktype_id strictly a str
MBueschelberger Jan 20, 2025
7a9556f
update README
MBueschelberger Jan 20, 2025
0994005
add compability matrix and bump version manually
MBueschelberger Jan 20, 2025
33501b3
add blank space into matrix
MBueschelberger Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update webform and custom properties aliases
MBueschelberger committed Dec 18, 2024
commit 3cc313afce6094ce376906bcb871dd6ba8a3fa1b
2 changes: 1 addition & 1 deletion dsms/knowledge/properties/attachments.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ class Attachment(KItemProperty):
)

content: Optional[Union[str, bytes]] = Field(
None, description="Content of the file"
None, description="Content of the file", exclude=True
)

# OVERRIDE
21 changes: 8 additions & 13 deletions dsms/knowledge/utils.py
Original file line number Diff line number Diff line change
@@ -181,6 +181,7 @@ def _update_ktype(ktype: "KType") -> Response:
"""Update a KType in the remote backend."""
payload = ktype.model_dump(
exclude_none=True,
by_alias=True,
)
logger.debug("Update KType for `%s` with body: %s", ktype.id, payload)
response = _perform_request(
@@ -306,15 +307,9 @@ def _update_kitem(new_kitem: "KItem", old_kitem: "Dict[str, Any]") -> Response:
**differences,
)
if new_kitem.custom_properties:
custom_properties = new_kitem.custom_properties.model_dump()
# # a smarted detection whether the custom properties were updated is needed
# old_properties = old_kitem.get("custom_properties")
# if isinstance(old_properties, dict):
# old_custom_properties = old_properties.get("content")
# else:
# old_custom_properties = None
# if custom_properties != old_custom_properties:
# payload.update(custom_properties={"content": custom_properties})
custom_properties = new_kitem.custom_properties.model_dump(
by_alias=True
)
payload.update(custom_properties={"content": custom_properties})
logger.debug(
"Update KItem for `%s` with payload: %s", new_kitem.id, payload
@@ -957,13 +952,13 @@ def _map_data_type_to_widget(value):
from dsms.knowledge.webform import Widget

if isinstance(value, str):
widget = Widget.TEXT
widget = Widget.TEXT.value
elif isinstance(value, (int, float)):
widget = Widget.NUMBER
widget = Widget.NUMBER.value
elif isinstance(value, bool):
widget = Widget.CHECKBOX
widget = Widget.CHECKBOX.value
elif isinstance(value, list):
widget = Widget.MULTI_SELECT
widget = Widget.MULTI_SELECT.value
else:
raise ValueError(
f"Unsupported data type: {type(value)}. Value: {value}"
104 changes: 24 additions & 80 deletions dsms/knowledge/webform.py
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@
BaseModel,
ConfigDict,
Field,
model_serializer,
model_validator,
AliasGenerator,
AliasChoices,
)

@@ -147,11 +147,18 @@ class BaseWebformModel(BaseModel):
"""Base webform model"""

model_config = ConfigDict(
alias_generator=lambda field_name: to_camel( # pylint: disable=W0108
field_name
alias_generator=AliasGenerator(
validation_alias=lambda field_name: AliasChoices(
to_camel(field_name), field_name # pylint: disable=W0108
),
serialization_alias=lambda field_name: to_camel( # pylint: disable=W0108
field_name
),
),
exclude={"kitem"},
use_enum_values=True,
)

kitem: Optional[Any] = Field(
None, description="Associated KItem instance", exclude=True, hide=True
)
@@ -252,25 +259,6 @@ def __repr__(self) -> str:
"""Pretty print the model fields"""
return str(self)

@model_serializer
def serialize(self) -> Dict[str, Any]:
"""
Serialize the Input object to a dictionary representation.

This method transforms the Input instance into a dictionary, where the keys
are the attribute names and the values are the corresponding attribute values.
The "type" attribute is treated specially by storing its `value` instead of
the object itself.

Returns:
Dict[str, Any]: A dictionary representation of the Input object.
"""
return {
key: (value.value if isinstance(value, Enum) else value)
for key, value in self.__dict__.items()
if key not in self.model_config["exclude"]
}


class Input(BaseWebformModel):
"""Input fields in the sections in webform"""
@@ -308,25 +296,6 @@ class Input(BaseWebformModel):
None, description="Placeholder for the input"
)

@model_serializer
def serialize(self) -> Dict[str, Any]:
"""
Serialize the Input object to a dictionary representation.

This method transforms the Input instance into a dictionary, where the keys
are the attribute names and the values are the corresponding attribute values.
The "type" attribute is treated specially by storing its `value` instead of
the object itself.

Returns:
Dict[str, Any]: A dictionary representation of the Input object.
"""
return {
key: (value.value if isinstance(value, Enum) else value)
for key, value in self.__dict__.items()
if key not in self.model_config["exclude"]
}

def __str__(self) -> str:
"""Pretty print the model fields"""
return print_model(self, "input")
@@ -464,16 +433,10 @@ class Entry(BaseWebformModel):
measurement_unit: Optional[MeasurementUnit] = Field(
None,
description="Measurement unit of the entry",
alias=AliasChoices(
"measurementUnit", "measurement_unit", "measurementunit"
),
)
relation_mapping: Optional[RelationMapping] = Field(
None,
description="Relation mapping of the entry",
alias=AliasChoices(
"relationMapping", "relation_mapping", "relationmapping"
),
)
required: Optional[bool] = Field(False, description="Required input")

@@ -579,27 +542,31 @@ def _validate_inputs(cls, self: "Entry") -> "Entry":

# check if widget is mapped to a data type
if self.type in (
Widget.TEXT,
Widget.FILE,
Widget.TEXTAREA,
Widget.VOCABULARY_TERM,
Widget.TEXT.value,
Widget.FILE.value,
Widget.TEXTAREA.value,
Widget.VOCABULARY_TERM.value,
):
dtype = str
elif self.type in (Widget.NUMBER, Widget.SLIDER):
elif self.type in (Widget.NUMBER.value, Widget.SLIDER.value):
dtype = (int, float)
elif self.type == Widget.CHECKBOX:
elif self.type == Widget.CHECKBOX.value:
dtype = bool
elif self.type in (Widget.SELECT, Widget.RADIO, Widget.MULTI_SELECT):
if self.type == Widget.MULTI_SELECT:
elif self.type in (
Widget.SELECT.value,
Widget.RADIO.value,
Widget.MULTI_SELECT.value,
):
if self.type == Widget.MULTI_SELECT.value:
dtype = list
else:
dtype = str
choices = [choice.value for choice in select_options]
elif self.type == Widget.KNOWLEDGE_ITEM:
elif self.type == Widget.KNOWLEDGE_ITEM.value:
dtype = KnowledgeItemReference
else:
raise ValueError(
f"Widget type is not mapped to a data type: {self.widget}"
f"Widget type is not mapped to a data type: {self.type}"
)

# check if value is set
@@ -628,29 +595,6 @@ def _validate_inputs(cls, self: "Entry") -> "Entry":

return self

@model_serializer
def serialize(self) -> Dict[str, Any]:
"""
Serialize the Entry object to a dictionary representation.

This method transforms the Entry instance into a dictionary, where the keys
are the attribute names and the values are the corresponding attribute values.
The "type" attribute is treated specially by storing its `value` instead of
the object itself.

Returns:
Dict[str, Any]: A dictionary representation of the Entry object.
"""
dumped = {}
for key, value in self.__dict__.items():
if key != "kitem":
if key == "type":
value = value.value
if key in ("measurement_unit", "relation_mapping"):
key = to_camel(key)
dumped[key] = value
return dumped

@classmethod
def _get_input_spec(cls, self: "Entry"):
spec = []