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


Python Blog.save方法代码示例

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


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

示例1: update_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def update_blog(request):
    """
    Expects:{"username":"[email protected]","name":"Default","content":"This is some HTML"}\n

    1.Updates article for user\n
    2.Ensures unique blog name , (can be replaced by an custom ID field to allow duplicate blogs)\n
    3.Checks if the blogs username is registered
    4.Checks if the owner of the article in request is actually the owner

    TODO : Verify user login via session / Use PUT instead of POST / Use Partial update
    """

    if request.method == 'POST':

        queryset = Blog.objects.all()
        serializer = BlogSerilizer(data=request.data)
        updated_blog = request.data['name']
        userset = User.objects.all()

        for user in userset:
            if user.username == request.data['username']:
                for blogs in queryset:
                    if updated_blog == blogs.name:
                        if blogs.username == request.data['username']:
                            if serializer.is_valid():
                                blog_id = blogs.id
                                blog_obj = Blog(id=blog_id, name=updated_blog, content=request.data['content'],
                                                username=request.data['username'])
                                blog_obj.save(force_update=True)
                                return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(status=status.HTTP_412_PRECONDITION_FAILED)
开发者ID:jaideepkekre,项目名称:kekreblog,代码行数:33,代码来源:views.py

示例2: blog_add

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def blog_add():
    user_now = current_user()
    blog = Blog(request.form)
    blog.user = user_now
    blog.save()
    log('发布成功')
    return redirect(url_for('timeline_view', username=user_now.username))
开发者ID:Maluscore,项目名称:tweet,代码行数:9,代码来源:app.py

示例3: blog_add

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def blog_add(request):
    if request.method == 'POST':
        form = BlogForm(request.POST)
        tag = TagForm(request.POST)
        if form.is_valid() and tag.is_valid():
            cd = form.cleaned_data
            cdtag = tag.cleaned_data
            tagname = cdtag['tag_name']
            for taglist in tagname.split():
                Tag.objects.get_or_create(tag_name=taglist.strip())
            title = cd['caption']
            author = Author.objects.get(id=1)
            content = cd['content']
            blog = Blog(caption=title, author=author, content=content)
            blog.save()
            for taglist in tagname.split():
                blog.tags.add(Tag.objects.get(tag_name=taglist.strip()))
                blog.save()
            id = Blog.objects.order_by('-publish_time')[0].id
            return HttpResponseRedirect('blog/%s' % id)
    else:
        form = BlogForm()
        tag = TagForm(initial={'tag_name': 'notags'})
    return render_to_response('blog_add.html',
        {'form': form, 'tag': tag}, context_instance=RequestContext(request))
开发者ID:zhibzeng,项目名称:PythonCode,代码行数:27,代码来源:views.py

示例4: add

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def add(request):
    if request.user.is_authenticated():
        category= get_object_or_404(Category, category=request.POST.get('category'))
        blog = Blog(title=request.POST.get('title'), body=request.POST.get('body'),
                author=request.user, category=category)
        blog.save()
        return HttpResponseRedirect(reverse('Blog:main'))
    else:
        return HttpResponse("You are not logged in.")
开发者ID:hossamsalah,项目名称:django-Blog,代码行数:11,代码来源:views.py

示例5: new_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def new_blog(request):
	if request.method != 'POST':
		c = {}
		c.update(csrf(request))
		return render(request, "new_blog_form.html",c)
	else:
		blog = Blog(baslik=request.POST['baslik'],icerik=request.POST['icerik'],olusturulma_tarihi=datetime.today())
		blog.save()
		return redirect('/blog/list_blogs')
开发者ID:kkaba46,项目名称:ab2014-blog,代码行数:11,代码来源:views.py

示例6: new

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def new(request):
    blog = Blog()
    blog.title = 'This is a brand new blog.'
    blog.content = 'lalalallalalalalala'
    blog.created_at = datetime.datetime.now()

    blog.save()
    
    return HttpResponse('Save OK. <a href="/blog/view/%s/">view</a>'%blog.id)
