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


Python Tag.save方法代码示例

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


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

示例1: post_new

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def post_new(request):
    """新建文章"""
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            # 开始处理标签
            print post.author
            ptags = request.POST['tags'].strip()
            all_tags = []
            if ptags:
                tags = ptags.split(',')
                for tag in tags:
                    try:
                        t = Tag.objects.get(name=tag)
                    except Tag.DoesNotExist:
                        t = Tag(name=tag)
                        t.save()
                    all_tags.append(t)
            post.save()
            for tg in all_tags:
                post.tags.add(tg)
            return redirect('blog.views.post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render_to_response('post_edit.html', {'form': form, 'is_new': True},context_instance=RequestContext(request))
开发者ID:bingfengblog,项目名称:bingfengblog,代码行数:29,代码来源:views.py

示例2: handle

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
    def handle(self, *args, **options):
        user = \
            get_user_model().objects.get_or_create(email='[email protected]', username='测试用户',
                                                   password='[email protected]#eTYU')[0]

        pcategory = Category.objects.get_or_create(name='我是父类目', parent_category=None)[0]

        category = Category.objects.get_or_create(name='子类目', parent_category=pcategory)[0]

        category.save()
        basetag = Tag()
        basetag.name = "标签"
        basetag.save()
        for i in range(1, 20):
            article = Article.objects.get_or_create(category=category,
                                                    title='nice title ' + str(i),
                                                    body='nice content ' + str(i),
                                                    author=user
                                                    )[0]
            tag = Tag()
            tag.name = "标签" + str(i)
            tag.save()
            article.tags.add(tag)
            article.tags.add(basetag)
            article.save()

        from DjangoBlog.utils import cache
        cache.clear()
        self.stdout.write(self.style.SUCCESS('created test datas \n'))
开发者ID:lutianba2014,项目名称:DjangoBlog,代码行数:31,代码来源:create_testdata.py

示例3: test_edit_tag

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

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

        # Edit the tag
        response = self.client.post('/admin/blogengine/tag/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 tag amended
        all_tags = Tag.objects.all()
        self.assertEquals(len(all_tags), 1)
        only_tag = all_tags[0]
        self.assertEquals(only_tag.name, 'perl')
        self.assertEquals(only_tag.description, 'The Perl programming language')
开发者ID:kngeno,项目名称:Djangoblog,代码行数:28,代码来源:tests.py

示例4: Index

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def Index(request):
	if request.POST:
		if not request.user.is_authenticated():
			return redirect('/login/')
		form = PostForm(request.POST)
		if form.is_valid():
			submitted_title = request.POST['title']
			submitted_content = request.POST['content']
			submmited_tags = request.POST['tags']
			pub_date = datetime.now()
			new_post = Post(title=submitted_title, 
							content=submitted_content, pub_date=pub_date)
			new_post.save()
			submmited_tags = submmited_tags.replace(',', ',')
			tags = submmited_tags.split(',')
			for tag in tags:
				tag.strip()
				new_tag = Tag(post=new_post, name=tag)
				new_tag.save()
	""" request.GET """
	ctx = {}
	posts = Post.objects.all().order_by('-pub_date')
	tags = Tag.objects.all()
	post_form = PostForm()
	ctx.update(csrf(request))
	ctx['posts'] = posts
	ctx['tags'] = tags
	ctx['form'] = post_form
	return render(request, 'blog/index.html', ctx)
开发者ID:yhfyhf,项目名称:Django-Blog,代码行数:31,代码来源:views.py

示例5: test_all_post_feed

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

示例6: blog_entry_add_view

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def blog_entry_add_view(request):
    """
    lets superusers add a blog entry
    :param request:
    :return:
    """
    options = blogAttributes()
    entryForm = EntryForm()
    options['form'] = entryForm
    options['tags'] = Tag.objects.all()
    if request.POST and request.method == 'POST':
        entryForm = EntryForm(request.POST)
        if entryForm.is_unique(request):
            entry = entryForm.customSave(request.user)
            # loop through the tags
            if len(entry.tags) > 0:
                tags = entry.tags.split(',')
                for tag in tags:
                    # if the tag doesn't exist
                    if not Tag.objects.filter(name=tag).exists():
                        # save the tag
                        t = Tag()
                        t.name = tag
                        t.save()
            messages.add_message(request, messages.SUCCESS, 'The Entry has been saved')
            return redirect(blog_view)
        else:
            messages.add_message(request, messages.ERROR, 'An Entry with this Title already exists')

    return render_to_response('entryForm.html', options, context_instance=RequestContext(request))
开发者ID:huayuev5,项目名称:potato-blog-example,代码行数:32,代码来源:views.py

示例7: blog_entry_edit_view

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def blog_entry_edit_view(request, eID):
    """
    lets superusers edit a blog entry
    :param request:
    :return:
    """
    options = blogAttributes()
    entry = get_object_or_404(Entry, id=eID)
    options['entry'] = entry
    options['form'] = EntryForm(instance=entry)
    if request.POST and request.method == 'POST':
        entryForm = EntryForm(request.POST, instance=get_object_or_404(Entry, id=eID))
        if entryForm.is_unique(request, entry):
            if entryForm.has_changed():
                entry = entryForm.customSave(request.user)
                # loop through the tags
                if len(entry.tags) > 0:
                    tags = entry.tags.split(',')
                    for tag in tags:
                        # if the tag doesn't exist
                        if not Tag.objects.filter(name=tag).exists():
                            # save the tag
                            t = Tag()
                            t.name = tag
                            t.save()
                messages.add_message(request, messages.SUCCESS, 'The Entry has been updated')
                return redirect(blog_entry_view, titleSlug=entry.title_slug)
            else:
                messages.add_message(request, messages.INFO, 'No changes have been made')
        else:
            messages.add_message(request, messages.ERROR, 'An Entry with this Title already exists')

    return render_to_response('entryForm.html', options, context_instance=RequestContext(request))
开发者ID:huayuev5,项目名称:potato-blog-example,代码行数:35,代码来源:views.py

示例8: check_or_create_tag

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def check_or_create_tag(name):
    try:
        x = Tag.objects.get(slug=name)
    except Tag.DoesNotExist:
        x = Tag(name)
        x.slug = name.strip()
        x.save()
    print x
    return x
开发者ID:encima,项目名称:potato-blog,代码行数:11,代码来源:views.py

示例9: test_edit_posts

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

示例10: addtag

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def addtag(request):
	tag_name=request.GET.get('tag_name')
	newtag=Tag()
	newtag.tag_name=tag_name
	newtag.save()
	id=newtag.id
	tag={'id':id,'tag_name':tag_name}
	tag=json.dumps(tag)
	return HttpResponse(tag)
开发者ID:strong-ge,项目名称:firstBlog,代码行数:11,代码来源:views.py

示例11: test_delete_post

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

示例12: test_tag_page

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
    def test_tag_page(self):
        # 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](http://127.0.0.1:8000/)'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.save()
        post.tags.add(tag)

        # 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 tag URL
        tag_url = post.tags.all()[0].get_absolute_url()

        # Fetch the tag
        response = self.client.get(tag_url)
        self.assertEquals(response.status_code, 200)

        # Check the tag name is in the response
        self.assertTrue(post.tags.all()[0].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

示例13: test_index

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

示例14: test_delete_post

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
    def test_delete_post(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.test = 'My first post'
        post.slug = 'first-post'
        post.pub_date = timezone.now()
        post.author = author
        # post.site = site
        post.save()
        post.tags.add(tag)
        post.save()

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

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

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

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

        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 0)
开发者ID:digisnaxx,项目名称:digidex,代码行数:47,代码来源:tests.py

示例15: setTags

# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import save [as 别名]
def setTags(entry, tags):
    
    if tags is None:
        entry.tags = []
    else:
        try:
            # Check if we got a movable type style category array of structs
            if type(tags[0]) == dict:
                # We have a MT style list of IDs.
                tags = getTagsFromMT(tags)
        except:
            pass
        # Create any tags that don't exist yet, and then add them to the entry
        for tag in tags:
            if len(Tag.objects.filter(tag__iexact=tag)) == 0:
                new_tag = Tag()
                new_tag.tag = tag
                new_tag.save()
        entry.tags = [Tag.objects.get(tag__iexact=tag) for tag in tags]
开发者ID:nicholasstudt,项目名称:django-blog,代码行数:21,代码来源:utils.py


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