From aa49b2d4ce286d328af3846ffa78fb038db3157c Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sun, 17 Sep 2017 14:59:50 +0200 Subject: [PATCH] Fix regex for pages --- club/migrations/0010_auto_20170912_2028.py | 8 +++++++- core/models.py | 2 +- core/urls.py | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/club/migrations/0010_auto_20170912_2028.py b/club/migrations/0010_auto_20170912_2028.py index 71bd639b..d80a4cb6 100644 --- a/club/migrations/0010_auto_20170912_2028.py +++ b/club/migrations/0010_auto_20170912_2028.py @@ -6,8 +6,12 @@ from club.models import Club def generate_club_pages(apps, schema_editor): - for club in Club.objects.all(): + def recursive_generate_club_page(club): club.make_page() + for child in Club.objects.filter(parent=club).all(): + recursive_generate_club_page(child) + for club in Club.objects.filter(parent=None).all(): + recursive_generate_club_page(club) class Migration(migrations.Migration): @@ -28,5 +32,7 @@ class Migration(migrations.Migration): name='page', field=models.OneToOneField(related_name='club', blank=True, null=True, to='core.Page'), ), + migrations.RunSQL('SET CONSTRAINTS ALL IMMEDIATE', reverse_sql=migrations.RunSQL.noop), migrations.RunPython(generate_club_pages), + migrations.RunSQL(migrations.RunSQL.noop, reverse_sql='SET CONSTRAINTS ALL IMMEDIATE'), ] diff --git a/core/models.py b/core/models.py index c6d7c997..f7972863 100644 --- a/core/models.py +++ b/core/models.py @@ -841,7 +841,7 @@ class Page(models.Model): name = models.CharField(_('page unix name'), max_length=30, validators=[ validators.RegexValidator( - r'^[A-z.+-]+$', + r'^[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]$', _('Enter a valid page name. This value may contain only ' 'unaccented letters, numbers ' 'and ./+/-/_ characters.') ), ], diff --git a/core/urls.py b/core/urls.py index 9242eee5..27a63070 100644 --- a/core/urls.py +++ b/core/urls.py @@ -87,9 +87,9 @@ urlpatterns = [ url(r'^page/$', PageListView.as_view(), name='page_list'), url(r'^page/create$', PageCreateView.as_view(), name='page_new'), url(r'^page/(?P[0-9]*)/delete$', PageDeleteView.as_view(), name='page_delete'), - url(r'^page/(?P[a-z0-9/-_]*)/edit$', PageEditView.as_view(), name='page_edit'), - url(r'^page/(?P[a-z0-9/-_]*)/prop$', PagePropView.as_view(), name='page_prop'), - url(r'^page/(?P[a-z0-9/-_]*)/hist$', PageHistView.as_view(), name='page_hist'), - url(r'^page/(?P[a-z0-9/-_]*)/rev/(?P[0-9]+)/', PageRevView.as_view(), name='page_rev'), - url(r'^page/(?P[a-z0-9/-_]*)/$', PageView.as_view(), name='page'), + url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/edit$', PageEditView.as_view(), name='page_edit'), + url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/prop$', PagePropView.as_view(), name='page_prop'), + url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/hist$', PageHistView.as_view(), name='page_hist'), + url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/rev/(?P[0-9]+)/', PageRevView.as_view(), name='page_rev'), + url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/$', PageView.as_view(), name='page'), ]