Skip to content

Commit

Permalink
fix: ComposerInfo data export
Browse files Browse the repository at this point in the history
  • Loading branch information
sctop committed Apr 13, 2024
1 parent fecd4b7 commit 3964ece
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 58 deletions.
2 changes: 1 addition & 1 deletion data
Submodule data updated from 661682 to e74ea8
18 changes: 11 additions & 7 deletions data_model/actual_data/composer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections import OrderedDict

from ..loader import FileLoader
from .used_by import BaseUsedBy, UsedByRegisterMixin, OrderedDictWithCounter, UsedByToJsonMixin
from .used_by import BaseUsedBy, UsedByRegisterMixin, UsedByToJsonMixin
from ..constant.file_type import FILETYPES_TRACK
from ..tool.interpage import InterpageMixin
from ..types.url import UrlModel
Expand All @@ -8,10 +10,9 @@

class ComposerUsedBy(BaseUsedBy, UsedByToJsonMixin):
SUPPORTED_FILETYPE = [*FILETYPES_TRACK]
_components = ["data_track"]

def __init__(self):
self.data_track = OrderedDictWithCounter()
self.data_track = OrderedDict()

def register(self, file_loader: FileLoader, count_increase=True):
filetype = file_loader.filetype
Expand All @@ -20,11 +21,12 @@ def register(self, file_loader: FileLoader, count_increase=True):
if filetype in self.SUPPORTED_FILETYPE:
if filetype in FILETYPES_TRACK:
self.data_track[instance_id] = file_loader
if not count_increase:
self.data_track.counter_adjust(instance_id, -1)
else:
raise ValueError

def to_json(self, no_used_by: bool = True):
return {"data_track": [i.to_json_basic() for i in self.data_track.values()]}


class NameMasker(ObjectAccessProxier):
def __init__(self, obj: str):
Expand Down Expand Up @@ -68,9 +70,10 @@ def to_json(self):
d = {
"uuid": self.uuid,
"filetype": self.filetype,
"namespace": self.namespace,

"name": self.name.to_json(),
"namespace": self.namespace,
"no": self.no,
"realname": self.realname,
"nickname": self.nickname,
"intro": self.intro,
Expand All @@ -85,9 +88,10 @@ def to_json_basic(self):
d = {
"uuid": self.uuid,
"filetype": self.filetype,
"namespace": self.namespace,

"name": self.name.to_json(),
"namespace": self.namespace,
"no": self.no,
"realname": self.realname,
"nickname": self.nickname,
"intro": self.intro,
Expand Down
50 changes: 0 additions & 50 deletions data_model/actual_data/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,56 +322,6 @@ def to_json_basic(self):
return self.to_json()


class Composer(BaseDataModel, UsedByRegisterMixin):
"""
Defines a `composer` dict.
Note: This class implements irregular Singleton behaviour, in which when
you're loading the data, it might return an existing instance if
there's a match in either the `nickname` or `composer_id`.
"""
realname = String("realname")
nickname = String("nickname")
_components = ["composer_id", "realname", "nickname", "contact"]
_instance = {}

def __init__(self, key_name="composer"):
super().__init__(key_name)
self.contact = Contact()
self.used_by = ComposerUsedBy()

def load(self, value: dict):
self.composer_id = str(value.get("composer_id", ""))
if self.composer_id in self._instance.keys():
return self._instance[self.composer_id]

# If none is found, then it's the first time to create
# Check if the composer is auto-indexed
if value.get("composer_id", "") != "":
value = constant_manager.query("composer", value["composer_id"])
super().load(value)

self.realname = value["realname"]
self.nickname = value["nickname"]
self.contact.load(value["contact"])

self._instance[self.composer_id] = self

return self

def to_json(self):
return {"composer_id": self.composer_id,
"realname": self.realname,
"nickname": self.nickname,
"contact": self.contact.to_json_basic(),
"used_by": self.used_by.to_json_basic()}

def to_json_basic(self):
return {"composer_id": self.composer_id,
"nickname": self.nickname,
"contact": self.contact.to_json_basic()}


# -------------------------------------------------------

class TrackInfo(FileLoader, UsedByRegisterMixin, InterpageMixin, RelatedToRegisterMixin):
Expand Down

0 comments on commit 3964ece

Please sign in to comment.