Skip to content

Commit

Permalink
revise lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Sep 10, 2024
1 parent 363aedb commit 066b816
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion frontend/animal/EndpointForm/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EndpointFormStore {

@action.bound
endpointNameLookup(val) {
const url = `/vocab/api/${val}/endpoint-name-lookup/`;
const url = this.config.vocabulary_api.replace("9999", val);

if (!val) {
return;
Expand Down
8 changes: 5 additions & 3 deletions hawc/apps/animal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
tryParseInt,
)
from ..study.models import Study
from ..vocab.constants import VocabularyNamespace
from ..vocab.models import Term
from . import constants, managers

Expand Down Expand Up @@ -806,11 +807,12 @@ def unique_items(els):

@classmethod
def get_vocabulary_settings(cls, assessment: Assessment, form: ModelForm) -> str:
vocab = VocabularyNamespace(assessment.vocabulary) if assessment.vocabulary else None
return json.dumps(
{
"vocabulary": assessment.vocabulary,
"vocabulary_url": assessment.get_vocabulary_url(),
"vocabulary_display": assessment.get_vocabulary_display(),
"vocabulary": vocab.value if vocab else None,
"vocabulary_api": vocab.api_root if vocab else None,
"vocabulary_display": vocab.display_name if vocab else None,
"object": {
"system": form["system"].value() or "",
"organ": form["organ"].value() or "",
Expand Down
33 changes: 20 additions & 13 deletions hawc/apps/vocab/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db.models import IntegerChoices
from django.urls import reverse_lazy
from django.utils.functional import classproperty
from django.urls import reverse


class VocabularyNamespace(IntegerChoices):
Expand All @@ -12,25 +11,33 @@ class VocabularyNamespace(IntegerChoices):
EHV = 1, "EHV"
ToxRefDB = 2, "ToxRefDB"

@classproperty
def display_dict(cls) -> dict:
return {1: "EPA Environmental health vocabulary", 2: "EPA ToxRefDB vocabulary"}

@classproperty
def display_urls(cls) -> dict:
return {1: reverse_lazy("vocab:ehv-browse"), 2: reverse_lazy("vocab:toxrefdb-browse")}

@classmethod
def display_choices(cls) -> list:
return [(key, value) for key, value in cls.display_dict.items()]
return [(item, item.display_name) for item in cls]

@property
def api_root(self) -> str:
match self:
case self.EHV:
return reverse("vocab:api:ehv-endpoint-name-lookup", args=(9999,))
case self.ToxRefDB:
return reverse("vocab:api:toxrefdb-endpoint-name-lookup", args=(9999,))

@property
def display_url(self) -> str:
return self.display_urls[self.value].lower()
match self:
case self.EHV:
return reverse("vocab:ehv-browse")
case self.ToxRefDB:
return reverse("vocab:toxrefdb-browse")

@property
def display_name(self) -> str:
return self.display_dict[self.value]
match self:
case self.EHV:
return "EPA Environmental health vocabulary"
case self.ToxRefDB:
return "EPA ToxRefDB vocabulary"


class VocabularyTermType(IntegerChoices):
Expand Down

0 comments on commit 066b816

Please sign in to comment.