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


Python Page.regenerate方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import regenerate [as 别名]
    def post(self):
        msgs = []
        section = None
        try:
            section = Section.get( self.request.get('section_key') )
        except BadKeyError:
            # invalid key, try again
            self.redirect('.')

        node_type = self.request.get('node_type')
        data_input = self.request.POST.get('data_input').file.read()
        data_type = self.request.get('data_type')

        data = None
        if data_type == 'json':
            data = json.loads( data_input )
        elif data_type == 'yaml':
            data = yaml.load( data_input )
        else:
            # someone is messing with the input params
            self.redirect('.')

        # logging.info( 'data=' + json.dumps( data ) )

        # figure out what this node_type is
        item = None
        if node_type == 'page':
            item = Page(
                section = section,
                name = data['name'],
                title = data['title'],
                content = data['content'],
                type = data['type'],
                label_raw = ' '.join( data['label'] ),
                attribute_raw = ' '.join( data['attribute'] ),
                inserted = util.str_to_datetime( data['inserted'] ),
                updated = util.str_to_datetime( data['updated'] ),
                )

        elif node_type == 'recipe':
            item = Recipe(
                section = section,
                name = data['name'],
                title = data['title'],
                intro = data['intro'],
                serves = data['serves'],
                ingredients = data['ingredients'],
                method = data['method'],
                type = data['type'],
                label_raw = ' '.join( data['label'] ),
                attribute_raw = ' '.join( data['attribute'] ),
                inserted = util.str_to_datetime( data['inserted'] ),
                updated = util.str_to_datetime( data['updated'] ),
                )

        else:
            # again, someone is messing with the input params
            self.redirect('.')

        # regenerate this item
        item.set_derivatives()
        item.put()
        item.section.regenerate()

        # output messages
        msgs.append( 'Added node [%s, %s]' % (item.name, item.title) )

        if 'comments' in data:
            for comment in data['comments']:
                # load each comment in against this node
                comment = Comment(
                    node = item,
                    name = comment['name'],
                    email = comment['email'],
                    website = comment['website'],
                    comment = comment['comment'],
                    comment_html = util.render(comment['comment'], 'text'),
                    status = comment['status'],
                    inserted = util.str_to_datetime( comment['inserted'] ),
                    updated = util.str_to_datetime( comment['updated'] ),
                )
                comment.put()
                msgs.append( 'Added comment [%s, %s]' % (comment.name, comment.email) )

        # now that we've added a node, regenerate it
        item.regenerate()

        # also, check that this section doesn't have duplicate content
        Task( params={ 'section_key': str(section.key()), 'name': item.name }, countdown=30, ).add( queue_name='section-check-duplicate-nodes' )

        vals = {
            'msgs'        : msgs,
            'node_type'   : node_type,
            'section_key' : section.key(),
            'data_type'   : data_type,
            }
        self.template( 'load-import.html', vals, 'admin' );
开发者ID:ranginui,项目名称:kohacon,代码行数:99,代码来源:load.py


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