diff --git a/kerrokantasi/management/__init__.py b/kerrokantasi/management/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/kerrokantasi/management/commands/__init__.py b/kerrokantasi/management/commands/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/kerrokantasi/management/commands/convert_ckeditor_uploads.py b/kerrokantasi/management/commands/convert_ckeditor_uploads.py deleted file mode 100644 index 7f445093..00000000 --- a/kerrokantasi/management/commands/convert_ckeditor_uploads.py +++ /dev/null @@ -1,127 +0,0 @@ -import os -import re -from collections import namedtuple -from django.conf import settings -from django.core.management.base import BaseCommand -from django.urls import reverse - -from democracy.models import Section, SectionFile, SectionImage - - -class UploadedFile(namedtuple("UploadedFile", "url, year, month, day, filename")): - @property - def path(self): - return os.path.join(settings.MEDIA_ROOT, "uploads", self.year, self.month, self.day, self.filename) - - -class Command(BaseCommand): - """ - Look at all section content trying to identify media files uploaded via ckeditor through the admin page. - Move all found files to the sendfile protected storage, create SectionFile objects for them and replace the - links in the section content with new download url. - - If the item is inside an image tag (not a link), - convert the item to section image instead and move to image storage. - """ - - CKEDITOR_UPLOAD_REGEX = r'(?P(\d+)/(?P\d+)/(?P\d+)/(?P[\w.\-]+))"' # noqa: E501 - - def add_arguments(self, parser): - parser.add_argument("--dry", action="store_true", help="Execute dry run") - parser.add_argument("--domain", default="https://api.hel.fi/kerrokantasi", help="Root URL of the service") - - def handle(self, **options): # noqa: C901 - self.dry_run = options.pop("dry", False) - self.domain = options.pop("domain") - self.regex = re.compile(self.CKEDITOR_UPLOAD_REGEX.format(self.domain)) - all_sections = Section.objects.all() - section_count = all_sections.count() - counter = 0 - moved_files = {} # mapping of parsed urls to sectionfiles - for section in all_sections: - counter += 1 - self.stdout.write("Section [{}/{}]\n".format(counter, section_count)) - for translation in section.translations.all(): - for match in self.regex.finditer(translation.content): - uploaded_file = UploadedFile( - match.group(3), - match.group("year"), - match.group("month"), - match.group("day"), - match.group("filename"), - ) - if os.path.exists(uploaded_file.path) and match.group("tag").startswith(" {}\n".format(translation.language_code, uploaded_file.url, new_url) - ) - if not self.dry_run: - translation.save()