def edit_layout(request, layout_slug=None): if not request.user.is_superuser: raise PermissionDenied() try: layout_id = int(layout_slug) layout = Layout.objects.get(pk=int(layout_id)) except ValueError: try: layout = Layout.objects.get(slug=layout_slug) except Layout.DoesNotExist: return redirect('publisher.views.new_layout', name = layout_slug.replace('_',' ').title(), slug = layout_slug) except Layout.DoesNotExist: raise Http404 try: form = Form(forms.EditLayoutForm, instance=layout) if request.method=='POST': if form.is_valid(): n = form.save(commit=False) n.save() return redirect("publisher.views.edit_layout", [str(n.id)], info = 'Layout "%s" saved successfully' % n.name ) except Exception, e: form.non_field_errors = str(e) or "Please try again later."
def new_flatpage(request): if not request.user.is_superuser: raise PermissionDenied() try: form = Form(forms.NewFlatPageForm, initial={}) if request.method=='POST': if form.is_valid(): n = form.save(commit=False) if n.url and not n.url.endswith('/'): n.url += '/' n.save() site = Site.objects.get_current() n.sites.add(site) n.save() return redirect("publisher.views.edit_flatpage", [str(n.id)], info=_('Created successfully')) except Exception, e: form.non_field_errors = unicode(e) or _("Please try again later.")
def new_layout(request): if not request.user.is_superuser: raise PermissionDenied() initial = {} if request.method=='GET': initial = { 'name': request.GET.get('name',''), 'slug': request.GET.get('slug',''), } try: form = Form(forms.NewLayoutForm, initial=initial) if request.method=='POST': if form.is_valid(): n = form.save(commit=False) n.save() return redirect("publisher.views.edit_layout", [str(n.id)], info = 'Layout "%s" created successfully' % n.name ) except Exception, e: form.non_field_errors = str(e) or "Please try again later."
def edit_flatpage(request, flatpage_id): if not request.user.is_superuser: raise PermissionDenied() try: flatpage = entity = FlatPage.objects.get(pk=flatpage_id) except FlatPage.DoesNotExist: raise Http404 try: form = Form(forms.EditFlatPageForm, instance=flatpage) if request.method=='POST': if form.is_valid(): n = form.save(commit=False) site = Site.objects.get_current() if n.url and not n.url.endswith('/'): n.url += '/' n.sites.add(site) n.save() return redirect("publisher.views.edit_flatpage", [str(n.id)], info=_('Saved successfully')) except Exception, e: form.non_field_errors = unicode(e) or _("Please try again later.")