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


Python Page.set_derivatives方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import set_derivatives [as 别名]
    def post(self):
        item = None
        vals = {}
        try:
            # get all the incoming values
            section = Section.get( self.request.get('section') )
            name = self.request.get('name').strip()
            title = self.request.get('title').strip()
            content = self.request.get('content')
            type = self.request.get('type')
            label_raw = self.request.get('label_raw').strip()
            attribute_raw = util.make_attr_raw_string(
                {
                    'index-entry'   : self.request.get('index_entry'),
                    'has-comments'  : self.request.get('has_comments'),
                    'comments-open' : self.request.get('comments_open'),
                    }
                ).strip()

            # some pre-processing of the input params
            if name == '':
                name = util.urlify(self.request.get('title'))

            if self.request.get('key'):
                item = Page.get( self.request.get('key') )
                item.section = section
                item.name = name
                item.title = title
                item.content = content
                item.type = type
                item.label_raw = label_raw
                item.attribute_raw = attribute_raw
            else:
                item = Page(
                    section = section,
                    name = name,
                    title = title,
                    content = content,
                    type = type,
                    label_raw = label_raw,
                    attribute_raw = attribute_raw,
                    )

            # update and save this page
            item.set_derivatives()
            item.put()
            # once saved, regenerate certain section properties
            section.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' )
            self.redirect('.')
        except Exception, err:
            vals['item'] = self.request.POST
            vals['err'] = err
            vals['sections'] = Section.all()
            vals['types'] = models.type_choices
            self.template( 'page-form.html', vals, 'admin' );
开发者ID:ranginui,项目名称:kohacon,代码行数:59,代码来源:page.py

示例2: post

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import set_derivatives [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.set_derivatives方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。