feat: added recursive structure
This commit is contained in:
@@ -115,13 +115,6 @@ class Collection(Generic[T]):
|
||||
self._data.append(other)
|
||||
other._inner._is_in_collection.add(self)
|
||||
|
||||
# all of the existing hooks to get the defined datastructures
|
||||
for collection_attribute, generator in self.extend_object_to_attribute.items():
|
||||
other.__getattribute__(collection_attribute).extend(generator, **kwargs)
|
||||
|
||||
for attribute, new_object in self.append_object_to_attribute.items():
|
||||
other.__getattribute__(attribute).append(new_object, **kwargs)
|
||||
|
||||
for attribute, a in self.sync_on_append.items():
|
||||
# syncing two collections by reference
|
||||
b = other.__getattribute__(attribute)
|
||||
@@ -141,6 +134,13 @@ class Collection(Generic[T]):
|
||||
|
||||
a.extend(b_data, **kwargs)
|
||||
|
||||
# all of the existing hooks to get the defined datastructures
|
||||
for collection_attribute, generator in self.extend_object_to_attribute.items():
|
||||
other.__getattribute__(collection_attribute).extend(generator, **kwargs)
|
||||
|
||||
for attribute, new_object in self.append_object_to_attribute.items():
|
||||
other.__getattribute__(attribute).append(new_object, **kwargs)
|
||||
|
||||
def append(self, other: Optional[T], **kwargs):
|
||||
"""
|
||||
If an object, that represents the same entity exists in a relevant collection,
|
||||
@@ -164,13 +164,13 @@ class Collection(Generic[T]):
|
||||
for c in self.push_to:
|
||||
r = c._find_object(other)
|
||||
if r is not None:
|
||||
# output("found push to", r, other, c, self, color=BColors.RED, sep="\t")
|
||||
output("found push to", r, other, c, self, color=BColors.RED, sep="\t")
|
||||
return c.append(other, **kwargs)
|
||||
|
||||
for c in self.pull_from:
|
||||
r = c._find_object(other)
|
||||
if r is not None:
|
||||
# output("found pull from", r, other, c, self, color=BColors.RED, sep="\t")
|
||||
output("found pull from", r, other, c, self, color=BColors.RED, sep="\t")
|
||||
c.remove(r, existing=r, **kwargs)
|
||||
|
||||
existing = self._find_object(other)
|
||||
|
||||
@@ -129,7 +129,7 @@ class Song(Base):
|
||||
source_list: List[Source] = None,
|
||||
target_list: List[Target] = None,
|
||||
lyrics_list: List[Lyrics] = None,
|
||||
main_artist_list: List[Artist] = None,
|
||||
artist_list: List[Artist] = None,
|
||||
feature_artist_list: List[Artist] = None,
|
||||
album_list: List[Album] = None,
|
||||
tracksort: int = 0,
|
||||
@@ -145,6 +145,9 @@ class Song(Base):
|
||||
TITEL = "title"
|
||||
|
||||
def __init_collections__(self) -> None:
|
||||
self.feature_artist_collection.push_to = [self.artist_collection]
|
||||
self.artist_collection.pull_from = [self.feature_artist_collection]
|
||||
|
||||
self.album_collection.sync_on_append = {
|
||||
"artist_collection": self.artist_collection,
|
||||
}
|
||||
@@ -156,14 +159,10 @@ class Song(Base):
|
||||
"album_collection": self.album_collection
|
||||
}
|
||||
|
||||
|
||||
self.album_collection.append_object_to_attribute = {
|
||||
"artist_collection": self
|
||||
}
|
||||
|
||||
self.feature_artist_collection.push_to = [self.artist_collection]
|
||||
self.artist_collection.pull_from = [self.feature_artist_collection]
|
||||
|
||||
def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]):
|
||||
if object_type is Song:
|
||||
return
|
||||
@@ -239,11 +238,6 @@ class Song(Base):
|
||||
return f"{self.tracksort}/{len(self.album_collection[0].song_collection) or 1}"
|
||||
|
||||
|
||||
"""
|
||||
All objects dependent on Album
|
||||
"""
|
||||
|
||||
|
||||
class Album(Base):
|
||||
title: str
|
||||
unified_title: str
|
||||
@@ -311,6 +305,9 @@ class Album(Base):
|
||||
UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection", "artist_collection")
|
||||
|
||||
def __init_collections__(self):
|
||||
self.feature_artist_collection.push_to = [self.artist_collection]
|
||||
self.artist_collection.pull_from = [self.feature_artist_collection]
|
||||
|
||||
self.song_collection.append_object_to_attribute = {
|
||||
"album_collection": self
|
||||
}
|
||||
@@ -515,7 +512,7 @@ class Artist(Base):
|
||||
source_list: List[Source] = None,
|
||||
contact_list: List[Contact] = None,
|
||||
feature_song_list: List[Song] = None,
|
||||
main_album_list: List[Album] = None,
|
||||
album_list: List[Album] = None,
|
||||
label_list: List[Label] = None,
|
||||
**kwargs
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user