diff --git a/commons_api/wikidata/templates/wikidata/country_detail.html b/commons_api/wikidata/templates/wikidata/country_detail.html index 23aa90c..14c9447 100644 --- a/commons_api/wikidata/templates/wikidata/country_detail.html +++ b/commons_api/wikidata/templates/wikidata/country_detail.html @@ -10,6 +10,9 @@ {% if country.iso_3166_1_code %} {% endif %} + {% if country.geoshape_url %} + + {% endif %} {% endblock %} diff --git a/commons_api/wikidata/tests/geoshape.py b/commons_api/wikidata/tests/geoshape.py index 8debb55..d981351 100644 --- a/commons_api/wikidata/tests/geoshape.py +++ b/commons_api/wikidata/tests/geoshape.py @@ -82,3 +82,15 @@ def testWithLastModified(self, requests_get): requests_get.called_once_with(geoshape_url, headers={'If-Modified-Since': 'Fri, 25 May 2018 14:44:24 GMT'}) # Has done nothing, because it assumes a current boundary is up to date self.assertEqual(0, Boundary.objects.count()) + + @unittest.mock.patch('commons_api.wikidata.tasks.refresh_geoshape') + def testPostCountry(self, refresh_geoshape): + queued_at = timezone.now() + geoshape_url = 'http://example.org/some/geoshape.map' + country = models.Country.objects.create(id='Q142', + refresh_geoshape_last_queued=queued_at, + geoshape_url=geoshape_url) + response = self.client.post('/country/Q142', {'refresh-geoshape': None}) + country.refresh_from_db() + refresh_geoshape.delay.assert_called_once_with('wikidata', 'country', 'Q142', + queued_at=country.refresh_geoshape_last_queued) diff --git a/commons_api/wikidata/views.py b/commons_api/wikidata/views.py index 0e9948d..fa75dc2 100644 --- a/commons_api/wikidata/views.py +++ b/commons_api/wikidata/views.py @@ -53,6 +53,16 @@ def post(self, request, *args, **kwargs): messages.info(request, "Boundaries for {} will " "be refreshed".format(self.object)) + if 'refresh-geoshape' in request.POST: + from commons_api.wikidata.tasks import refresh_geoshape + from django.contrib.contenttypes.models import ContentType + last_queued = timezone.now() + self.model.objects.filter(pk=self.object.pk).update(refresh_geoshape_last_queued=last_queued) + ct = ContentType.objects.get_for_model(self.model) + refresh_geoshape.delay(ct.app_label, ct.model, self.object.id, queued_at=last_queued) + messages.info(request, "Getting boundary from wikidata " + "for {}".format(self.object)) + return redirect(self.object.get_absolute_url())