Exemplo n.º 1
0
def add_article_lib(self,article_id, title, content, desc, category_id, tags):
    """02添加新文章"""
    if category_id is None or tags is None:
    #if id('') == id(None):
        return {'status': False, 'msg': '请选择分类'}
    if title is None or content is None or desc is None:
        return {'status': False, 'msg': '请输入标题或文章内容'}
    if article_id != '':
        article = Article.by_id(article_id)
        article.tags = []
    else:
        article = Article()
    article.content = content
    article.title = title
    article.desc = desc
    article.category_id = category_id
    for tag_id in tags:
        tag = Tag.by_id(tag_id)
        article.tags.append(tag)
    article.user_id = self.current_user.id
    self.db.add(article)
    self.db.commit()
    if article_id is not None:
        return {'status': True, 'msg': '文档修改成功'}
    return {'status': True, 'msg': '文档添加成功'}
Exemplo n.º 2
0
def add_article_lib(self, title, content, desc, category_id, thumbnail, tags,
                    article_id):
    if category_id == '' or tags == []:
        return {'status': False, 'msg': '请选择分类或标签'}

    if title == '' or content == '' or desc == '':
        return {'status': False, 'msg': '请输入标题、内容、摘要'}

    if article_id != '':
        article = Article.by_id(article_id)
        article.tags = []
    else:
        article = Article()
    article.title = title
    article.content = content
    article.desc = desc
    article.category_id = category_id
    article.thumbnail = thumbnail
    for tags_id in tags:
        tag = Tag.by_id(tags_id)
        article.tags.append(tag)
    article.user_id = self.current_user.id
    self.db.add(article)
    self.db.commit()
    if article_id != '':
        return {'status': True, 'msg': '文档修改成功!'}
    return {'status': True, 'msg': '文档提交成功!'}
Exemplo n.º 3
0
def add_article_lib(self, title, content, desc, category_id, thumbnail, tags,
                    article_id):
    ''' 上传文章  及修改文章 '''
    if category_id == '' or tags == '':
        return {'status': False, 'msg': '请选择分类或者标签'}

    if title == '' or content == '' or desc == '':
        return {'status': False, 'msg': '请输入标题,内容, 简介'}

    if article_id != '':
        print '2-' * 19
        article = Article.by_id(article_id)
        article.tags = []

    else:
        print '-1-' * 10
        article = Article()
    article.content = content
    article.title = title
    article.desc = desc
    article.category_id = category_id
    article.thumbnail = thumbnail

    for tags_id in tags:
        tag = Tag.by_id(tags_id)
        article.tags.append(tag)

    article.user_id = self.current_user.id
    self.db.add(article)
    self.db.commit()
    if article_id != '':
        return {'status': True, 'msg': '文档修改成功'}
    return {'status': True, 'msg': '文档提交成功'}
Exemplo n.º 4
0
def add_article_lib(self, title, content, desc, category_id, thumbnail, tags,
                    article_id):
    '''发布新闻'''
    if category_id == '' or tags == '':
        return {'status': False, 'msg': '请选择分类或者标签!'}

    if title == '' or content == '' or desc == '':
        return {'status': False, 'msg': '请输入标题、内容、简介!'}

    # 判断文章是否存在,存在则是编辑,不存在则是新增
    if article_id != '':
        article = Article.by_id(article_id)
        article.tags = []  # 如果文章已存在,则避免标签重复,这里直接将标签置空
    else:
        article = Article()
    article.content = content
    article.title = title
    article.desc = desc
    article.category_id = category_id
    article.thumbnail = thumbnail

    for tags_id in tags:
        tag = Tag.by_id(tags_id)
        article.tags.append(tag)

    article.user_id = self.current_user.id
    self.db.add(article)
    self.db.commit()

    if article_id != '':
        return {'status': True, 'msg': '文档修改成功!'}
    return {'status': True, 'msg': '文档提交成功!'}
Exemplo n.º 5
0
def add_article_lib(self, article_id, title, content, desc, category,
                    thumbnail, tags):
    """03增加文章"""
    print title, content, desc
    if category is None or tags is None:
        return {'status': False, 'msg': '请选择分类和标签'}
    if title is None or content is None or desc is None:
        return {'status': False, 'msg': '请输入文章或内容'}
    if article_id != '':
        article = Article.by_id(article_id)
        article.tags = []
    else:
        article = Article()
    article.content = content
    article.title = title
    article.desc = desc
    article.category_id = category
    for tag in tags:
        tag = Tag.by_id(tag)
        article.tags.append(tag)
    article.user_id = self.current_user.id
    self.db.add(article)
    self.db.commit()
    if article_id is not None:
        return {'status': True, 'msg': '文档修改成功'}
    return {'status': True, 'msg': '文档上传成功'}
Exemplo n.º 6
0
def articles_delete_lib(self, article_id):
    if article_id is None:
        return {'status': False, 'msg': '文章ID不存在'}
    article = Article.by_id(article_id)
    if article is not None:
        self.db.delete(article)
        self.db.commit()
    return Article.all()
