fixed add_page and edit_page URL definitions to work with "/" path.

This commit is contained in:
2019-01-01 18:30:52 +01:00
parent 12930c2ec6
commit 5ed8976074
2 changed files with 25 additions and 21 deletions

View File

@@ -179,13 +179,16 @@ class PageAddForm(WYSIWYGEditorMixin, generic.CreateView):
def get_initial(self): def get_initial(self):
"""Try to get the path of the parent page as initial data.""" """Try to get the path of the parent page as initial data."""
path = os.path.splitext(self.kwargs['path'])[0] if self.kwargs['path']:
if path.startswith('/'): path = os.path.splitext(self.kwargs['path'])[0]
path = path[1:] if path.startswith('/'):
if path.endswith('/'): path = path[1:]
path = path[:-1] if path.endswith('/'):
parent = models.Page.objects.get(path=path) path = path[:-1]
return {'parent': parent} parent = models.Page.objects.get(path=path)
return {'parent': parent}
else:
return None
class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView): class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView):
@@ -204,7 +207,8 @@ class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView):
:param queryset: Get the single item from this filtered queryset. :param queryset: Get the single item from this filtered queryset.
:return: :return:
""" """
path = os.path.splitext(self.kwargs['path'])[0] path = self.kwargs['path'] or 'index.html'
path = os.path.splitext(path)[0]
queryset = queryset or self.get_queryset() queryset = queryset or self.get_queryset()
if path.startswith('/'): if path.startswith('/'):
path = path[1:] path = path[1:]

View File

@@ -29,13 +29,13 @@ sitemaps = {
urlpatterns = [ # Ignore PyLintBear (C0103) urlpatterns = [ # Ignore PyLintBear (C0103)
url(r'^$', views.StartPage.as_view()), url(r'^$', views.StartPage.as_view()),
url(r'^404/$', TemplateView.as_view(template_name='404.html')), url(r'^404/$', TemplateView.as_view(template_name='404.html')),
url(r'^add_page/(?P<path>[\+\.\-\d\w\/]+)/$', url(r'^add_page/(?P<path>[\+\.\-\d\w\/]*)$',
views.PageAddForm.as_view(), name='add-page'), views.PageAddForm.as_view(), name='add-page'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^ckeditor/', include('ckeditor_uploader.urls')), url(r'^ckeditor/', include('ckeditor_uploader.urls')),
url(r'^comments/', include('django_comments.urls')), url(r'^comments/', include('django_comments.urls')),
url(r'^edit_page/(?P<path>[\+\.\-\d\w\/]+)/$', url(r'^edit_page/(?P<path>[\+\.\-\d\w\/]*)$',
views.PageEditForm.as_view(), name='edit-page'), views.PageEditForm.as_view(), name='edit-page'),
url(r'^events/', include('events.urls')), url(r'^events/', include('events.urls')),
url(r'^events.ics$', EventListIcal.as_view(), name='events-ical'), url(r'^events.ics$', EventListIcal.as_view(), name='events-ical'),