开发者ID:blueidoo,项目名称:Tee,代码行数:11,代码来源:views.py

示例7: post

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def post(request):
    if (request.method=='POST'):
        data=JSONParser().parse(request)
        blog =  Blog()
        if(data['title'] and data['blogpost']):
            blog.title = data['title']
            blog.user = request.user
            blog.blogpost = data['blogpost']
            blog.save()
        return HttpResponseRedirect('/blog/userhome/',status=status.HTTP_200_OK)
开发者ID:vaishnavimerugu,项目名称:BlogIt,代码行数:12,代码来源:views.py

示例8: new_post

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def new_post(request,usrname):
    if request.method=='GET':
        return render_to_response('newpost.html',{'username':usrname})
    if request.method=='POST':
        topic=request.POST['topic']
        content=request.POST['content']
	date_str=request.POST['date']
	d=datetime.strptime(date_str,'%Y-%m-%d')
	date=d.date()
        blog=Blog(username=usrname,topic=topic,content=content,created=date)
        blog.save()
        return HttpResponse('/user/%s'%usrname)
开发者ID:arun-k,项目名称:blog_django,代码行数:14,代码来源:views.py

示例9: test_single_existence

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
 def test_single_existence(self):
     """Test that the blog is created only once """
     self.blog = Blog(title="test", tag_line="new blog", entries_per_page=10,
                     recents=5, recent_comments=5)
     self.blog.save()
     blog = Blog(title="test", tag_line="new blog", entries_per_page=10,
                 recents=5, recent_comments=5)
     #should raise Exception when another blog is created
     self.assertRaises(Exception, blog.save)
     blog = Blog.objects.get()
     blog.title = 'edited'
     blog.save()
     self.assertEqual(Blog.objects.count(), 1)
     self.assertEqual(Blog.objects.get().title, 'edited')
开发者ID:huan80s,项目名称:django-blogango,代码行数:16,代码来源:tests.py

示例10: parse

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def parse(rpc_raw, op_return_data, from_user_address, block_index, tx_id, block_time):
    from models import Blog
    if op_return_data[2:5] == "blg": #Non-Encrypted Blog Post
        if not Blog.objects.filter(key=op_return_data[5:]).exists():
            print "Found blogpost"
            new_blog = Blog(**{
                "address_from": from_user_address,
                "block_index": block_index,
                "tx_id": tx_id,
                "msg": "",
                "key": op_return_data[5:],
                "time": block_time
            })
            new_blog.save()
开发者ID:tariq786,项目名称:Peerapps,代码行数:16,代码来源:opreturn_scanner.py

示例11: add_blog_success

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def add_blog_success(request):
    logger.debug('enter success')
    if request.method == "POST":
        logger.debug('request.POST:' + str(request.POST))

        caption = request.POST['caption']
        content = request.POST['content']
        category = request.POST['category']
#        logger.debug('category======%s', str(dir(category)))
        c = Category.objects.get(name=category)
        b = Blog(caption=caption, content=content, category=c, user=request.user)
        b.save()

    return render_to_response('blog/add_blog_success.html', context_instance=RequestContext(request))
开发者ID:lpcpp,项目名称:www,代码行数:16,代码来源:views.py

