Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: identify temporary text values with UUID instead of text ha…
- Loading branch information
1 parent
1e2c8f2
commit 08624b2
Showing
8 changed files
with
192 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from dsp_tools.models.value import KnoraStandoffXml | ||
from dsp_tools.models.xmlresource import XMLResource | ||
|
||
|
||
@dataclass(frozen=True) | ||
class StandoffStashItem: | ||
""" | ||
Holds information about a single stashed XML text value. | ||
""" | ||
|
||
uuid: str | ||
prop_name: str | ||
value: KnoraStandoffXml | ||
# Permissions missing still | ||
|
||
|
||
@dataclass(frozen=True) | ||
class StandoffStash: | ||
""" | ||
Holds information about a number of stashed XML text values, organized by resource instance. | ||
""" | ||
|
||
res_2_stash_items: dict[str, list[StandoffStashItem]] | ||
res_2_xmlres: dict[str, XMLResource] | ||
|
||
@staticmethod | ||
def make(tups: list[tuple[XMLResource, StandoffStashItem]]) -> StandoffStash | None: | ||
""" | ||
Factory method for StandoffStash. | ||
Args: | ||
tups: A list of tuples of XMLResource and StandoffStashItem. | ||
Returns: | ||
StandoffStash | None: A StandoffStash object or None, if an empty list was passed. | ||
""" | ||
if not tups: | ||
return None | ||
res_2_stash_items = {} | ||
res_2_xmlres = {} | ||
for xmlres, stash_item in tups: | ||
if xmlres.id not in res_2_stash_items: | ||
res_2_stash_items[xmlres.id] = [stash_item] | ||
res_2_xmlres[xmlres.id] = xmlres | ||
else: | ||
res_2_stash_items[xmlres.id].append(stash_item) | ||
return StandoffStash(res_2_stash_items, res_2_xmlres) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.