def save(self, commit=True): if self.instance: wiki = self.instance else: wiki = Wiki() wiki.title = self.cleaned_data['title'] wiki.slug = self.cleaned_data['slug'] wiki.description = self.cleaned_data['description'] wiki.text = self.cleaned_data['text'] wiki.format = self.cleaned_data['format'] wiki.published = self.cleaned_data['published'] wiki.template = self.cleaned_data['template'] wiki.show_in_rss = self.cleaned_data['show_in_rss'] wiki.cacheable = self.cleaned_data['cacheable'] wiki.show_in_rss = self.cleaned_data['show_in_rss'] wiki.disable_comments = self.cleaned_data['disable_comments'] if self.cleaned_data['temp_tags']: wiki.tags = map(lambda tag: db.Category(tag), self.cleaned_data['temp_tags'].split(' ')) else: wiki.tags = [] if commit: wiki.save() return wiki
def save(self, commit=True): if self.instance: wiki = self.instance else: wiki = Wiki() wiki.title = self.cleaned_data["title"] wiki.slug = self.cleaned_data["slug"] wiki.description = self.cleaned_data["description"] wiki.text = self.cleaned_data["text"] wiki.format = self.cleaned_data["format"] wiki.published = self.cleaned_data["published"] wiki.template = self.cleaned_data["template"] wiki.show_in_rss = self.cleaned_data["show_in_rss"] wiki.cacheable = self.cleaned_data["cacheable"] wiki.show_in_rss = self.cleaned_data["show_in_rss"] wiki.disable_comments = self.cleaned_data["disable_comments"] if self.cleaned_data["temp_tags"]: wiki.tags = map(lambda tag: db.Category(tag), self.cleaned_data["temp_tags"].split(" ")) else: wiki.tags = [] if commit: wiki.save() return wiki
def wiki(wiki_url): flag = not current_user.is_anonymous() or "None" print flag if request.method == "POST": title = wiki_url author = current_user.username or 'Anonymous' content = request.form["content"] wiki = Wiki(title=title, author=author, content=content) wiki.save() redirect("/wiki/"+title) try: item = Wiki.objects(title=wiki_url).order_by('-updated_at')[0] except: return render_template("/wiki/newpage.html", wiki_url=wiki_url, author=author) if wiki_url == str(item.title): return render_template('/wiki/wikipage.html', flag=flag, title=item.title, content=item.content, author=item.author, created_at=item.created_at)
def save(request, pagename): '''保存页面内容并转到更新后的页面,如果页面已存在则更新它的内容, 如果页面不存在,则新建这个页面''' content = request.POST['content'] pages = Wiki.objects.filter(pagename=pagename) if pages: pages[0].content = content pages[0].save() else: page = Wiki(pagename=pagename, content=content) page.save() return HttpResponseRedirect('/wiki/%s' % pagename)