Skip to content

Commit

Permalink
chore: Simplify logic, because either both or neither of date_from an…
Browse files Browse the repository at this point in the history
…d date_to are set
  • Loading branch information
jpmckinney committed Nov 7, 2024
1 parent 65e9d3c commit 5e389b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions data_registry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,8 @@ def detail(request, pk):
"dateModified": collection.modified.isoformat(),
}

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

if language := collection.language:
dataset["inLanguage"] = language
Expand Down
6 changes: 3 additions & 3 deletions tests/data_registry/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setUpTestData(cls):
public=True,
)
cls.collection2.active_job = cls.collection2.job_set.create(
date_from=datetime.date(2010, 2, 1),
date_from=None,
date_to=None,
)
cls.collection2.save()
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_detail_missing_date(self):
response = Client().get(f"/en/publication/{self.collection2.id}")

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

def test_collection_not_found(self):
with self.assertNumQueries(1):
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_publications_api(self):
"retrieval_frequency": "MONTHLY",
"last_retrieved": "2001-02-03",
"frozen": False,
"date_from": "2010-02-01",
"date_from": None,
"date_to": None,
},
{
Expand Down

0 comments on commit 5e389b4

Please sign in to comment.