Exemplo n.º 7
0
def article_delete_lib(self, article_id):
    article = Article.by_id(article_id)
    if article is None:
        return Article.all()

    self.db.delete(article)
    self.db.commit()
    return Article.all()
Exemplo n.º 8
0
def article_delete_lib(self, article_id):
    '''删除文章'''
    article = Article.by_id(article_id)
    if article is None:
        return Article.all()
    self.db.delete(article)
    self.db.commit()
    # flash (self, '请输入角色名称!', 'error')
    return Article.all()
Exemplo n.º 9
0
def del_article_lib(self, article_id):
    ''' 删除文章 '''
    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '文章已经不存在'}
    self.db.delete(article)
    self.db.commit()
    # articles = Article.all()
    return {'status': True}
Exemplo n.º 10
0
def article_content_lib(self, article_id):
    if article_id is None:
        return {'status': False, 'msg': '缺少文章ID'}
    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '文章不存在'}
    article.readnum += 1
    self.db.add(article)
    self.db.commit()
    return {'status': True, 'msg': '获取到文章', 'data': article}
Exemplo n.º 11
0
def add_comment_lib(self, content, article_id):

    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '文章不存在'}

    comment = Comment()
    comment.content = content
    comment.article_id = article.id
    comment.user_id = self.current_user.id
    self.db.add(comment)
    self.db.commit()
    return {'status': True, 'msg': '评论成功'}
Exemplo n.º 12
0
def add_article_like_lib(self, article_id):
    ''' 点赞与取消点赞 '''
    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '该文章不存在'}
    if self.current_user in article.user_likes:
        article.user_likes.remove(self.current_user)
        self.db.add(article)
        self.db.commit()
        return {'status': True, 'msg': '取消了点赞'}
    article.user_likes.append(self.current_user)
    self.db.add(article)
    self.db.commit()
    return {'status': True, 'msg': '点赞成功'}
Exemplo n.º 13
0
def add_comment_lib(self, content, article_id):
    '''添加评论'''
    if content == '':
        return {'status': False, 'msg': '请输入评论!'}

    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '文档不存在!'}

    comment = Comment()
    comment.content = content
    comment.article_id = article.id
    comment.user_id = self.current_user.id
    self.db.add(comment)
    self.db.commit()
    return {'status': True, 'msg': '评论成功!'}
Exemplo n.º 14
0
def add_like_lib(self, article_id):
    """09点赞添加"""
    if article_id is None:
        return {'status': False, 'msg': '文章ID不存在'}
    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '文章ID不正确'}
    if self.current_user in article.user_likes:
        article.user_likes.remove(self.current_user)
        self.db.add(article)
        self.db.commit()
        return {'status': True, 'msg': '您已经取消点赞了'}
    article.user_likes.append(self.current_user)
    self.db.add(article)
    self.db.commit()
    return {'status': True, 'msg': '点赞成功'}
Exemplo n.º 15
0
def add_like_lib(self, article_id):
    '''点赞'''
    if article_id is None:
        return {'status': False, 'msg': '文章不存在!'}

    article = Article.by_id(article_id)
    if article is None:
        return {'status': False, 'msg': '文章不存在!'}

    # 对当前用户是否存在user_like,存在执行取消点赞,不再执行点赞
    if self.current_user in article.user_likes:
        # 取消点赞
        article.user_likes.remove(self.current_user)
        self.db.add(article)
        self.db.commit()
        return {'status': True, 'msg': '取消点赞!'}

    # 点赞执行:
    article.user_likes.append(self.current_user)
    self.db.add(article)
    self.db.commit()
    return {'status': True, 'msg': '评论成功!'}
Exemplo n.º 16
0
def article_info_libs(self, id):
    article = Article.by_id(id)
    return article
Exemplo n.º 17
0
def article_lib(self, article_id):
    ''' 显示文章详情页 '''
    article = Article.by_id(article_id)
    comments = article.comments

    return article, comments
Exemplo n.º 18
0
def get_article_things(self, article_id):
    ''' 修改的文章的详细 '''
    article = Article.by_id(article_id)
    tags, categorys = get_tags_categorys_lib(self)

    return article, categorys, tags
Exemplo n.º 19
0
def article_modify_lib(self,article_id):
    if article_id is None:
        return {'status': False, 'msg': '文章ID 不存在'}
    article = Article.by_id(article_id)
    tags, categorys = get_tags_categorys_lib(self)
    return article, categorys, tags
Exemplo n.º 20
0
def get_article_tags_categorys_lib(self, article_id):
    article = Article.by_id(article_id)
    tags, categorys = get_tags_categorys_lib(self)
    return article, tags, categorys
Exemplo n.º 21
0
def article_lib(self, article_id):
    article = Article.by_id(article_id)
    comments = article.comments
    return article, comments
Exemplo n.º 22
0
def article_modify_lib(self, id):
    article = Article.by_id(id)
    category, tags = get_tags_categorys(self)
    return article, category, tags