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


Python Page.by_name方法代码示例

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


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

示例1: log

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
def log(name):
    """Show the list of recent changes."""
    revision = Page.by_name(name)
    if revision is None:
        return show(name)
    revisions = revision.page.revisions.all().order('-timestamp').fetch(-1)
    return web.render_template('log.html', revision=revision, revisions=revisions)
开发者ID:cloudappsetup,项目名称:kalapy,代码行数:9,代码来源:views.py

示例2: edit

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
def edit(name):
    note = error = ''
    revision = Page.by_name(name)

    return web.render_template('edit.html',
        new=revision is None,
        revision=revision,
        page_name=name,
        note=note,
        error=error)
开发者ID:cloudappsetup,项目名称:kalapy,代码行数:12,代码来源:views.py

示例3: get

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
 def get(self, page_name):
     page = Page.by_name(page_name)
     revision = None
     revision_id = self.request.get('v')
     if revision_id:  # if a specific revision is requested
         revision = Revision.by_id(revision_id, page)
     self.render(
         'edit.jinja',
         page_name=page_name,
         revision=revision,
         user=self.user,
         page=page)
开发者ID:romanlevin,项目名称:roman-wiki,代码行数:14,代码来源:wiki.py

示例4: show

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
def show(name):
    revision = request.args.get('rev')
    if revision:
        revision = Page.by_revision(revision)
        revision_requested = True
    else:
        revision = Page.by_name(name)
        revision_requested = False
    if revision is None:
        return (web.render_template('missing.html',
                revision_requested=revision_requested,
                page_name=name,
                protected=False), 404)
    return web.render_template('show.html', revision=revision)
开发者ID:cloudappsetup,项目名称:kalapy,代码行数:16,代码来源:views.py

示例5: post

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
 def post(self, page_name):
     page = Page.by_name(page_name)
     if self.user:
         body = self.request.get('content')
     else:  # if posted while not logged in.
         self.write('ERROR: not logged in.')
         self.abort()
     if not page:  # For creatubg a new page.
         page = Page(title=page_name)
         page.put()
     revision = Revision(body=body, user=self.user, parent=page)
     revision.put()
     page.revision = revision
     page.put()
     self.redirect_to('WikiPage', page_name=page_name)
开发者ID:romanlevin,项目名称:roman-wiki,代码行数:17,代码来源:wiki.py

示例6: diff

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
def diff(name):

    old = request.args.get('old')
    new = request.args.get('new')

    try:
        old = int(old)
        new = int(new)
    except:
        pass

    error = ''
    diff = page = old_rev = new_rev = None

    if not (old and new):
        error = _('No revisions specified.')
    else:
        revision = Page.by_name(name)
        revisions = dict([(rev.key, rev) for rev in revision.page.revisions \
            .all().filter('key in', [old, new]).fetch(-1)])

        if len(revisions) != 2:
            error = _('At least one of the revisions requested ' \
                      'does not exist.')
        else:
            new_rev = revisions[new]
            old_rev = revisions[old]
            page = old_rev.page
            diff = unified_diff(
                (old_rev.text + '\n').splitlines(True),
                (new_rev.text + '\n').splitlines(True),
                page.name, page.name,
                old_rev.time,
                new_rev.time,
                3
            )
    return web.render_template('diff.html',
        error=error,
        old_revision=old_rev,
        new_revision=new_rev,
        page=page,
        revision=page,
        diff=diff
    )
开发者ID:cloudappsetup,项目名称:kalapy,代码行数:46,代码来源:views.py

示例7: save

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
def save(name):

    revision = Page.by_name(name)
    text = request.form.get('text')
    note = request.form.get('note')

    if request.form.get('cancel') or \
        revision and revision.text == text:
        return web.redirect(web.url_for('show', name=name))
    elif not text:
        error = _('You cannot save empty revisions.')
    else:
        note = request.form.get('note', '')
        page = revision.page if revision else Page(name=name)
        revision = Revision(text=text, page=page, note=note)
        revision.save()
        db.commit()

    return web.redirect(web.url_for('show', name=name))
开发者ID:cloudappsetup,项目名称:kalapy,代码行数:21,代码来源:views.py

示例8: revert

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import by_name [as 别名]
def revert(name):
    """Revert an old revision."""
    rev_id = request.args.get('rev')
    try:
        rev_id = int(rev_id)
    except:
        pass

    old_revision = page = None
    error = _('No such revision')

    if request.method == 'POST' and request.form.get('cancel'):
        return web.redirect(web.url_for('show', name=page_name))

    if rev_id:
        old_revision = Page.by_revision(rev_id)
        if old_revision:
            new_revision = Page.by_name(name)
            if old_revision == new_revision:
                error = _('You tried to revert the current active ' \
                          'revision.')
            elif old_revision.text == new_revision.text:
                error = _('There are no changes between the current ' \
                          'revision and the revision you want to ' \
                          'restore.')
            else:
                error = ''
                page = old_revision.page
                if request.method == 'POST':
                    note = request.form.get('note', '')
                    note = 'revert' + (note and ': ' + note or '')
                    revision = Revision(page=page, text=old_revision.text,
                                         note=note)
                    revision.save()
                    db.commit()
                    return web.redirect(web.url_for('show', name=name))

    return web.render_template('revert.html',
        error=error,
        old_revision=old_revision,
        revision=page
    )
开发者ID:cloudappsetup,项目名称:kalapy,代码行数:44,代码来源:views.py


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