def edit_page(request, pageid): page = get_object_or_404(Page, id=pageid) # Store values in case the url_changed signal needs to be sent oldpath = page.get_absolute_url() oldtitle = page.title if request.POST and request.POST.get('save','') == _('Save'): form = PageForm(request.POST, instance=page) if form.is_valid(): form.cleaned_data['updated_by'] = request.user page = form.save() # TODO: Move this stuff (up till 'is_ajax') to models.py # Notify those who care that url to this page has changed if 'slug' in form.changed_data: url_changed.send( Page, id=page.id, oldpath=oldpath, oldtitle=oldtitle, newpath=page.get_absolute_url(), newtitle=page.title) if not page.is_leaf(): if any([x in form.changed_data for x in ('online')]): page.propagate() if request.is_ajax(): response = http.HttpResponse('', 'text/plain') response['X-Finch'] = page.get_absolute_url() # This is mostly for tests. See remarks above if request.META.get('HTTP_USER_AGENT', '').find('MSIE')<0: response.status_code = 302 return response else: return http.HttpResponseRedirect(page.get_absolute_url()) else: form = PageForm(instance=page) if page.is_root(): # Slug is not updatable for a rootpage (it is always '') form.fields.pop('slug', None) caption = _("Edit Page") action_url = reverse('edit_page', args=[page.id]) if request.is_ajax(): template = 'finch/ajax.html' else: template = 'contentmanager/contentmanager_base.html' context = RequestContext(request, locals()) return render_to_response('finch/edit.html', context)
def move_confirm(request, pageid, targetid): page = get_object_or_404(Page, id=pageid) target = get_object_or_404(Page, id=targetid) is_valid = True if target.get_children().filter(slug=page.slug).count()>0: errormessage = "Target already contains a page at %s%s" \ % (target.get_absolute_url(), page.slug) is_valid = False if target in page.get_descendants(): errormessage = "Cannot move page to a its own subtree." is_valid = False if is_valid and request.POST \ and request.POST.get('confirm', '') == _('Yes'): oldpath = page.get_absolute_url() page.move(target=target, pos='last-child') # reget the page with updated tree-props page = Page.objects.get(id=pageid) # saving the page will update the urlpath page.save() # TODO: Move to models.py url_changed.send( Page, id=page.id, oldpath=oldpath, oldtitle=page.title, #title doesn't change when moving newpath=page.get_absolute_url(), newtitle=page.title) # After moving get the permissions from the parent # TODO: *copy* from the parent and *then* propagate to prevent # overwriting different settings in the (new) siblings page.get_parent().propagate() return http.HttpResponseRedirect(page.get_absolute_url()) if request.is_ajax(): template = 'finch/ajax.html' else: template = 'contentmanager/contentmanager_base.html' tree = page.get_tree(parent=page) context = RequestContext(request, locals()) return render_to_response('finch/move-confirm.html', context)