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


Python Category.name方法代码示例

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


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

示例1: test_create_post_without_tag

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_create_post_without_tag(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Log in
        self.client.login(username='bobsmith', password="password")

        # Check response code
        response = self.client.get('/admin/blog/post/add/')
        self.assertEquals(response.status_code, 200)

        # Create the new post
        response = self.client.post('/admin/blog/post/add/', {
            'title': 'My first post',
            'text': 'This is my first post',
            'pub_date_0': '2013-12-28',
            'pub_date_1': '22:00:04',
            'slug': 'my-first-post',
            # 'site': '1',
            'category': '1'
        },
                                    follow=True
        )
        self.assertEquals(response.status_code, 200)

        # Check added successfully
        self.assertTrue('added successfully' in response.content)

        # Check new post now in database
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
开发者ID:digisnaxx,项目名称:digidex,代码行数:36,代码来源:tests.py

示例2: test_creating_a_new_post_and_saving_it_to_the_database

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

示例3: test_edit_category

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_edit_category(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Log in
        self.client.login(username='bobsmith', password="password")

        # Edit the category
        response = self.client.post('/admin/blogengine/category/1/', {
            'name': 'perl',
            'description': 'The Perl programming language'
            }, follow=True)
        self.assertEquals(response.status_code, 200)

        # Check changed successfully
        self.assertTrue('changed successfully' in response.content)

        # Check category amended
        all_categories = Category.objects.all()
        self.assertEquals(len(all_categories), 1)
        only_category = all_categories[0]
        self.assertEquals(only_category.name, 'perl')
        self.assertEquals(only_category.description, 'The Perl programming language')
开发者ID:kngeno,项目名称:Djangoblog,代码行数:28,代码来源:tests.py

示例4: post

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def post(self):
        from .models import FontIcon,FontIconLibrary
        iconclass = None
        i = request.form.get('icon',None) 
        if i is not None:

            lib,icon = i.split('-')[0],i.split('-')[1:]
            iconclass = FontIcon.query.filter(FontIcon.name==''.join(map(str,icon)),FontIconLibrary.name==lib).first()

        self._context['form_args'] = {'heading':self._form_heading}
        self._form = self._form(request.form)
        if self._form.validate():
            from blog.models import Category
            c = Category.query.filter(Category.name==self._form.name.data).first()
            if c is None:
                c = Category()
                if iconclass is not None:
                    c.icon_id = iconclass.id
                c.name = self._form.name.data
                c.description = self._form.description.data
                c.save()
                self.flash('You added category: {}'.format(c.name))
                if request.args.get('last_url'):
                    return self.redirect(request.args.get('last_url'),raw=True)
            else:
                self.flash('There is already a category by that name, try again')
        return self.redirect('core.index')
开发者ID:c0debrain,项目名称:flask-cms,代码行数:29,代码来源:views.py

示例5: addCategory

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

示例6: addCategory

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

示例7: test_validate_account

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_validate_account(self):
        site = Site.objects.get_current().domain
        user = BlogUser.objects.create_superuser(email="[email protected]",
                                                 username="liangliangyy1", password="liangliangyy1")

        self.client.login(username='liangliangyy1', password='liangliangyy1')
        response = self.client.get('/admin/')
        self.assertEqual(response.status_code, 200)

        category = Category()
        category.name = "categoryaaa"
        category.created_time = datetime.datetime.now()
        category.last_mod_time = datetime.datetime.now()
        category.save()

        article = Article()
        article.title = "nicetitleaaa"
        article.body = "nicecontentaaa"
        article.author = user
        article.category = category
        article.type = 'a'
        article.status = 'p'
        article.save()

        response = self.client.get(article.get_admin_url())
        self.assertEqual(response.status_code, 200)
开发者ID:lutianba2014,项目名称:DjangoBlog,代码行数:28,代码来源:tests.py

示例8: test_all_post_feed

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_all_post_feed(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '[email protected]', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()
 
        # Create a post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.category = category

        # Save it
        post.save()

        # Add the tag
        post.tags.add(tag)
        post.save()

        # Check we can find it
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Fetch the feed
        response = self.client.get('/feeds/posts/')
        self.assertEquals(response.status_code, 200)

        # Parse the feed
        feed = feedparser.parse(response.content)

        # Check length
        self.assertEquals(len(feed.entries), 1)

        # Check post retrieved is the correct one
        feed_post = feed.entries[0]
        self.assertEquals(feed_post.title, post.title)
        self.assertEquals(feed_post.description, post.text)
开发者ID:kngeno,项目名称:Djangoblog,代码行数:62,代码来源:tests.py

示例9: test_creating_a_new_comment_and_saving_it_to_the_database

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

示例10: test_validate_comment

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_validate_comment(self):
        site = Site.objects.get_current().domain
        user = BlogUser.objects.create_superuser(email="[email protected]",
                                                 username="liangliangyy1", password="liangliangyy1")

        self.client.login(username='liangliangyy1', password='liangliangyy1')

        c = Category()
        c.name = "categoryccc"
        c.created_time = datetime.datetime.now()
        c.last_mod_time = datetime.datetime.now()
        c.save()

        article = Article()
        article.title = "nicetitleccc"
        article.body = "nicecontentccc"
        article.author = user
        article.category = c
        article.type = 'a'
        article.status = 'p'
        article.save()
        s = TextMessage([])
        s.content = "nicetitleccc"
        rsp = search(s, None)
        self.assertTrue(rsp != '没有找到相关文章。')
        rsp = category(None, None)
        self.assertIsNotNone(rsp)
        rsp = recents(None, None)
        self.assertTrue(rsp != '暂时还没有文章')

        cmd = commands()
        cmd.title = "test"
        cmd.command = "ls"
        cmd.describe = "test"
        cmd.save()

        cmdhandler = CommandHandler()
        rsp = cmdhandler.run('test')
        self.assertIsNotNone(rsp)
        s.source = 'u'
        s.content = 'test'
        msghandler = MessageHandler(s, {})

        #msghandler.userinfo.isPasswordSet = True
        #msghandler.userinfo.isAdmin = True
        msghandler.handler()
        s.content = 'y'
        msghandler.handler()
        s.content='idcard:12321233'
        msghandler.handler()
        s.content='weather:上海'
        msghandler.handler()
        s.content='admin'
        msghandler.handler()
        s.content='123'
        msghandler.handler()

        s.content = 'exit'
        msghandler.handler()
开发者ID:lutianba2014,项目名称:DjangoBlog,代码行数:61,代码来源:tests.py

示例11: POST

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

示例12: test_edit_posts

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_edit_posts(self):
        category = Category()
        category.name = 'python'
        category.description = 'The python language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        author = User.objects.create_user('testuser', '[email protected]', 'password')
        author.save()

        # site = Site()
        # site.name = 'nunfuxgvn.com'
        # site.domain = 'nunfuxgvn.com'
        # site.save()


        post = Post()
        post.title = 'First Post'
        post.content = 'My first post -yay'
        post.slug = 'first-post'
        post.pub_date = timezone.now()
        post.author = author
        # post.site = site
        post.save()
        post.tags.add(tag)
        post.save()

        self.client.login(username='bobsmith', password='password')

        response = self.client.post('/admin/blog/post/1/', {
            'title': 'Second Post',
            'text': 'This is my second post',
            'pub_date_0': '2014-07-17',
            'pub_date_1': '11:49:24',
            'slug': 'second-post',
            # 'site': '1',
            'category': '1',
            'tags': '1'
        },
                                    follow=True
        )
        self.assertEquals(response.status_code, 200)

        # Check post successfully changed
        self.assertTrue('changed successfully' in response.content)

        # Check post amended 
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post.title, 'Second Post')
        self.assertEquals(only_post.content, 'This is my second post')
开发者ID:digisnaxx,项目名称:digidex,代码行数:59,代码来源:tests.py

示例13: test_delete_post

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_delete_post(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '[email protected]', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()
        
        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.site = site
        post.author = author
        post.category = category
        post.save()
        post.tags.add(tag)
        post.save()

        # Check new post saved
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)

        # Log in
        self.client.login(username='bobsmith', password="password")

        # Delete the post
        response = self.client.post('/admin/blogengine/post/1/delete/', {
            'post': 'yes'
        }, follow=True)
        self.assertEquals(response.status_code, 200)

        # Check deleted successfully
        self.assertTrue('deleted successfully' in response.content)

        # Check post deleted
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 0)
开发者ID:kngeno,项目名称:Djangoblog,代码行数:57,代码来源:tests.py

示例14: test_category_page

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_category_page(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the author
        author = User.objects.create_user('testuser', '[email protected]', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()

        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is [my first blog post](http://127.0.0.1:8000/)'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.category = category
        post.save()

        # Check new post saved
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Get the category URL
        category_url = post.category.get_absolute_url()

        # Fetch the category
        response = self.client.get(category_url)
        self.assertEquals(response.status_code, 200)

        # Check the category name is in the response
        self.assertTrue(post.category.name in response.content)

        # Check the post text is in the response
        self.assertTrue(markdown.markdown(post.text) in response.content)

        # Check the post date is in the response
        self.assertTrue(str(post.pub_date.year) in response.content)
        self.assertTrue(post.pub_date.strftime('%b') in response.content)
        self.assertTrue(str(post.pub_date.day) in response.content)

        # Check the link is marked up properly
        self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
开发者ID:kngeno,项目名称:Djangoblog,代码行数:56,代码来源:tests.py

示例15: test_index

# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import name [as 别名]
    def test_index(self):
        category = Category()
        category.name = 'python'
        category.description = 'The python language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'perl'
        tag.description = 'The Perl programming language'
        tag.save()

        author = User.objects.create_user('testuser', '[email protected]', 'password')
        author.save()

        # site = Site()
        # site.name = 'nunfuxgvn.com'
        # site.domain = 'nunfuxgvn.com'
        # site.save()

        post = Post()
        post.title = 'First Post'
        post.content = 'My [first post](http://127.0.0.1:8000/) -yay'
        post.slug = 'first-post'
        post.pub_date = timezone.now()
        post.author = author
        # post.site = site
        post.category = category
        post.save()
        post.tags.add(tag)

        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)

        # Fetch test_index
        response = self.client.get('/')
        self.assertEquals(response.status_code, 200)

        self.assertTrue(post.title in response.content)

        self.assertTrue(markdown.markdown(post.content) in response.content)

        self.assertTrue(post.category.name in response.content)

        post_tag = all_posts[0].tags.all()[0]
        self.assertTrue(post_tag.name in response.content)

        self.assertTrue(str(post.pub_date.year) in response.content)
        self.assertTrue(post.pub_date.strftime('%b') in response.content)
        self.assertTrue(str(post.pub_date.day) in response.content)

        self.assertTrue('<a href="http://127.0.0.1:8000/">first post</a>' in response.content)
开发者ID:digisnaxx,项目名称:digidex,代码行数:54,代码来源:tests.py


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