Skip to content

Commit

Permalink
Commit all changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann committed Dec 19, 2024
1 parent 913b4f9 commit fec5d29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
18 changes: 0 additions & 18 deletions src/dsp_tools/xmllib/internal_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import warnings
from typing import Any

from lxml import etree

from dsp_tools.models.custom_warnings import DspToolsUserInfo
from dsp_tools.models.custom_warnings import DspToolsUserWarning
from dsp_tools.models.exceptions import InputError
from dsp_tools.xmllib.models.config_options import NewlineReplacement
from dsp_tools.xmllib.models.config_options import Permissions
from dsp_tools.xmllib.models.values import Richtext
from dsp_tools.xmllib.models.values import Value
from dsp_tools.xmllib.value_checkers import is_string_like
from dsp_tools.xmllib.value_converters import replace_newlines_with_tags

Expand Down Expand Up @@ -91,18 +88,3 @@ def check_and_fix_collection_input(value: Any, prop_name: str, res_id: str) -> l
raise InputError(msg)
case _:
return [value]


def serialise_values_of_the_same_property(values: list[Value]) -> etree._Element:
"""
Takes a list of values with the same property name and serialises them as one element.
Args:
values: List of values to serialise
Returns:
etree Element to add to the resource
"""
main_prop = values[0].make_prop()
main_prop.extend([prop.make_element() for prop in values])
return main_prop
9 changes: 3 additions & 6 deletions src/dsp_tools/xmllib/models/dsp_base_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from dsp_tools.models.exceptions import InputError
from dsp_tools.xmllib.internal_helpers import check_and_fix_collection_input
from dsp_tools.xmllib.internal_helpers import create_richtext_with_checks
from dsp_tools.xmllib.internal_helpers import serialise_values_of_the_same_property
from dsp_tools.xmllib.models.config_options import NewlineReplacement
from dsp_tools.xmllib.models.config_options import Permissions
from dsp_tools.xmllib.models.geometry import Circle
Expand Down Expand Up @@ -407,7 +406,7 @@ def serialise(self) -> etree._Element:
res_ele = self._serialise_resource_element()
res_ele.extend(self._serialise_geometry_shape())
if self.comments:
res_ele.append(serialise_values_of_the_same_property(cast(list[Value], self.comments)))
res_ele.extend(serialise_values(cast(list[Value], self.comments)))
return res_ele

def _serialise_resource_element(self) -> etree._Element:
Expand Down Expand Up @@ -649,10 +648,8 @@ def add_migration_metadata(
def serialise(self) -> etree._Element:
res_ele = self._serialise_resource_element()
self._final_checks()
if self.comments:
res_ele.append(serialise_values_of_the_same_property(cast(list[Value], self.comments)))
if self.link_to:
res_ele.append(serialise_values_of_the_same_property(cast(list[Value], self.link_to)))
generic_vals = self.comments + self.link_to
res_ele.extend(serialise_values(cast(list[Value], generic_vals)))
return res_ele

def _final_checks(self) -> None:
Expand Down

0 comments on commit fec5d29

Please sign in to comment.