Skip to content

Commit

Permalink
fix: Allow missing dates from jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Nov 7, 2024
1 parent a473854 commit 8ef856f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion data_registry/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ msgstr "Лицензия"

#: data_registry/templates/detail.html:155
msgid "Publication policy:"
msgstr "Политика публикации:"
msgstr "Политика публикации данных:"

#: data_registry/templates/detail.html:163
#: data_registry/templates/search.html:159
Expand Down
4 changes: 3 additions & 1 deletion data_registry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def detail(request, pk):
}

if job:
dataset["temporalCoverage"] = f"{job.date_from.strftime('%Y-%m-%d')}/{job.date_to.strftime('%Y-%m-%d')}"
dataset["temporalCoverage"] = "/".join(
date.strftime("%Y-%m-%d") if date else ".." for date in (job.date_from, job.date_to)
)

if language := collection.language:
dataset["inLanguage"] = language
Expand Down
11 changes: 9 additions & 2 deletions tests/data_registry/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setUpTestData(cls):
)
cls.collection2.active_job = cls.collection2.job_set.create(
date_from=datetime.date(2010, 2, 1),
date_to=datetime.date(2023, 9, 30),
date_to=None,
)
cls.collection2.save()

Expand Down Expand Up @@ -99,6 +99,13 @@ def test_detail(self, get_files):
response, f"""<a href="{url}" rel="nofollow" data-event="jsonl.gz year" download>2022</a>""", html=True
)

def test_detail_missing_date(self):
with self.assertNumQueries(2):
response = Client().get(f"/en/publication/{self.collection2.id}")

self.assertTemplateUsed("detail.html")
self.assertContains(response, '"temporalCoverage": "2010-02-01/..",')

def test_collection_not_found(self):
with self.assertNumQueries(1):
response = Client().get("/en/publication/10/download?name=2000.jsonl.gz")
Expand Down Expand Up @@ -199,7 +206,7 @@ def test_publications_api(self):
"last_retrieved": "2001-02-03",
"frozen": False,
"date_from": "2010-02-01",
"date_to": "2023-09-30",
"date_to": None,
},
{
"id": self.collection_no_files.id,
Expand Down

0 comments on commit 8ef856f

Please sign in to comment.