Skip to content

Commit

Permalink
#660: add migration to remove trailing/leading whitespace from Seed u…
Browse files Browse the repository at this point in the history
…rls, ensure they get stripped in form
  • Loading branch information
Fasand committed Jul 18, 2024
1 parent f520bf4 commit fafff0a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Seeder/source/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
26 changes: 26 additions & 0 deletions Seeder/source/migrations/0007_strip_seed_urls_20240718_0951.py
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit fafff0a

Please sign in to comment.