Skip to content

Commit

Permalink
feat: align with datatracker StreamName (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks authored Aug 9, 2024
1 parent dcb5a7a commit 46031f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 10 additions & 2 deletions rpc/dt_v1_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class NoSuchSlug(Exception):
pass


def datatracker_stdlevelname(slug: str) -> tuple[str, str, str]:
def datatracker_name(namemodel: str, slug: str) -> tuple[str, str, str]:
try:
response = requests.get(
f"{settings.DATATRACKER_API_V1_BASE}/name/stdlevelname?fmt=json&slug={slug}"
f"{settings.DATATRACKER_API_V1_BASE}/name/{namemodel}?fmt=json&slug={slug}"
)
except requests.exceptions.ConnectionError:
raise DatatrackerFetchFailure
Expand All @@ -32,3 +32,11 @@ def datatracker_stdlevelname(slug: str) -> tuple[str, str, str]:
else:
obj = api_response["objects"][0]
return (obj["slug"], obj["name"], obj["desc"])


def datatracker_stdlevelname(slug: str) -> tuple[str, str, str]:
return datatracker_name("stdlevelname", slug)


def datatracker_streamname(slug: str) -> tuple[str, str, str]:
return datatracker_name("streamname", slug)
13 changes: 12 additions & 1 deletion rpc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DatatrackerFetchFailure,
NoSuchSlug,
datatracker_stdlevelname,
datatracker_streamname,
)
from simple_history.models import HistoricalRecords

Expand Down Expand Up @@ -184,9 +185,19 @@ class StdLevelName(Name):
class TlpBoilerplateChoiceName(Name):
pass

class StreamNameManager(models.Manager):
def from_slug(self, slug):
if self.filter(slug=slug).exists():
return self.get(slug=slug)
else:
try:
_, name, desc = datatracker_streamname(slug)
return self.create(slug=slug, name=name, desc=desc)
except (DatatrackerFetchFailure, NoSuchSlug):
raise self.model.DoesNotExist

class StreamName(Name):
pass
objects = StreamNameManager()


class DocRelationshipName(Name):
Expand Down

0 comments on commit 46031f3

Please sign in to comment.