本文整理汇总了Python中models.Page.title方法的典型用法代码示例。如果您正苦于以下问题:Python Page.title方法的具体用法?Python Page.title怎么用?Python Page.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.title方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: page_edit_about
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def page_edit_about(request):
shop = request.shop
static_pages = Page.objects.filter(shop=shop)
dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
try:
about = About.objects.filter(shop=shop).get()
except About.DoesNotExist:
about = Page(shop=shop)
about.save()
if request.method == "POST":
form = AboutForm(request.POST)
if form.is_valid():
about.title = form.cleaned_data['title']
about.body = form.cleaned_data['body']
about.meta_content = form.cleaned_data['meta_content']
about.save()
request.flash['message'] = unicode(_("Page successfully saved."))
request.flash['severity'] = "success"
return HttpResponseRedirect(reverse('page_edit_about'))
else:
form = AboutForm(instance=about)
return render_to_response('store_admin/web_store/pages_edit_about.html',
{'form': form, 'static_pages': static_pages, 'dynamic_pages': dynamic_pages},
RequestContext(request))
示例2: create_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def create_page(db, page):
new_data = Page()
new_data.title = unicode(page['title'])
new_data.content = unicode(page["content"])
new_data.css = unicode(page['css'])
new_data.book_id = int(page["book_id"])
db.session.add(new_data)
示例3: get_object
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def get_object(self, request, region='', slug=''):
self.setup_region(region)
obj = Page(slug=slugify(slug), region=self.region)
obj.title = obj.versions.most_recent().name
obj.page = obj
return obj
示例4: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
form = PageForm(initial={'name': name})
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.title = form.cleaned_data['title']
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})
示例5: edit_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def edit_page(request, slug):
try:
page = Page.objects.get(title_slug=slug)
except Page.DoesNotExist:
page = Page()
page.title = slug
page.title_slug = slug
if update_post_with_request(page, request, update_user=True, force_slug=False):
return HttpResponseRedirect(page.get_absolute_url())
else:
return render_req_to_resp(request, 'post_edit.html', {'post': page})
示例6: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def post(self, slug=None):
if slug:
page = Page.gql("WHERE slug = :1", slug).get()
else:
page = Page()
page.title = self.request.get('title')
page.slug = self.request.get('slug')
page.content = self.request.get('content')
page.order_in_menu = int(self.request.get('order_in_menu'))
page.put()
self.redirect(page.get_url())
示例7: edit_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def edit_page(request, page_slug=None, template_name='page/edit.html'):
title = title_from_slug(page_slug)
try:
page = Page.objects.get(slug=page_slug)
except Page.DoesNotExist:
page = Page()
if request.method == 'POST':
revision = PageRevision(page=page, number=page.next_revision())
form = PageRevisionForm(request.POST, instance=revision)
if form.is_valid():
# Save the page, in case it is new and because a revision requires a valid Page object
page.title = title
page.slug = page_slug
page.save()
# Save the revision
new_revision = form.save(commit=False)
new_revision.page = page
new_revision.number = page.next_revision()
new_revision.save()
# Update the page's current revision now that the new revision has been persisted
page.current_revision = new_revision
page.save()
return HttpResponseRedirect("/" + page_slug)
else:
print form.errors
else:
form = PageRevisionForm(instance=page.current_revision, initial={"comment": ""})
context = {
'title': title,
'form': form.as_table(),
}
return render_to_response(template_name, RequestContext(request, context))
示例8: get_object
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def get_object(self, request, slug):
obj = Page(slug=slugify(slug))
obj.title = obj.versions.most_recent().name
obj.page = obj
return obj
示例9: save
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import title [as 别名]
def save(user_slug, wiki_slug, page_slug):
""" Saves page changes in the database.
-] patch - array of changed content blocks; 'undefined' if unchanged
<- slugified page title
"""
user = User.get_by(name_slug=user_slug)
if user != g.user:
return False
wiki = user.wiki_by_slug(wiki_slug)
try:
page = wiki.page_by_slug(page_slug)
except NoResultFound:
old_last_page = Page.get_by(wiki=wiki, next_page_id=-1)
page = Page(wiki=wiki, title="", title_slug="",
content="<h1>Untitled</h1>", next_page_id=-1)
models.session.commit()
old_last_page.next_page_id = page.id
patch = request.form.getlist('patch')
block = re.compile('<(?:h1|h2|h3|p)>.*?</(?:h1|h2|h3|p)>')
content_blocks = block.findall(page.content)
# If the page's title has been changed in the content...
new_title = page.title
if len(patch) and patch[0] != 'undefined':
new_title = patch[0][4:-5]
newline = re.compile('\n')
new_title = re.sub(newline, "", new_title)
if page.title != new_title:
# ..if a page exists with this title, append " (alternative)" to it.
try:
same_title_page = Page.get_by(title=new_title)
except NoResultFound:
pass
if same_title_page:
stp = same_title_page
header_end = 4 + len(stp.title)
stp.title += " (alternative)"
stp.title_slug = slugify(stp.title)
stp.content = stp.content[:header_end] + " (alternative)" + \
stp.content[header_end:]
# ..if the page with changed title was the main page, make a new one.
if page.title == wiki.title:
try:
if new_title:
second_page = page
else:
second_page = Page.get_by(id=page.next_page_id)
next_page_id = second_page.id
except NoResultFound:
next_page_id = -1
new_main_page = Page(wiki=wiki, title=wiki.title,
title_slug=slugify(wiki.title),
content="<h1>%s</h1><p></p>" % wiki.title,
next_page_id=next_page_id)
models.session.commit()
wiki.first_page_id = new_main_page.id
# ..change the page's title in the database.
page.title = new_title
page.title_slug = slugify(new_title)
# Replace content with patched content.
for i, block in enumerate(patch):
if block != 'undefined':
if i < len(content_blocks):
content_blocks[i] = block
else:
content_blocks.append(block)
# Sanitize unsafe angle brackets.
content = ''.join(content_blocks)
unsafe_lt = re.compile(r"<(?!/?(h1|h2|h3|p|b|i|u)>)")
content = re.sub(unsafe_lt, '<', content)
# The content is reversed to get around regex lookbehind limitation.
unsafe_gt = re.compile(r">(?!(1h|2h|3h|p|b|i|u)/?<)")
content = re.sub(unsafe_gt, ';tg&', content[::-1])
page.content = content[::-1]
# If the title is blank, delete the page.
deleted = False
blank_title = re.compile('<h1>(<br>)*</h1>')
if blank_title.match(page.content):
try:
previous_page = Page.get_by(wiki=wiki, next_page_id=page.id)
previous_page.next_page_id = page.next_page_id
except NoResultFound:
pass
page.delete()
deleted = True
# Update the wiki's update date.
wiki.update_date = datetime.now()
# Commit to database!
models.session.commit()
if not deleted:
return slugify(page.title)
else:
return "untitled!"