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

@@ -14,7 +14,7 @@ from . import models, forms
class WYSIWYGEditorMixin(PermissionRequiredMixin):
"""
A view to update the Content-Security-Policy for the WYSIWYG editor.
Since it is only used in edit forms, it extends the PermissionRequiredMixin.
Since it is only used in edit forms, it extends the PermissionRequiredMixin.
"""
@csp_update(SCRIPT_SRC="'unsafe-eval'")
@@ -160,8 +160,8 @@ class ArticleForm(WYSIWYGEditorMixin, generic.UpdateView):
def get_object(self, queryset=None):
"""Get the Article or create a new one if no id has been provided.
:param queryset: Get the single item from this filtered queryset.
:return:
:param queryset: Get the single item from this filtered queryset.
:return:
"""
queryset = queryset or self.get_queryset()
if self.kwargs.get('pk'):
@@ -170,7 +170,7 @@ class ArticleForm(WYSIWYGEditorMixin, generic.UpdateView):
class PageAddForm(WYSIWYGEditorMixin, generic.CreateView):
""" Renders an Form to create a new page for users with conforming
""" Renders an Form to create a new page for users with conforming
permissions."""
form_class = forms.PageForm
@@ -179,13 +179,16 @@ class PageAddForm(WYSIWYGEditorMixin, generic.CreateView):
def get_initial(self):
"""Try to get the path of the parent page as initial data."""
path = os.path.splitext(self.kwargs['path'])[0]
if path.startswith('/'):
path = path[1:]
if path.endswith('/'):
path = path[:-1]
parent = models.Page.objects.get(path=path)
return {'parent': parent}
if self.kwargs['path']:
path = os.path.splitext(self.kwargs['path'])[0]
if path.startswith('/'):
path = path[1:]
if path.endswith('/'):
path = path[:-1]
parent = models.Page.objects.get(path=path)
return {'parent': parent}
else:
return None
class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView):
@@ -197,14 +200,15 @@ class PageEditForm(WYSIWYGEditorMixin, generic.UpdateView):
def get_object(self, queryset=None):
""" Get the path from the URL and fetch the corresponding page.
First get the path wihout fileextentsion leading or trailing slashes,
then search in the database if such a page exists.
: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()
if path.startswith('/'):
path = path[1:]
@@ -222,7 +226,7 @@ class PageHtml(generic.DetailView):
"""Get the page content from the db that equals the given URL.
:param queryset: Get the single item from this filtered queryset.
:return:
:return:
"""
queryset = queryset or self.get_queryset()
try:
@@ -248,10 +252,10 @@ class PagePdf(generic.DeleteView):
model = models.Page
def get_object(self, queryset=None):
"""Get the PDF page from the db that equals the given URL.
"""Get the PDF page from the db that equals the given URL.
:param queryset: Get the single item from this filtered queryset.
:return: models.Page object or raise a 404 if not found.
:return: models.Page object or raise a 404 if not found.
"""
queryset = queryset or self.get_queryset()
try:
@@ -288,8 +292,8 @@ class StartPage(generic.TemplateView):
def get_context_data(self):
""" Adds recent ariticles and recent comments to the context.
:return: array() with the context data
:return: array() with the context data
"""
page = models.Page.objects.get(slug='index')
recent_comment_list = comments.get_model().objects.filter(