From 9835df72a0ee5eb3b78bce4347b526e130a5881a Mon Sep 17 00:00:00 2001 From: Dirk Doesburg Date: Wed, 29 May 2024 18:42:46 +0200 Subject: [PATCH] Fix random fixtures crashes (#3693) --- .../migrations/0029_alter_partner_address.py | 26 +++++++++++++++++++ website/partners/models.py | 8 ++---- .../management/commands/createfixtures.py | 12 ++++++--- 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 website/partners/migrations/0029_alter_partner_address.py diff --git a/website/partners/migrations/0029_alter_partner_address.py b/website/partners/migrations/0029_alter_partner_address.py new file mode 100644 index 000000000..169a3ec9f --- /dev/null +++ b/website/partners/migrations/0029_alter_partner_address.py @@ -0,0 +1,26 @@ +# Generated by Django 5.0.2 on 2024-05-22 19:06 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("partners", "0028_alter_partner_alternate_logo_alter_partner_logo_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="partner", + name="address", + field=models.CharField( + max_length=100, + validators=[ + django.core.validators.RegexValidator( + message="Enter a valid address", + regex="^([^/@:;%_]+) \\d+([^/@:;%_]*)", + ) + ], + ), + ), + ] diff --git a/website/partners/models.py b/website/partners/models.py index 61cb299a3..e5038dc37 100644 --- a/website/partners/models.py +++ b/website/partners/models.py @@ -53,12 +53,8 @@ class Partner(models.Model): max_length=100, validators=[ RegexValidator( - regex=( - r"^([1-9][e][\s])*([ëéÉËa-zA-Z]" - r"+(([\.][\s])|([\s]))?)+[1-9][0-9]" - r"*(([-][1-9][0-9]*)|([\s]?[ëéÉËa-zA-Z]+))?$" - ), - message=_("Enter a valid address"), + regex=r"^([^/@:;%_]+) \d+([^/@:;%_]*)", + message="Enter a valid address", ) ], ) diff --git a/website/utils/management/commands/createfixtures.py b/website/utils/management/commands/createfixtures.py index b4b27cc70..14910e134 100644 --- a/website/utils/management/commands/createfixtures.py +++ b/website/utils/management/commands/createfixtures.py @@ -49,7 +49,7 @@ def _generate_title(): - words = _faker.words(random.randint(1, 3)) + words = _faker.words(random.randint(2, 4)) return " ".join([word.capitalize() for word in words]) @@ -237,7 +237,7 @@ def create_member_group(self, group_model): if random.random() < 0.1: month = timedelta(days=30) member_group.until = _faker.date_time_between_dates( - member_group.since, member_group.since + 30 * month + member_group.since + 12 * month, member_group.since + 60 * month ).date() member_group.active = random.random() < 0.9 @@ -273,12 +273,16 @@ def create_member_group_membership(self, member, group): today = date.today() membership.since = _faker.date_time_between_dates( - group.since, group.until + group.since, + group.until - timedelta(days=3) + if group.until + else group.since + timedelta(days=365), ).date() if random.random() < 0.2 and membership.since < today: membership.until = _faker.date_time_between_dates( - membership.since, group.until + membership.since, + group.until if group.until else group.since + timedelta(days=2 * 365), ).date() membership.full_clean()