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


Python Blog.category方法代码示例

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


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

示例1: test_unicode

# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import category [as 别名]
 def test_unicode(self):
     """
     Scenario: Given a blog named Icecream
     Expected:
     - its unicode should be (<id>) Icecream
     """
     # Arrage
     blog = Blog(title='Icecream') 
     blog.user = self.user
     blog.category = self.category
     blog.location = self.location
     blog.save()
     printed_unicode = '(%s) Icecream' % blog.id
     # Act
     result = blog.__unicode__()
     # Assert
     self.assertEquals(printed_unicode, result)
开发者ID:opendream,项目名称:livestory,代码行数:19,代码来源:test_models.py

示例2: create_blog

# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import category [as 别名]
def create_blog(title='Icecream', user = None, category = None, location = None, mood=1, private=True, draft=False, tags='hastags,foo,bar', trash=False, allow_download=True):
    user = user or create_user()
    category = category or create_category()
    location = location or create_location()
    
    blog = Blog(title = title) 
    blog.user = user
    blog.category = category
    blog.location = location
    blog.mood = mood
    blog.private = private
    blog.draft = draft
    blog.trash = trash
    blog.allow_download = allow_download
    blog.save()
    blog.save_tags(tags)
    blog.image.save('blog_%s.jpg' % blog.id, DjangoFile(open('static/tests/blog.jpg'), 'blog.jpg'))
    blog.published = datetime.now()
    blog.save()
    
    return blog
开发者ID:opendream,项目名称:livestory,代码行数:23,代码来源:factory.py

示例3: blog_publish

# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import category [as 别名]
def blog_publish(request, whose):
    """
    发表博客
    前台使用的Ajax请求
    :param request:请求
    :param whose:当前请求用户的唯一标识
    :return:
    """
    if request.method == 'POST' and request.is_ajax():
        try:
            blog_title = request.POST['blogTitle']
            blog_content = request.POST['blogContent']
            category = request.POST['blogCategory']
            is_top = request.POST['top']
            is_star = request.POST['star']
            level = request.POST['level']
            key_words = request.POST['keyWords']
            status = request.POST['status']
        except KeyError:
            logger.debug('* 带非法参数请求,已经拒绝用户')
            raise Http404

        logger.debug('* BLOG TITLE:' + blog_title)
        logger.debug('* BLOG CONTENT:' + blog_content)
        logger.debug('* BLOG CATALOG:' + category)
        logger.debug('* BLOG TOP:' + is_top)
        logger.debug('* BLOG STAR:' + is_star)
        logger.debug('* BLOG LEVEL:' + level)
        logger.debug('* BLOG KEYS:' + key_words)
        logger.debug('* STATUS:' + status)
        # 使用博文表单验证对表单的合法性做确认
        form = BlogPublishForm(request.POST)
        user = User.objects.get(login_id=request.session['login_id'])
        exist = Blog.objects.filter(user=user, blog_title=blog_title).count() != 0
        response = {}
        if exist:
            response['error'] = 'error'
            response['msg'] = '当前博文标题已经存在于您的博客中,请修改标题'
            return HttpResponse(json.dumps(response), content_type='application/json')
        elif form.is_valid():
            logger.debug('* 信息均已经填写完整,通过表单验证,写入数据库')
            is_update_op = False
            if 'blogId' in request.POST:
                logger.debug("* 当前进行的操作是更新博文操作")
                is_update_op = True

            publish_ip = request.META['REMOTE_ADDR']
            print(color_format("* 客户端的IP地址是:{}".format(publish_ip), fore='cyan'))
            if is_update_op:
                blog = Blog.objects.get(user=user, blog_id=request.POST['blogId'])
                blog.update_date = datetime.datetime.now()
            else:
                blog = Blog()

            # 设值博文的标题
            blog.blog_title = blog_title
            # 设值博文发表的内容
            blog.blog_content = blog_content
            # 设置博文发表者的IP
            blog.publish_ip = publish_ip
            # 设置博文的分类
            blog.category = BlogCategory.objects.filter(user=user, category_id=category).first()
            blog.keywords = key_words
            blog.level = level
            blog.star = is_star == 'true'
            blog.top = is_top == 'true'
            blog.status = status
            blog.user_id = user.user_id
            blog.save()
            response['error'] = 'success'
            response['msg'] = '博客进入审核阶段,审核合法后发表'
        else:
            logger.debug('* 博客内容不完整')
            response['error'] = 'error'
            response['msg'] = '博客内容不完整'
        return HttpResponse(json.dumps(response), content_type='application/json')
    else:
        logger.debug('* 非法请求方式,已经拒绝用户')
        raise Http404
开发者ID:xuejiacore,项目名称:Loj,代码行数:81,代码来源:blogViews.py


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