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


Python models.Tag类代码示例

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


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

示例1: post_new

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,代码行数:27,代码来源:views.py

示例2: Index

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,代码行数:29,代码来源:views.py

示例3: blog_entry_add_view

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,代码行数:30,代码来源:views.py

示例4: blog_entry_edit_view

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,代码行数:33,代码来源:views.py

示例5: test_edit_tag

    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,代码行数:26,代码来源:tests.py

示例6: test_all_post_feed

    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,代码行数:60,代码来源:tests.py

示例7: admin_edit_post

def admin_edit_post(request, post_id):
    
    if users.is_current_user_admin():
        
        post = Post.get_by_id(int(post_id))
        if not post:
            raise Http404
        
        if request.method == 'GET':
            tp = Tag_Post.all().filter('post', post)
            
            tags = ''
            # Get all tags
            for tag in tp:
                tags += tag.tag.title + ','
                
            form = PostForm({'title':post.title, 'category':post.category.key(), 'content':post.content, 'tags':tags})
            
        elif request.method == 'POST':
            
            form = PostForm(request.POST)
            
            if form.is_valid():
                
                # delete related tag_post
                for tp in post.tags:
                    tp.delete()

                p = form.save(commit=False)
                post.author = users.get_current_user()
                post.category = p.category
                post.content = p.content
                post.put()

                # add tag_post
                tagText = request.POST['tags']
                if tagText:
                    tags = tagText.split(',')
                    for tag in tags:
                        if tag:
                            tag = string.lower(string.strip(tag))

                            t = Tag.all().filter("title = ", unicode(tag, "utf-8")).get()
                            if not t:

                                t = Tag(title=unicode(tag, "utf-8"))
                                t.put()
                            Tag_Post(tag=t, post=post).put()

            return HttpResponseRedirect('/admin')
        
        return render_to_response('admin/edit.html',
                                      dictionary={ 'form':form,
                                                    'type': 'Edit Post',
                                                     },
                                      context_instance=RequestContext(request)
                                    )
    else:
        return HttpResponseRedirect('/')
开发者ID:kylewu,项目名称:wwb_wwblog,代码行数:59,代码来源:admin_views.py

示例8: addtag

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,代码行数:9,代码来源:views.py

示例9: check_or_create_tag

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,代码行数:9,代码来源:views.py

示例10: test_edit_posts

    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,代码行数:57,代码来源:tests.py

示例11: test_delete_post

    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,代码行数:55,代码来源:tests.py

示例12: test_tag_page

    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,代码行数:54,代码来源:tests.py

示例13: action_update_tags

    def action_update_tags(self,slug=None):
        for tag in Tag.all():
            tag.delete()
        for entry in Entry.all().filter('entrytype =','post'):
            if entry.tags:
                for t in entry.tags:
                    try:
                        Tag.add(t)
                    except:
                        traceback.print_exc()

        self.write(_('"All tags for entry have been updated."'))
开发者ID:zy-sunshine,项目名称:sunblackshineblog,代码行数:12,代码来源:views.py

示例14: test_index

    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,代码行数:52,代码来源:tests.py

示例15: get_tags

def get_tags(tags):
    """
        Get tags from request info.
    """
    assert isinstance(tags, basestring)
    
    # comma separator
    tags = tags.split(',')
    for tag in tags:
        tag = tag.strip()
        Tag.get_or_insert(tag, tag=tag)
        
    return tags
开发者ID:Jessi18,项目名称:BloGAE,代码行数:13,代码来源:handlers.py


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