当前位置: 首页>>代码示例>>Python>>正文


Python Page.delete方法代码示例

本文整理汇总了Python中models.Page.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Page.delete方法的具体用法?Python Page.delete怎么用?Python Page.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Page的用法示例。


在下文中一共展示了Page.delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_page_delete

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import delete [as 别名]
def handle_page_delete(page):

    # get form values
    cancel = request.form.has_key('cancel')

    if cancel:
        # redirect to view page
        return redirect_to_user_page(page.acct.uid, page.slug)

    # delete page
    uid = page.acct.uid
    private = page.private
    Page.delete(page)

    # redirect to home or private home, depending on visibility of deleted page
    target_slug = '__private' if private else '__home'
    return redirect_to_user_page(uid, target_slug)
开发者ID:alienlike,项目名称:hypertextual,代码行数:19,代码来源:hypertextual.py

示例2: save

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import delete [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, '&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!"
开发者ID:aostrega,项目名称:piki,代码行数:94,代码来源:piki.py

示例3: delete

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import delete [as 别名]
 def delete(self):
     route = self.request.matchdict['route']
     Page.delete(route)
     return HTTPFound(location=self.request.route_url('home'))
开发者ID:daymien,项目名称:pymyblog,代码行数:6,代码来源:views.py


注:本文中的models.Page.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。