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


Python Category.slug方法代码示例

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


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

示例1: addCategory

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
def addCategory(request):
    name = request.POST['name']
    slug = request.POST['slug']
    desc = request.POST['desc']
    type = request.POST['type']
    pid = request.POST['category_parent']
    if pid == '0':
        pid = None
    if type and type == 'add':
        try:
            cats=Category.objects.filter(name=name)
            if cats.count() >= 1:
                messages.add_message(request,messages.INFO,'categry [%s] already exits!'%(name))
            else:
                cat = Category(name=name,slug=slug,desc=desc,parent_id=pid)
                cat.save()
                messages.add_message(request,messages.INFO,'categry [%s] save ok!'%(name))
        except Exception as e:
            print 'exception:',e
    elif type and type == 'edit':
        id = request.POST.get('id','')
        cat = Category.objects.get(id=id)
        cat.name=name
        cat.slug=slug
        cat.desc=desc
        cat.parent_id = pid
        cat.save()
    return HttpResponseRedirect('/admin/categories')
开发者ID:zhigoo,项目名称:youflog,代码行数:30,代码来源:admin.py

示例2: addCategory

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
def addCategory(request):
    if request.method=='POST':
        name = request.POST['name']
        slug = request.POST['slug']
        desc = request.POST['desc']
        type = request.POST['type']
        if type and type == 'add':
            try:
                cats=Category.objects.filter(name=name)
                if cats.count() >= 1:
                    messages.add_message(request,messages.INFO,'categry [%s] already exits!'%(name))
                else:
                    cat = Category(name=name,slug=slug,desc=desc)
                    cat.save()
                    messages.add_message(request,messages.INFO,'categry [%s] save ok!'%(name))
            except:
                pass
                
        elif type and type == 'edit':
            id = request.POST.get('id','')
            cat = Category.objects.get(id=id)
            cat.name=name
            cat.slug=slug
            cat.desc=desc
            cat.save()
        return HttpResponseRedirect('/admin/categories')
开发者ID:Spoylerman,项目名称:libaoyinblog,代码行数:28,代码来源:admin.py

示例3: test_creating_a_new_comment_and_saving_it_to_the_database

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
 def test_creating_a_new_comment_and_saving_it_to_the_database(self):
     # start by create one Category and one post
     category = Category()
     category.name = "First"
     category.slug = "first"
     category.save()
     
     # create new post
     post = Post()
     post.category = category
     post.title = "First post"
     post.content = "Content"
     post.visable = True
     post.save()
     
     # create one comment
     comment = Comment()
     comment.name = "John"
     comment.content = "This is cool"
     comment.post = post
     
     # check save
     comment.save()
     
     # now check we can find it in the database
     all_comment_in_database = Comment.objects.all()
     self.assertEquals(len(all_comment_in_database), 1)
     only_comment_in_database = all_comment_in_database[0]
     self.assertEquals(only_comment_in_database, comment)
     
     # and check that it's saved its two attributes: name and content
     self.assertEquals(only_comment_in_database.name, comment.name)
     self.assertEquals(only_comment_in_database.content, comment.content)
开发者ID:pabllo87,项目名称:Ultra-simple-blog,代码行数:35,代码来源:models.py

示例4: test_creating_a_new_post_and_saving_it_to_the_database

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
 def test_creating_a_new_post_and_saving_it_to_the_database(self):
     # start by create one Category
     category = Category()
     category.name = "First"
     category.slug = "first"
     category.save()
     
     # create new post
     post = Post()
     post.category = category
     post.title = "First post"
     post.content = "Content"
     post.visable = True
     
     # check we can save it
     post.save()
     
     # check slug
     self.assertEquals(post.slug, "first-post")
     
     # now check we can find it in the database
     all_post_in_database = Post.objects.all()
     self.assertEquals(len(all_post_in_database), 1)
     only_post_in_database = all_post_in_database[0]
     self.assertEquals(only_post_in_database, post)
     
     # check that it's saved all attributes: category, title, content, visable and generate slug
     self.assertEquals(only_post_in_database.category, category)
     self.assertEquals(only_post_in_database.title, post.title)
     self.assertEquals(only_post_in_database.content, post.content)
     self.assertEquals(only_post_in_database.visable, post.visable)
     self.assertEquals(only_post_in_database.slug, post.slug)
开发者ID:pabllo87,项目名称:Ultra-simple-blog,代码行数:34,代码来源:models.py

示例5: POST

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [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

示例6: test_create_category

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
    def test_create_category(self):
        category = Category()

        category.name = 'python'
        category.description = 'The python language'
        category.slug = 'python'

        category.save()

        all_categories = Category.objects.all()
        self.assertEquals(len(all_categories), 1)
        only_category = all_categories[0]
        self.assertEquals(only_category, category)

        self.assertEquals(only_category.name, 'python')
        self.assertEquals(only_category.description, 'The python language')
        self.assertEquals(only_category.slug, 'python')
开发者ID:digisnaxx,项目名称:digidex,代码行数:19,代码来源:tests.py

示例7: test_creating_a_new_category_and_saving_it_to_the_database

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
    def test_creating_a_new_category_and_saving_it_to_the_database(self):
        # start by createing a new Category object
        category = Category()
        category.name = "First"
        category.slug = "first"

        # check we can save it to the database
        category.save()

        # now check we can find it in the database again
        all_category_in_database = Category.objects.all()
        self.assertEquals(len(all_category_in_database), 1)
        only_category_in_database = all_category_in_database[0]
        self.assertEquals(only_category_in_database, category)

        # and check that it's saved its two attributes: name and slug
        self.assertEquals(only_category_in_database.name, category.name)
        self.assertEquals(only_category_in_database.slug, category.slug)
开发者ID:pabllo87,项目名称:Ultra-simple-blog,代码行数:20,代码来源:models.py

示例8: test_unique_slug_generate

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
 def test_unique_slug_generate(self):
     # start by create one Category
     category = Category()
     category.name = "First"
     category.slug = "first"
     category.save()
     
     # create new posts
     post1 = Post(category=category, title="First post", content="Content", visable=True)
     post1.save()
     
     post2 = Post(category=category, title="First post", content="Content", visable=True)
     post2.save()
     
     # check posts then it's the same title
     self.assertEquals(post1.title, post2.title)
     # and different slug
     self.assertNotEquals(post1.slug, post2.slug)
开发者ID:pabllo87,项目名称:Ultra-simple-blog,代码行数:20,代码来源:models.py


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