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 create_page(request, pageid): page = get_object_or_404(Page, id=pageid) if request.POST: form = PageForm(request.POST) if form.is_valid(): data = form.cleaned_data data['site_id'] = settings.SITE_ID data['created_by'] = request.user data['updated_by'] = request.user # No longer needed... data.pop('parent_page_id') newpage = page.add_child(**data) if request.is_ajax(): response = http.HttpResponse('', 'text/plain') response['X-Finch'] = newpage.get_absolute_url() # This is mostly for automated tests ... # The test-client never is_ajax of course but when # creating automated tests (using django-viewtester # for example) this would (otherwise) generate a 200 # response code and the test will fail # Needs a fix for crap IE browsers that strip the # X-Finch when the response code is 302 Assuming # no developers worth their salt will use IE to create # tests I think this is ok if request.META.get('HTTP_USER_AGENT', '').find('MSIE')<0: response.status_code = 302 return response else: return http.HttpResponseRedirect(newpage.get_absolute_url()) else: form = PageForm(initial={'parent_page_id':pageid, 'online':page.online }) caption = _("Create Childpage") action_url = reverse('create_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)