Skip to content

Commit a5a408c

Browse files
committed
add TDAMM_TAG_CHOICES to collection_choice_fields
1 parent 13649ae commit a5a408c

File tree

3 files changed

+58
-48
lines changed

3 files changed

+58
-48
lines changed

sde_collections/admin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .models.collection import Collection, WorkflowHistory
99
from .models.pattern import DivisionPattern, IncludePattern, TitlePattern
1010
from .tasks import import_candidate_urls_from_api
11+
from .models.collection_choice_fields import TDAMMTags
1112

1213

1314
@admin.action(description="Generate deployment message")
@@ -267,14 +268,14 @@ def exclude_and_delete_children(modeladmin, request, queryset):
267268
class CandidateURLForm(forms.ModelForm):
268269
# Define the fields as MultipleChoiceFields with checkboxes
269270
tdamm_tag_manual = forms.MultipleChoiceField(
270-
choices=CandidateURL.TDAMM_TAG_CHOICES,
271+
choices=TDAMMTags.choices,
271272
required=False,
272273
label="TDAMM Manual Tags",
273274
widget=forms.CheckboxSelectMultiple,
274275
)
275276

276277
tdamm_tag_ml = forms.MultipleChoiceField(
277-
choices=CandidateURL.TDAMM_TAG_CHOICES,
278+
choices=TDAMMTags.choices,
278279
required=False,
279280
label="TDAMM ML Tags",
280281
widget=forms.CheckboxSelectMultiple,

sde_collections/models/candidate_url.py

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ..utils.paired_field_descriptor import PairedFieldDescriptor
99
from .collection import Collection
10-
from .collection_choice_fields import Divisions, DocumentTypes
10+
from .collection_choice_fields import Divisions, DocumentTypes, TDAMMTags
1111
from .pattern import ExcludePattern, TitlePattern
1212

1313

@@ -82,53 +82,9 @@ class CandidateURL(models.Model):
8282
help_text="Helps keep track if the Current URL is present in production or not",
8383
)
8484
is_tdamm = models.BooleanField("Is TDAMM?", default=False, help_text="Enable TDAMM tagging for this URL")
85-
86-
TDAMM_TAG_CHOICES = [
87-
("MMA_M_EM", "Messenger - EM Radiation"),
88-
("MMA_M_EM_G", "Messenger - EM Radiation - Gamma rays"),
89-
("MMA_M_EM_X", "Messenger - EM Radiation - X-rays"),
90-
("MMA_M_EM_U", "Messenger - EM Radiation - Ultraviolet"),
91-
("MMA_M_EM_O", "Messenger - EM Radiation - Optical"),
92-
("MMA_M_EM_I", "Messenger - EM Radiation - Infrared"),
93-
("MMA_M_EM_M", "Messenger - EM Radiation - Microwave"),
94-
("MMA_M_EM_R", "Messenger - EM Radiation - Radio"),
95-
("MMA_M_G", "Messenger - Gravitational Waves"),
96-
("MMA_M_G_CBI", "Messenger - Gravitational Waves - Compact Binary Inspiral"),
97-
("MMA_M_G_S", "Messenger - Gravitational Waves - Stochastic"),
98-
("MMA_M_G_CON", "Messenger - Gravitational Waves - Continuous"),
99-
("MMA_M_G_B", "Messenger - Gravitational Waves - Burst"),
100-
("MMA_M_C", "Messenger - Cosmic Rays"),
101-
("MMA_M_N", "Messenger - Neutrinos"),
102-
("MMA_O_BI", "Objects - Binaries"),
103-
("MMA_O_BI_BBH", "Objects - Binaries - Binary Black Holes"),
104-
("MMA_O_BI_BNS", "Objects - Binaries - Binary Neutron Stars"),
105-
("MMA_O_BI_C", "Objects - Binaries - Cataclysmic Variables"),
106-
("MMA_O_BI_N", "Objects - Binaries - Neutron Star-Black Hole"),
107-
("MMA_O_BI_B", "Objects - Binaries - Binary Pulsars"),
108-
("MMA_O_BI_W", "Objects - Binaries - White Dwarf Binaries"),
109-
("MMA_O_BH", "Objects - Black Holes"),
110-
("MMA_O_BH_AGN", "Objects - Black Holes - Active Galactic Nuclei"),
111-
("MMA_O_BH_IM", "Objects - Black Holes - Intermediate mass"),
112-
("MMA_O_BH_STM", "Objects - Black Holes - Stellar mass"),
113-
("MMA_O_BH_SUM", "Objects - Black Holes - Supermassive"),
114-
("MMA_O_E", "Objects - Exoplanets"),
115-
("MMA_O_N", "Objects - Neutron Stars"),
116-
("MMA_O_N_M", "Objects - Neutron Stars - Magnetars"),
117-
("MMA_O_N_P", "Objects - Neutron Stars - Pulsars"),
118-
("MMA_O_N_PWN", "Objects - Neutron Stars - Pulsar Wind Nebula"),
119-
("MMA_O_S", "Objects - Supernova Remnants"),
120-
("MMA_S_F", "Signals - Fast Radio Bursts"),
121-
("MMA_S_G", "Signals - Gamma-ray Bursts"),
122-
("MMA_S_K", "Signals - Kilonovae"),
123-
("MMA_S_N", "Signals - Novae"),
124-
("MMA_S_P", "Signals - Pevatrons"),
125-
("MMA_S_ST", "Signals - Stellar flares"),
126-
("MMA_S_SU", "Signals - Supernovae"),
127-
]
128-
12985
tdamm_tag = PairedFieldDescriptor(
13086
field_name="tdamm_tag",
131-
field_type=ArrayField(models.CharField(max_length=255, choices=TDAMM_TAG_CHOICES), blank=True, null=True),
87+
field_type=ArrayField(models.CharField(max_length=255, choices=TDAMMTags.choices), blank=True, null=True),
13288
switch="is_tdamm",
13389
verbose_name="TDAMM Tags",
13490
)

