def page(request, slug="index"): if request.method == "GET": if exists(slug): page = get_page(slug) return dict(page=page, edit=request.GET.get('edit', False), exists=True) else: return dict(exists=False, slug=slug) else: # save/create a page if exists(slug): page = get_page(slug) page.body = request.POST.get('body', '') page.title = request.POST.get('title', '') tags = parse_tags(request.POST.get('tags', '')) page.update_tags(tags) page.save() return HttpResponseRedirect(page.get_absolute_url()) else: if slug == '': slug = request.POST.get('title').lower() page = create_page(slug=slug, title=request.POST.get('title', ''), body=request.POST.get('body', ''), tags=parse_tags(request.POST.get('tags', ''))) return HttpResponseRedirect(page.get_absolute_url())
def get(self, requested_page): referer_val = requested_page user = get_current_user(self.request.cookies.get('user_id')) if user: page_name = get_page_name(requested_page) if page_name == "": page = models.get_page("root") else: page = models.get_page(page_name) if page: self.render_edit(page.content, user.username) else: self.render_edit("", user.username) else: self.redirect("/login?referer_val=%s" % referer_val)
def get(self): path = self.request.path page_id = path.split('/')[2] page = models.get_page(page_id) template_values = { 'type_name': self.type_name, 'page': page, 'user_email': models.get_user_email(), 'is_admin': is_admin(), 'is_member_or_admin': is_admin() or models.is_member(), 'logout': users.create_logout_url('/'), } template = JINJA_ENVIRONMENT.get_template(self.template_file) self.response.write(template.render(template_values))
def get(self): if not is_admin(): handle_404(self) return type_name = self.request.get("type_name") page_id = self.request.get("page_id") page = models.get_page(page_id) template_values = { "type_name": type_name, "page": page, 'user_email': models.get_user_email(), 'is_admin': is_admin(), 'is_member_or_admin': is_admin() or models.is_member(), 'logout': users.create_logout_url('/'), } template = JINJA_ENVIRONMENT.get_template('templates/editpage.html') self.response.write(template.render(template_values))
def page_history(request, slug="index"): if exists(slug): page = get_page(slug) return dict(page=page) else: return HttpResponse("no such page")