• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Blog类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: post

 def post(self):
   """
   Post method to like and unlike blogs
   """
   if self.user:
     if self.request.get("like_blog"):
       _blog_id = self.request.get("like_blog")
       user = self.user
       user_id = user.key.id()
       _user = User.by_id(int(user_id))
       _blog = Blog.get_by_id(int(_blog_id))
       like = Like(user=user.key, blog=_blog.key)
       like.like = 1
       like_key = like.put()
       blog = _blog.key.get()
       blog.likes.append(like_key)
       blog.put()
       self.redirect('/')
     if self.request.get("dislike"):
       _blog_id = self.request.get("dislike")
       user = self.user
       user_id = user.key.id()
       _user = User.by_id(int(user_id))
       _blog = Blog.get_by_id(int(_blog_id))
       like = Like.query(Like.user == user.key, Like.blog == _blog.key).get()
       like_key = like.key
       blog = _blog.key.get()
       blog.likes.remove(like_key)
       blog.put()
       like_key.delete()
       self.redirect('/')
   else:
     self.redirect('/login')
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:33,代码来源:blog.py


示例2: post

    def post(self):
        update = self.request.get('update', False)
        cate_name = self.request.get('cate_name')
        tags_list = self.request.get_all('tags_name', [])
        title = self.request.get('title')
        blog = self.request.get('blog')
        if not blog:
            self.response.write('blog content empty!')

        cate = Category.query(Category.title==cate_name).get()
        if not cate:
            cate = Category(title=cate_name)
            cate.put()
        print tags_list
        tags = Tag.query(Tag.title.IN(tags_list)).fetch()
        tags_old = [tag.title for tag in tags]
        tags_new = []
        for tag in tags_list:
            if tag not in tags_old:
                tag = Tag(title=tag)
                tag.put()
                tags_new.append(tag)
        print tags
        print tags_new
        tags += tags_new
        print tags
        print '==='
        print dir(tags[0])
        tags = [tag.key for tag in tags]

        blog = Blog(title=title, text=blog, category=cate.key, tags=tags)
        blog.put()
        self.response.write('blog publish success')
        self.response.set_status(200)
开发者ID:hackrole,项目名称:gblog,代码行数:34,代码来源:blog.py


示例3: _get_blogs_by_page

def _get_blogs_by_page():
	total = Blog.count_all()
	
	page = Page(total, _get_page_index())
	blogs = Blog.find_by(' order by create_at desc limit ?,?', page.offset, page.limit)
	
	return blogs,page
开发者ID:SharpZKing,项目名称:awesome-python-webapp,代码行数:7,代码来源:urls.py


示例4: api_create_blog

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


示例5: test_get_select_posts_bytag

    def test_get_select_posts_bytag(self):
        blog = Blog('tests/data/feed.xml')

        selected = blog.select_posts_bytag(u'鏡館')

        for p in selected:
            self.assertTrue(u'鏡館' in p.tags)
开发者ID:so-c,项目名称:nozomi_miraha,代码行数:7,代码来源:test_blog.py


示例6: update_blog

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


示例7: blog_add

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


示例8: blog_add

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


示例9: index

def index(request):
    context = base_context()
    rpp = record_per_page()
    cur_page = 1
    try:
        cur_page = int(request.REQUEST["jumpPage"].strip())
    except:
        cur_page = 1

    blogs_count = Blog.all().count()
    max_page = blogs_count / rpp
    temp2 = blogs_count % rpp
    if temp2 != 0:
        max_page = max_page + 1

    if cur_page > max_page or cur_page <= 0:
        cur_page = max_page
        blogs = Blog.all().order("-date").fetch(0)
    else:
        blogs = Blog.all().order("-date").fetch(rpp, rpp * (cur_page - 1))

    context.cur_page = cur_page
    context.max_page = max_page
    context.action_mode = "/"
    context.range1 = range(1, max_page + 1)
    context.up_page = cur_page - 1
    context.down_page = cur_page + 1
    context.blogs = blogs
    template = loader.get_template("blogs/index.html")
    return HttpResponse(template.render(context))
开发者ID:proming,项目名称:myblogongae,代码行数:30,代码来源:views.py


示例10: Post

    def Post(self):
        title = self.Request.get("title")
        content = self.Request.get("content")

        blog = Blog(title=title, content=content)
        blog.put()
        return webapp2.redirect("/blog")
开发者ID:hackrole,项目名称:GAE_project,代码行数:7,代码来源:blog.py


示例11: api_create_blog

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


示例12: api_delete_blog

def api_delete_blog(blog_id):
    check_admin()
    blog = Blog.get(blog_id)
    blog = Blog.get(blog_id)
    if blog is None:
        raise APIResourceNotFoundError("Blog")
    blog.delete()
    return dict(id=blog_id)
开发者ID:cnu4,项目名称:awesome-blog,代码行数:8,代码来源:urls.py


示例13: api_index

def api_index(*, page="1"):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber("count(id)")
    p = Page(num, page_index, page_size=5)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = yield from Blog.findAll(orderBy="created_at desc", limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
开发者ID:naphystart,项目名称:PersonalBlog,代码行数:8,代码来源:handlers.py


示例14: api_blogs

def api_blogs(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
开发者ID:hellozmz,项目名称:awesome_python3_webapp,代码行数:8,代码来源:handlers.py


示例15: test_single_existence

 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())
     self.blog.delete()
开发者ID:Anoopsmohan,项目名称:django-blogango,代码行数:8,代码来源:tests.py


示例16: index

def index(*, page="1"):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber("count(id)")
    p = Page(num, page_index, page_size=5)
    blogs = yield from Blog.findAll(orderBy="created_at desc", limit=(p.offset, p.limit))
    for blog in blogs:
        blog.html_summary = markdown2.markdown(blog.summary)
    return {"__template__": "blogs.html", "page_index": get_page_index(page), "blogs": blogs}
开发者ID:naphystart,项目名称:PersonalBlog,代码行数:8,代码来源:handlers.py


示例17: add

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


示例18: new_blog

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


示例19: add_entry

def add_entry():
    if not session.get('logged_in'):
        abort(401)
    blog = Blog()
    blog.title = cgi.escape(request.form['title'])
    blog.text = cgi.escape(request.form['text'])
    blog.put()
    flash('New entry was successfully posted')
    return redirect(url_for('show_entries'))
开发者ID:miquelet,项目名称:flask_projects,代码行数:9,代码来源:app.py


示例20: myapi_blogs

def myapi_blogs(request,*, page='1'):
    where_user='user_name='+'\''+request.__user__.name+'\''
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)',where=where_user)
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = yield from Blog.findAll(where=where_user,orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
开发者ID:daihaovigg,项目名称:web,代码行数:9,代码来源:handlers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.BlogPost类代码示例发布时间:2022-05-27
下一篇:
Python models.Author类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap