diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ac86e6..fa03400 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,10 +21,10 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python 3.11 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }} diff --git a/apis_core/apis_entities/management/commands/fetch_images.py b/apis_core/apis_entities/management/commands/fetch_images.py index b1a5491..0e77424 100644 --- a/apis_core/apis_entities/management/commands/fetch_images.py +++ b/apis_core/apis_entities/management/commands/fetch_images.py @@ -10,7 +10,7 @@ from apis_core.apis_entities.models import Person from dumper.utils import write_report -warnings.filterwarnings('ignore') +warnings.filterwarnings("ignore") class Command(BaseCommand): diff --git a/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html b/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html index e05712c..e481a2f 100644 --- a/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html +++ b/apis_core/apis_entities/templates/apis_entities/detail_views/entity_detail_generic.html @@ -62,7 +62,12 @@

{% if object.img_url %}
Bild von {{ object }} + {% if object.img_credit %} +
{{ object.img_credit }}
+ {% endif %}
+ + {% endif %} {% block info-table %} diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py index ed1bdc9..f326fa9 100644 --- a/apis_core/apis_entities/tests.py +++ b/apis_core/apis_entities/tests.py @@ -370,3 +370,8 @@ 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()) + + def test_027_img_credit(self): + entity = import_from_normdata("https://www.wikidata.org/wiki/Q76483", "person") + self.assertIsNone(entity.img_credit()) diff --git a/apis_core/apis_metainfo/migrations/0004_tempentityclass_img_last_checked_and_more.py b/apis_core/apis_metainfo/migrations/0004_tempentityclass_img_last_checked_and_more.py index e9fd600..cc2eb9b 100644 --- a/apis_core/apis_metainfo/migrations/0004_tempentityclass_img_last_checked_and_more.py +++ b/apis_core/apis_metainfo/migrations/0004_tempentityclass_img_last_checked_and_more.py @@ -13,8 +13,10 @@ class Migration(migrations.Migration): model_name="tempentityclass", name="img_last_checked", field=models.DateTimeField( - blank=True, null=True, verbose_name="geprüft am", - help_text="Datum an dem die Bild-URL eingetragen wurde." + blank=True, + null=True, + verbose_name="geprüft am", + help_text="Datum an dem die Bild-URL eingetragen wurde.", ), ), migrations.AddField( diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index 1524d81..ef19c6c 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -155,6 +155,13 @@ def fetch_image(self): self.save() return self + def img_credit(self): + credit = None + if self.img_url is not None: + if "commons.wikimedia.org/w/index" in self.img_url: + credit = "Wikimedia Commons" + return credit + @classmethod def get_listview_url(self): entity = self.__name__.lower() diff --git a/issue__112_fix_image_urls.ipynb b/issue__112_fix_image_urls.ipynb new file mode 100644 index 0000000..9d5176a --- /dev/null +++ b/issue__112_fix_image_urls.ipynb @@ -0,0 +1,81 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "eda7419e", + "metadata": {}, + "outputs": [], + "source": [ + "from urllib.parse import quote\n", + "from acdh_wikidata_pyutils import URL_STUB\n", + "from tqdm.notebook import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f03b29bb", + "metadata": {}, + "outputs": [], + "source": [ + "items = TempEntityClass.objects.filter(img_url__icontains=\"width\").filter(img_url__icontains=\"commons.wikimedia.org/w/index\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e8e31fb5", + "metadata": {}, + "outputs": [], + "source": [ + "items.count()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8ec94f95", + "metadata": {}, + "outputs": [], + "source": [ + "for x in tqdm(items, total=len(items)):\n", + " img_name = x.img_url.split('/')[-1].split('&')[0]\n", + " new_url = URL_STUB.format(quote(img_name))\n", + " if len(new_url) > 300:\n", + " new_url = None\n", + " x.img_url = new_url\n", + " x.save()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "454dd98d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Django Shell-Plus", + "language": "python", + "name": "django_extensions" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/requirements.txt b/requirements.txt index ab6f1b6..c1bcbaa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ acdh-django-browsing acdh_geonames_utils acdh-id-reconciler>=0.2,<1 acdh-tei-pyutils>=0.34,<1 -acdh-wikidata-pyutils>=0.5,<1 +acdh-wikidata-pyutils==1.0 apis-override-select2js==0.1 Django>4.1,<6 django-admin-csvexport diff --git a/set_env_variables.sh b/set_env_variables.sh index e0a3156..77758e8 100644 --- a/set_env_variables.sh +++ b/set_env_variables.sh @@ -1 +1 @@ -export $(grep -v '^#' .env | xargs) \ No newline at end of file +export $(grep -v '^#' .secret | xargs) \ No newline at end of file