From 3964ece920c830ba9ea27876c0bf769b88d8425c Mon Sep 17 00:00:00 2001 From: sctop <2094880085@qq.com> Date: Sat, 13 Apr 2024 21:52:34 +0800 Subject: [PATCH] fix: ComposerInfo data export --- data | 2 +- data_model/actual_data/composer.py | 18 ++++++----- data_model/actual_data/track.py | 50 ------------------------------ 3 files changed, 12 insertions(+), 58 deletions(-) diff --git a/data b/data index 6616821..e74ea84 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 661682144e89d030425b9fe3cff71f2c045d0556 +Subproject commit e74ea844b0735362ee07f252c323a50e0e0fbe22 diff --git a/data_model/actual_data/composer.py b/data_model/actual_data/composer.py index b1bccce..67d8e7f 100644 --- a/data_model/actual_data/composer.py +++ b/data_model/actual_data/composer.py @@ -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 @@ -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 @@ -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): @@ -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, @@ -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, diff --git a/data_model/actual_data/track.py b/data_model/actual_data/track.py index c98cae2..5705a08 100644 --- a/data_model/actual_data/track.py +++ b/data_model/actual_data/track.py @@ -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):