summaryrefslogtreecommitdiffstats
path: root/combo/manager/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'combo/manager/views.py')
-rw-r--r--combo/manager/views.py23
1 files changed, 22 insertions, 1 deletions
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'