diff --git a/Seeder/source/forms.py b/Seeder/source/forms.py index 2610f68f..b03c473b 100755 --- a/Seeder/source/forms.py +++ b/Seeder/source/forms.py @@ -95,6 +95,13 @@ class Meta: class SeedEdit(forms.ModelForm): + def clean_url(self): + """ Ensure URL is stripped of whitespace even in older browsers """ + url = self.cleaned_data["url"] + if isinstance(url, str): + url = url.strip() + return url + class Meta: model = models.Seed exclude = ['source', 'active'] diff --git a/Seeder/source/migrations/0007_strip_seed_urls_20240718_0951.py b/Seeder/source/migrations/0007_strip_seed_urls_20240718_0951.py new file mode 100644 index 00000000..dfc9a77a --- /dev/null +++ b/Seeder/source/migrations/0007_strip_seed_urls_20240718_0951.py @@ -0,0 +1,26 @@ +# Generated by Django 2.2.28 on 2024-07-18 09:51 + +from django.db import migrations + +def strip_old_seed_urls(apps, schema_editor): + """ Strip spaces from Seed URLs with leading/trailing whitespace """ + Seed = apps.get_model("source", "Seed") + for seed in Seed.objects.filter(url__contains=" "): + seed.url = seed.url.strip() + seed.save() + +def reverse_strip_old_seed_urls(apps, schema_editor): + """ I'm not adding spaces back to Seed urls... """ + pass + + +class Migration(migrations.Migration): + + dependencies = [ + ('source', '0006_auto_20220826_1306'), + ] + + operations = [ + migrations.RunPython(strip_old_seed_urls, + reverse_code=reverse_strip_old_seed_urls), + ]