示例12: blog_update

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def blog_update(request, id=""):
    id = id
    if request.method == 'POST':
        form = BlogForm(request.POST)
        tag = TagForm(request.POST)
        if form.is_valid() and tag.is_valid():
            cd = form.cleaned_data
            cdtag = tag.cleaned_data
            tagname = cdtag['tag_name']
            tagnamelist = tagname.split()
            for taglist in tagnamelist:
                Tag.objects.get_or_create(tag_name=taglist.strip())
            title = cd['caption']
            content = cd['content']
            blog = Blog.objects.get(id=id)
            if blog:
                blog.caption = title
                blog.content = content
                blog.save()
                for taglist in tagnamelist:
                    blog.tags.add(Tag.objects.get(tag_name=taglist.strip()))
                    blog.save()
                tags = blog.tags.all()
                for tagname in tags:
                    tagname = unicode(str(tagname), "utf-8")
                    if tagname not in tagnamelist:
                        notag = blog.tags.get(tag_name=tagname)
                        blog.tags.remove(notag)
            else:
                blog = Blog(caption=blog.caption, content=blog.content)
                blog.save()
            return HttpResponseRedirect('/blog/%s' % id)
    else:
        try:
            blog = Blog.objects.get(id=id)
        except Exception:
            raise Http404
        form = BlogForm(initial={'caption': blog.caption, 'content': blog.content}, auto_id=False)
        tags = blog.tags.all()
        if tags:
            taginit = ''
            for x in tags:
                taginit += str(x) + ' '
            tag = TagForm(initial={'tag_name': taginit})
        else:
            tag = TagForm()
    return render_to_response('blog_add.html',
        {'blog': blog, 'form': form, 'id': id, 'tag': tag},
        context_instance=RequestContext(request))
开发者ID:zhibzeng,项目名称:PythonCode,代码行数:51,代码来源:views.py

示例13: add_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def add_blog(request, blog_id=None):
    init_session_data(request)
    blog = Blog()
    if blog_id:
        blog.id = blog_id
    blog.title = 'New Blog'
    blog.content_body = ''
    blog.time = datetime.now()
    blog.save()
    request.session['articles_created'] = request.session['articles_created'].append(blog.id)
    request.session['edited_version'] = str(blog.version)
    request.session['blog_modified'] = str(blog.id)
    request.session['modification'] = 'add'

    return HttpResponseRedirect('/editblog/' + str(blog.id))
开发者ID:kiStephane,项目名称:MyBlog_Assignment,代码行数:17,代码来源:views.py

示例14: api_create_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def api_create_blog(request, *, name, summary, content):
    # 校验当前用户权限:
    check_admin(request)
    # 校验传递值中参数‘name’是否为空或空串,为空则抛出异常:
    if not name or not name.strip():
        # 参数‘name’为空则抛出异常:
        raise APIValueError("name", "name cannot be empty.")
    # 校验传递值中参数‘summary’是否为空或空串,为空则抛出异常:
    if not summary or not summary.strip():
        raise APIValueError("summary", "summary cannot be empty.")
    # 校验传递值中参数‘content’是否为空或空串,为空则抛出异常:
    if not content or not content.strip():
        raise APIValueError("content", "content cannot be empty.")
    # 创建Blog实例:
    blog = Blog(
        user_id=request.__user__.id,
        user_name=request.__user__.name,
        user_image=request.__user__.image,
        name=name.strip(),
        summary=summary.strip(),
        content=content.strip(),
    )
    # 将Blog信息存储到数据库:
    yield from blog.save()
    return blog
开发者ID:DeadAddict,项目名称:Python_L_Webapp,代码行数:27,代码来源:handlers.py

示例15: api_create_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import save [as 别名]
def api_create_blog(request, *, name, summary, content, hide, categorys_tag):
    check_admin(request)
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    if not hide:
        hide = False
    if not categorys_tag:
        raise APIValueError('categorys_tag', 'categorys_tag cannot be empty.')
    categorys_bit = yield from categorys_tag2bit(categorys_tag)
    blog = Blog(
        user_id=request.__user__.id,
        user_name=request.__user__.name,
        user_image=request.__user__.image,
        name=name.strip(),
        summary=summary.strip(),
        content=content.strip(),
        hide=hide,
        categorys_bit=categorys_bit
        )
    yield from blog.save()
    return blog
开发者ID:dramenk,项目名称:awesome,代码行数:27,代码来源:handlers.py


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