def post(self): if not (session and session.get('uid')): return jsonify({'error': 'Not logged in'}) page = Page(slug=request.form['slug']) page.url = request.form['url'] page.author = User.objects(id=ObjectId(session.get('uid'))) page.save() node = Node.objects(id=ObjectId(request.form['nid']))[0] nodes.pages.append(page) node.save(cascade=True) return jsonify({'success':1})
def edit(request, name): if not request.user.is_authenticated(): raise Http404 page = get(Page, name, True) if request.method == "POST": form = PageForm(request.POST) if form.is_valid(): if not page: page = Page() page.name = form.cleaned_data["name"] page.content = form.cleaned_data["content"] page.author = request.user page.tags = " ".join(filter(None, name.split("/"))) page.save() return HttpResponseRedirect("%s" % urlquote(page.get_path())) else: if page: form = PageForm(initial=page.__dict__) else: form = PageForm(initial={"name": name}) return render_to_response("edit.html", {"form": form})