Skip to content

Commit

Permalink
Merge pull request #54 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
closes #111
  • Loading branch information
csae8092 authored Jan 24, 2024
2 parents 20b5026 + 746d45a commit b9bd204
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h4 class="text-left">
<div class="text-center p-3">
<img src="{{ object.img_url }}" class="rounded" alt="Bild von {{ object }}" style="height: 200px">
{% if object.img_credit %}
<figcaption class="figure-caption"><a href="{{ object.img_url }}">{{ object.img_credit }}</a></figcaption>
<figcaption class="figure-caption"><a href="{{ object.img_credit }}">{{ object.img_credit_label }}</a></figcaption>
{% endif %}
</div>

Expand Down
4 changes: 3 additions & 1 deletion apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,10 @@ def test_026_fetch_image(self):
entity = import_from_normdata(grillparzer, "person")
entity.fetch_image()
self.assertTrue(entity.img_url)
self.assertTrue("Wikimedia Commons" in entity.img_credit())
self.assertTrue("Wikimedia Commons" in entity.img_credit_label())
self.assertTrue("File:" in entity.img_credit())

def test_027_img_credit(self):
entity = import_from_normdata("https://www.wikidata.org/wiki/Q76483", "person")
self.assertIsNone(entity.img_credit())
self.assertIsNone(entity.img_credit_label())
10 changes: 9 additions & 1 deletion apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ def fetch_image(self):
def img_credit(self):
credit = None
if self.img_url is not None:
img_name = self.img_url.split("/")[-1]
if "commons.wikimedia.org/w/index" in self.img_url:
credit = "Wikimedia Commons"
credit = f"https://commons.wikimedia.org/wiki/File:{img_name}"
return credit

def img_credit_label(self):
credit = None
if self.img_url is not None:
if "commons.wikimedia.org/w/index" in self.img_url:
return "Wikimedia Commons"
return credit

@classmethod
Expand Down

0 comments on commit b9bd204

Please sign in to comment.