From 7e78669c2a123c0094a92672864191c3529f3a66 Mon Sep 17 00:00:00 2001 From: Gytha Ogg Date: Mon, 15 Jul 2024 15:40:47 +0200 Subject: [PATCH] change rkts links from https to http closes #91 --- .../commands/change_rkts_links_to_http.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 apis_ontology/management/commands/change_rkts_links_to_http.py diff --git a/apis_ontology/management/commands/change_rkts_links_to_http.py b/apis_ontology/management/commands/change_rkts_links_to_http.py new file mode 100644 index 0000000..2e731b9 --- /dev/null +++ b/apis_ontology/management/commands/change_rkts_links_to_http.py @@ -0,0 +1,28 @@ +from django.core.management.base import BaseCommand + +from apis_ontology.models import Person, Place, Work, Instance + + +class Command(BaseCommand): + help = "Change https links in rkts links to http" + + def handle(self, *args, **options): + def convert_to_https(qs, entity_type=""): + for obj in qs: + obj.external_links = obj.external_links.replace("https://", "http://") + obj.save() + + self.stdout.write( + self.style.SUCCESS( + f"{len(qs)} {entity_type if entity_type else 'entities'} updated" + ) + ) + + http_persons = Person.objects.filter(external_links__contains="rkts") + convert_to_https(http_persons, "persons") + http_places = Place.objects.filter(external_links__contains="rkts") + convert_to_https(http_places, "places") + http_works = Work.objects.filter(external_links__contains="rkts") + convert_to_https(http_works, "works") + http_instances = Instance.objects.filter(external_links__contains="rkts") + convert_to_https(http_instances, "instances")