summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combo/manager/templates/combo/page_view.html1
-rw-r--r--combo/manager/urls.py1
-rw-r--r--combo/manager/views.py23
-rw-r--r--tests/test_manager.py18
4 files changed, 42 insertions, 1 deletions
diff --git a/combo/manager/templates/combo/page_view.html b/combo/manager/templates/combo/page_view.html
index c1fa61f..67f91ba 100644
--- a/combo/manager/templates/combo/page_view.html
+++ b/combo/manager/templates/combo/page_view.html
@@ -11,6 +11,7 @@
<ul class="extra-actions-menu">
<li><a href="{% url 'combo-manager-page-history' pk=object.id %}">{% trans 'history' %}</a></li>
<li><a download href="{% url 'combo-manager-page-export' pk=object.id %}">{% trans 'export' %}</a></li>
+ <li><a rel="popup" href="{% url 'combo-manager-page-add-child' pk=object.id %}">{% trans 'add a child page' %}</a></li>
<li><a rel="popup" href="{% url 'combo-manager-page-delete' pk=object.id %}">{% trans 'delete' %}</a></li>
</ul>
</span>
diff --git a/combo/manager/urls.py b/combo/manager/urls.py
index 23c1a8d..a99f99e 100644
--- a/combo/manager/urls.py
+++ b/combo/manager/urls.py
@@ -53,6 +53,7 @@ urlpatterns = [
name='combo-manager-page-delete'),
url(r'^pages/(?P<pk>\w+)/export$', views.page_export,
name='combo-manager-page-export'),
+ url(r'^pages/(?P<pk>\w+)/add/$', views.page_add_child, name='combo-manager-page-add-child'),
url(r'^pages/(?P<pk>\w+)/history$', views.page_history,
name='combo-manager-page-history'),
url(r'^pages/(?P<page_pk>\w+)/history/(?P<pk>\w+)/$', views.snapshot_restore,
diff --git a/combo/manager/views.py b/combo/manager/views.py
index 6b051ba..3633c7e 100644
--- a/combo/manager/views.py
+++ b/combo/manager/views.py
@@ -24,6 +24,7 @@ from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import redirect
+from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text, force_bytes
from django.utils.formats import date_format
@@ -97,7 +98,7 @@ class PageAddView(CreateView):
def get_initial(self):
initial = super(PageAddView, self).get_initial()
- if Page.objects.count() == 0: # first page
+ if not Page.objects.exists(): # first page
initial['title'] = _('Home')
return initial
@@ -117,6 +118,26 @@ class PageAddView(CreateView):
page_add = PageAddView.as_view()
+class PageAddChildView(PageAddView):
+ def get_initial(self):
+ # it can not be the first page, so don't try to initial the title
+ return super(CreateView, self).get_initial()
+
+ def dispatch(self, request, *args, **kwargs):
+ print(request.POST)
+ self.parent = get_object_or_404(Page, pk=kwargs['pk'])
+ return super(PageAddChildView, self).dispatch(request, *args, **kwargs)
+
+ def form_valid(self, form):
+ response = super(PageAddChildView, self).form_valid(form)
+ self.object.parent = self.parent
+ self.object.save()
+ return response
+
+
+page_add_child = PageAddChildView.as_view()
+
+
class PageEditView(UpdateView):
model = Page
template_name = 'combo/page_add.html'
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 136e8f9..3cb0ecd 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -73,6 +73,24 @@ def test_add_second_page(app, admin_user):
resp = resp.forms[0].submit()
assert Page.objects.get(slug='foobar').title == 'Foobar'
+
+def test_add_child_page(app, admin_user):
+ page = Page(title='One', slug='one')
+ page.save()
+ app = login(app)
+ resp = app.get('/manage/pages/%s/' % page.pk, status=200)
+ resp = resp.click(href='.*/add/')
+ resp.forms[0]['title'].value = 'Two'
+ resp = resp.forms[0].submit()
+ child = Page.objects.latest('pk')
+ assert resp.location.endswith('/manage/pages/%s/' % child.pk)
+ assert child.title == 'Two'
+ assert child.parent == page
+
+ app.get('/manage/pages/%s/add/' % child.pk, status=200)
+ app.get('/manage/pages/42/add/', status=404)
+
+
def test_edit_page(app, admin_user):
Page.objects.all().delete()
app = login(app)