sde_collections/models/collection_choice_fields.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,56 @@ class WorkflowStatusChoices(models.IntegerChoices):
9797
PROD_MAJOR = 16, "Prod: Major Issues"
9898
MERGE_PENDING = 17, "Code Merge Pending"
9999
NEEDS_DELETE = 19, "Delete from Prod"
100+
101+
102+
class TDAMMTags(models.TextChoices):
103+
"""TDAMM (Tagged Data for Multi-Messenger Astronomy) tag choices."""
104+
105+
MMA_M_EM = "MMA_M_EM", "Messenger - EM Radiation"
106+
MMA_M_EM_G = "MMA_M_EM_G", "Messenger - EM Radiation - Gamma rays"
107+
MMA_M_EM_X = "MMA_M_EM_X", "Messenger - EM Radiation - X-rays"
108+
MMA_M_EM_U = "MMA_M_EM_U", "Messenger - EM Radiation - Ultraviolet"
109+
MMA_M_EM_O = "MMA_M_EM_O", "Messenger - EM Radiation - Optical"
110+
MMA_M_EM_I = "MMA_M_EM_I", "Messenger - EM Radiation - Infrared"
111+
MMA_M_EM_M = "MMA_M_EM_M", "Messenger - EM Radiation - Microwave"
112+
MMA_M_EM_R = "MMA_M_EM_R", "Messenger - EM Radiation - Radio"
113+
MMA_M_G = "MMA_M_G", "Messenger - Gravitational Waves"
114+
MMA_M_G_CBI = "MMA_M_G_CBI", "Messenger - Gravitational Waves - Compact Binary Inspiral"
115+
MMA_M_G_S = "MMA_M_G_S", "Messenger - Gravitational Waves - Stochastic"
116+
MMA_M_G_CON = "MMA_M_G_CON", "Messenger - Gravitational Waves - Continuous"
117+
MMA_M_G_B = "MMA_M_G_B", "Messenger - Gravitational Waves - Burst"
118+
MMA_M_C = "MMA_M_C", "Messenger - Cosmic Rays"
119+
MMA_M_N = "MMA_M_N", "Messenger - Neutrinos"
120+
MMA_O_BI = "MMA_O_BI", "Objects - Binaries"
121+
MMA_O_BI_BBH = "MMA_O_BI_BBH", "Objects - Binaries - Binary Black Holes"
122+
MMA_O_BI_BNS = "MMA_O_BI_BNS", "Objects - Binaries - Binary Neutron Stars"
123+
MMA_O_BI_C = "MMA_O_BI_C", "Objects - Binaries - Cataclysmic Variables"
124+
MMA_O_BI_N = "MMA_O_BI_N", "Objects - Binaries - Neutron Star-Black Hole"
125+
MMA_O_BI_B = "MMA_O_BI_B", "Objects - Binaries - Binary Pulsars"
126+
MMA_O_BI_W = "MMA_O_BI_W", "Objects - Binaries - White Dwarf Binaries"
127+
MMA_O_BH = "MMA_O_BH", "Objects - Black Holes"
128+
MMA_O_BH_AGN = "MMA_O_BH_AGN", "Objects - Black Holes - Active Galactic Nuclei"
129+
MMA_O_BH_IM = "MMA_O_BH_IM", "Objects - Black Holes - Intermediate mass"
130+
MMA_O_BH_STM = "MMA_O_BH_STM", "Objects - Black Holes - Stellar mass"
131+
MMA_O_BH_SUM = "MMA_O_BH_SUM", "Objects - Black Holes - Supermassive"
132+
MMA_O_E = "MMA_O_E", "Objects - Exoplanets"
133+
MMA_O_N = "MMA_O_N", "Objects - Neutron Stars"
134+
MMA_O_N_M = "MMA_O_N_M", "Objects - Neutron Stars - Magnetars"
135+
MMA_O_N_P = "MMA_O_N_P", "Objects - Neutron Stars - Pulsars"
136+
MMA_O_N_PWN = "MMA_O_N_PWN", "Objects - Neutron Stars - Pulsar Wind Nebula"
137+
MMA_O_S = "MMA_O_S", "Objects - Supernova Remnants"
138+
MMA_S_F = "MMA_S_F", "Signals - Fast Radio Bursts"
139+
MMA_S_G = "MMA_S_G", "Signals - Gamma-ray Bursts"
140+
MMA_S_K = "MMA_S_K", "Signals - Kilonovae"
141+
MMA_S_N = "MMA_S_N", "Signals - Novae"
142+
MMA_S_P = "MMA_S_P", "Signals - Pevatrons"
143+
MMA_S_ST = "MMA_S_ST", "Signals - Stellar flares"
144+
MMA_S_SU = "MMA_S_SU", "Signals - Supernovae"
145+
146+
@classmethod
147+
def lookup_by_text(cls, text: str) -> str | None:
148+
"""Look up a TDAMM tag by its display text."""
149+
for choice in cls.choices:
150+
if choice[1].lower() == text.lower():
151+
return choice[0]
152+
return None

0 commit comments

Comments
 (0)