mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Dynamically generate enum for TaggableItemClass
This commit is contained in:
@@ -10,17 +10,13 @@ from pydantic import (
|
||||
)
|
||||
|
||||
from galaxy.managers.context import ProvidesUserContext
|
||||
from galaxy.model import ItemTagAssociation
|
||||
from galaxy.schema.fields import EncodedDatabaseIdField
|
||||
|
||||
|
||||
class TaggableItemClass(str, Enum):
|
||||
History = "History"
|
||||
HistoryDatasetAssociation = "HistoryDatasetAssociation"
|
||||
HistoryDatasetCollectionAssociation = "HistoryDatasetCollectionAssociation"
|
||||
LibraryDatasetDatasetAssociation = "LibraryDatasetDatasetAssociation"
|
||||
Page = "Page"
|
||||
StoredWorkflow = "StoredWorkflow"
|
||||
Visualization = "Visualization"
|
||||
taggable_item_names = {item: item for item in ItemTagAssociation.associated_item_names}
|
||||
# This Enum is generated dynamically and mypy can not statically infer it's real type
|
||||
# so it should be ignored. See:https://github.com/python/mypy/issues/4865#issuecomment-592560696
|
||||
TaggableItemClass = Enum('TaggableItemClass', taggable_item_names) # type: ignore
|
||||
|
||||
|
||||
class ItemTagsPayload(BaseModel):
|
||||
|
||||
@@ -19,7 +19,7 @@ from collections import defaultdict
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
from string import Template
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from typing import List, Optional, TYPE_CHECKING
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from boltons.iterutils import remap
|
||||
@@ -6350,6 +6350,11 @@ class Tag(RepresentById):
|
||||
class ItemTagAssociation(Dictifiable):
|
||||
dict_collection_visible_keys = ['id', 'user_tname', 'user_value']
|
||||
dict_element_visible_keys = dict_collection_visible_keys
|
||||
associated_item_names: List[str] = []
|
||||
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
super().__init_subclass__(**kwargs)
|
||||
cls.associated_item_names.append(cls.__name__.replace("TagAssociation", ""))
|
||||
|
||||
def __init__(self, id=None, user=None, item_id=None, tag_id=None, user_tname=None, value=None):
|
||||
self.id = id
|
||||
|
||||
@@ -7,7 +7,7 @@ from fastapi import (
|
||||
Body,
|
||||
status,
|
||||
)
|
||||
# TODO: replace with _router after merging #11219
|
||||
# TODO: replace with Router after merging #11219
|
||||
from fastapi_utils.cbv import cbv
|
||||
from fastapi_utils.inferring_router import InferringRouter as APIRouter
|
||||
|
||||
|
||||
Reference in New Issue
Block a user