Skip to content

Commit

Permalink
feat: Introduce new Object parent class
Browse files Browse the repository at this point in the history
This is because Bestand and Informatieobject (will) share similar logic.
  • Loading branch information
rien333 committed Dec 5, 2024
1 parent 6f677bb commit 606429a
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions mdto/mdto.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,30 @@ def to_xml(self) -> ET.Element:
return root


# TODO: this should be a subclass of a general object class
@dataclass
class Object:
"""https://www.nationaalarchief.nl/archiveren/mdto/object
This class serves as the parent class to Informatieobject and Bestand.
Hence, there is generally little reason to use it directly.
MDTO objects that derive from this class have a save() method, which can be used
to write an Informatieobject/Bestand to a XML file.
"""
naam: str
identificatie: IdentificatieGegevens

def __post_init__(self):
# check if name is of the right length
if len(self.naam) > MAX_NAAM_LENGTH:
_warn(
f"value '{self.naam}' of element 'naam' "
f"exceeds maximum length of {MAX_NAAM_LENGTH}."
)

# TODO: place more restrictions on taal?
@dataclass
class Informatieobject:
class Informatieobject(Object):
"""https://www.nationaalarchief.nl/archiveren/mdto/informatieobject
Example:
Expand Down Expand Up @@ -693,7 +713,7 @@ def to_xml(self) -> ET.ElementTree:


@dataclass
class Bestand:
class Bestand(Object):
"""https://www.nationaalarchief.nl/archiveren/mdto/bestand
Note:
Expand All @@ -718,15 +738,6 @@ class Bestand:
isRepresentatieVan: VerwijzingGegevens
URLBestand: str = None

def __post_init__(self):
# check if name is of the right length
# the getter and setter created weird errors
if len(self.naam) > MAX_NAAM_LENGTH:
_warn(
f"value '{self.naam}' of element 'naam' "
f"exceeds maximum length of {MAX_NAAM_LENGTH}."
)

def to_xml(self) -> ET.ElementTree:
"""
Transform Bestand into an XML tree with the following structure:
Expand Down

0 comments on commit 606429a

Please sign in to comment.