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


Python Category.get方法代码示例

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


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

示例1: POST

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import get [as 别名]
    def POST(self):
        def check(cate):
            parent=cate.parent_cat
            skey=cate.key()
            while parent:
                if parent.key()==skey:
                    return False
                parent=parent.parent_cat
            return True

        action=self.param("action")
        name=self.param("name")
        slug=self.param("slug")
        parentkey=self.param('parentkey')
        key=self.param('key')


        vals={'action':action,'postback':True}

        try:

                if action=='add':
                    cat= Category(name=name,slug=slug)
                    if not (name and slug):
                        raise Exception(_('Please input name and slug.'))
                    if parentkey:
                        cat.parent_cat=Category.get(parentkey)

                    cat.put()
                    self.redirect('/admin/categories')

                    #vals.update({'result':True,'msg':_('Saved ok')})
                    #self.render2('views/admin/category.html',vals)
                elif action=='edit':

                        cat=Category.get(key)
                        cat.name=name
                        cat.slug=slug
                        if not (name and slug):
                            raise Exception(_('Please input name and slug.'))
                        if parentkey:
                            cat.parent_cat=Category.get(parentkey)
                            if not check(cat):
                                raise Exception(_('A circle declaration found.'))
                        else:
                            cat.parent_cat=None
                        cat.put()
                        self.redirect('/admin/categories')

        except Exception ,e :
            if cat.is_saved():
                cates=[c for c in Category.all() if c.key()!=cat.key()]
            else:
                cates= Category.all()

            vals.update({'result':False,'msg':e.message,'category':cat,'key':key,'categories':cates})
            self.render2('views/admin/category.html',vals)
开发者ID:zy-sunshine,项目名称:sunblackshineblog,代码行数:59,代码来源:views.py

示例2: GET

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import get [as 别名]
    def GET(self,slug=None):
        action=self.param("action")
        key=self.param('key')
        category=None
        if action and  action=='edit':
                try:

                    category=Category.get(key)

                except:
                    pass
        else:
            action='add'
        vals={'action':action,'category':category,'key':key,'categories':[c for c in Category.all() if not category or c.key()!=category.key()]}
        self.render2('views/admin/category.html',vals)
开发者ID:zy-sunshine,项目名称:sunblackshineblog,代码行数:17,代码来源:views.py

示例3: new_post

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import get [as 别名]
def new_post(request):
    if request.method == 'POST': 
        form = AddNewPostForm(request.POST) # A form bound to the POST data
        
        if form.is_valid(): # All validation rules pass
            Post.objects.create(
                    author=request.user,
                    title=form.cleaned_data['post_title'],
                    content=form.cleaned_data['post_content'],
                    link=title_to_link(form.cleaned_data['post_title']),
                    publication_date=form.cleaned_data['post_publication_date'],
                    publish=form.cleaned_data['post_publish'],
                    category=Category.get(form.cleaned_data['post_category']),
                    tags=form.cleaned_data['post_tags'],
            )
            return HttpResponseRedirect('/blog') # Redirect after POST
    else:
        form = AddNewPostForm() # An unbound form

    return render(request, 'blog/new-post.html', 
            {'form': form})
开发者ID:pmosakowski,项目名称:homepage-blog,代码行数:23,代码来源:views.py


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