本文整理汇总了Python中models.Page.name方法的典型用法代码示例。如果您正苦于以下问题:Python Page.name方法的具体用法?Python Page.name怎么用?Python Page.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.name方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_database
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def setup_database(app):
with app.app_context():
db.create_all()
home = Page()
home.name = "Home"
contact = Page()
contact.name = Page()
db.session.add(home)
db.session.add(contact)
db.session.commit()
示例2: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if not page:
# it's a new page
page = Page()
page.name = form.cleaned_data['name']
page.user = request.user
page.created_on = datetime.now()
page.save()
page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page)
page_revision.save()
page.current_revision = page_revision
page.save()
else:
# it's an edit on an old page
page.name = form.cleaned_data['name']
revision_count = PageRevision.objects.filter(revision_for = page).count()
new_rev = revision_count + 1
page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page, revision_num = new_rev)
page_revision.save()
page.current_revision = page_revision
page.modified_on = datetime.now()
page.user = request.user
page.save()
return HttpResponseRedirect('../../%s/' % page.name)
else:
if page:
page_dict = page.__dict__
# we have phased out page.content,
# instead page will be a reference to current revision content.
# but for the purposes of the form, we'll emulate it (ugly hack!)
page_dict['content'] = page.current_revision.content
form = PageForm(initial=page_dict)
else:
form = PageForm(initial={'name': name})
context = RequestContext(request)
return render_to_response('wiki/edit.html', {'form': form}, context)
示例3: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if not page:
page = Page()
page.name = form.cleaned_data['name']
page.save()
revision = Revision()
revision.page = page
revision.content = form.cleaned_data['content']
if request.user.is_authenticated():
revision.editor = request.user
revision.save()
return HttpResponseRedirect(page.get_absolute_url())
else:
if page:
revision = page.get_latest_revision()
form = PageForm(initial={'name': page.name, 'content': revision.content})
else:
form = PageForm(initial={'name': name})
ctx = { 'form': form }
return render_to_response('wiki/edit.html', ctx, context_instance=RequestContext(request))
示例4: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
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.save()
return redirect(view, name=page.name)
else:
if page:
form = PageForm(initial=page.__dict__)
else:
form = PageForm(initial={'name': name})
context = {
'form': form,
}
return render_to_response('wiki/edit.html',
RequestContext(request, context))
示例5: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
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.save()
return HttpResponseRedirect("../../%s/" % page.name)
else:
if page:
form = PageForm(initial=page.__dict__)
else:
form = PageForm(initial={"name": name})
return render_to_response(
"wiki/edit.html",
{
"form": form,
"admin": is_admin(request),
"user": get_user(request),
"navbar": Page.objects.get(name="NavBar"),
},
)
示例6: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def post(self, ident=None):
if ident:
source = Page.fetch_by_key(ident)
else:
source = Page()
source.name = self.request.get('name', '')
source.url = self.request.get('url', '')
source.phrases = self.request.get('phrases', '')
key = source.put()
self.response.write(key.urlsafe())
示例7: show_pages
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def show_pages():
if request.method == "POST" and g.site.domain == g.user:
name = request.form['name']
if name:
p = Page()
p.name = name
p.slug = slugify(name)
p.site = g.site.domain
p.save()
return redirect(url_for(".edit_page", slug=p.slug))
pages = Page.objects(site=g.site.domain)
return render_template('pages.html', pages=pages)
示例8: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
def post(self):
current_user = users.get_current_user()
if not current_user:
return self.redirect('/')
user = User.get_by_id(current_user.user_id())
if not user:
return self.redirect('/register')
try:
page = Page(parent=user.key)
page.user = user.key
page.url = self.request.get('url')
page.name = self.request.get('name')
page.put()
self.redirect('/')
except db.Error:
self.redirect('/')
示例9: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import name [as 别名]
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})