fixed add_page and edit_page URL definitions to work with "/" path.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -29,13 +29,13 @@ sitemaps = {
|
||||
urlpatterns = [ # Ignore PyLintBear (C0103)
|
||||
url(r'^$', views.StartPage.as_view()),
|
||||
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'),
|
||||
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^ckeditor/', include('ckeditor_uploader.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'),
|
||||
url(r'^events/', include('events.urls')),
|
||||
url(r'^events.ics$', EventListIcal.as_view(), name='events-ical'),
|
||||
|
||||
Reference in New Issue
Block a user