示例#1
0
def delete_category_lib(self, id):
    categorys = Category.by_id(id)
    tags = Tag.all()
    if categorys is None:
        return Category.all(), tags

    self.db.delete(categorys)
    self.db.commit()
    return Category.all(), tags
示例#2
0
def add_category_lib(self, name):
    category = Category.by_name(name)
    if category is not None:
        return {'status': False, 'msg': '该分类名已存在'}

    category = Category()
    category.name = name
    self.db.add(category)
    self.db.commit()
    return {'status': True, 'msg': '分类添加成功'}
示例#3
0
def search_article_lib(self, category_id, tag_id):
    if tag_id is not None:
        tag = Tag.by_id(tag_id)
        articles = tag.articles
    if category_id is not None:
        category = Category.by_id(category_id)
        articles = category.articles
    comments = dbSession.query(Comment).order_by(
        Comment.createtime.desc()).all()
    tags = Tag.all()
    categorys = Category.all()
    return articles, comments, tags, categorys
示例#4
0
def del_category_tag_lib(self, c_uuid, t_uuid):
    """05删除分类或者标签"""
    try:
        if c_uuid is not None:
            category = Category.by_uuid(c_uuid)
            if category is None:
                flash(self, '分类不存在', 'error')
                return {'status': False}
            if category.articles:
                flash(self, '分类下存在文章,清先删除文章再删除此分类', 'error')
                return {'status': False}
            self.db.delete(category)
            self.db.commit()
            flash(self, '分类删除成功', 'success')
            return {'status': True}
        if t_uuid is not None:
            tag = Tag.by_uuid(t_uuid)
            if tag:
                flash(self, '标签不存在', 'error')
            self.db.delete(tag)
            self.db.commit()
            flash(self, '标签删除成功', 'success')
            return {'status': True}
        flash(self, '标签或分类删除失败', 'error')
        return {'status': False}
    except Exception as e:
        flash(self, '标签或分类删除失败', 'error')
        return {'status': False}
示例#5
0
def del_category_tag_lib(self, c_uuid, t_uuid):
    """04删除标签和分类"""
    if c_uuid is not None:
        category = Category.by_uuid(c_uuid)
        if category is None:
            flash(self, '分类不存在', 'error')
            return {'status': False}
        if category.articles:
            flash(self, '分类下有文章请先删除文章', 'error')
            return {'status': False}
        self.db.delete(category)
        self.db.commit()
        flash(self, '分类删除成功', 'success')
        return {'status': True}
    if t_uuid is not None:
        tag = Tag.by_uuid(t_uuid)
        if tag is None:
            flash(self, '标签不存在', 'error')
            return {'status': False, 'msg': '标签不存在'}
        self.db.delete(tag)
        self.db.commit()
        flash(self, '标签删除成功', 'success')
        return {'status': True}
    flash(self, '请输入标签或分类', 'error')
    return {'status': False}
示例#6
0
def article_list_lib(self):
    """01文章列表页"""s
    articles = dbSession.query(Article).order_by(Article.createtime.desc()).all()
    comments = dbSession.query(Comment).order_by(Comment.createtime.desc()).all()
    tags = Tag.all()
    categorys = Category.all()
    return articles, comments, tags, categorys
示例#7
0
def add_category_tag_lib(self, category_name='', tag_name=''):
    ''' 添加文章的分类和标签 '''
    if category_name != '':
        category = Category.by_name(category_name)
        if category == None:
            category = Category()
            category.name = category_name
            self.db.add(category)
            self.db.commit()
    if tag_name != '':
        tag = Tag.by_name(tag_name)
        if tag == None:
            tag = Tag()
            tag.name = tag_name
            self.db.add(tag)
            self.db.commit()
    return {'status': True}
示例#8
0
def delete_tag_lib(self, id):
    tags = Tag.by_id(id)
    categorys = Category.all()
    if tags is None:
        return categorys, Tag.all()

    self.db.delete(tags)
    self.db.commit()
    return categorys, Tag.all()
示例#9
0
def del_category_tag_lib(self, category_uuid, tag_uuid):
    ''' 删除分类,标签 '''
    category = Category.by_uuid(category_uuid)
    tag = Tag.by_uuid(tag_uuid)
    if category != None:
        self.db.delete(category)
    if tag != None:
        self.db.delete(tag)
    self.db.commit()
    return {'status': True}
示例#10
0
def article_search_lib(self, category_id, tag_id):
    if tag_id != '':
        tag = Tag.by_id(tag_id)
        articles = tag.articles
    if category_id != '':
        category = Category.by_id(category_id)
        articles = category.articles

    tags, categorys = get_tags_categorys_lib(self)
    comments = Comment.all_createtime_desc()
    return articles, comments, categorys, tags
def article_search_list_lib(self, category_id, tag_id):
    '''查找'''
    if category_id != '':
        category = Category.by_id(category_id)  # 获取分类
        articles = category.articles  # 获取该分类的文章
    if tag_id != '':
        tag = Tag.by_id(tag_id)  # 获取标签
        articles = tag.articles  # 获取该标签的文章
    comments = Comment.all_createtime_desc()  # 获取所有评论
    tags, categorys = get_tags_categorys_lib(self)  # 获取标签和分类
    return articles, comments, categorys, tags  # 返回这些参数赋值给handler
示例#12
0
def add_category_tag_lib(self, category_name, tag_name):
    """03添加分类和标签"""
    if category_name is not None:
        category = Category.by_name(category_name)
        if category is not None:
            return {'status': False, 'msg': '分类已经存在'}
        else:
            category = Category()
        category.name = category_name
        self.db.add(category)
        self.db.commit()
        return {'status': True, 'msg': '分类添加成功'}
    if tag_name is not None:
        tag = Tag.by_name(tag_name)
        if tag is not None:
            return {'status': False, 'msg': '标签已经存在'}
        else:
            tag = Tag()
        tag.name = tag_name
        self.db.add(tag)
        self.db.commit()
        return {'status': True, 'msg': '标签添加成功'}
    return {'status': False, 'msg': '请输入标签或分类'}
def add_tags_categorys_lib(self, category_name, tag_name):
    '''管理标签'''
    if category_name != '':
        category = Category.by_name(category_name)
        if category is not None:
            return {'status': False, 'msg': '该分类名已存在!'}
        else:
            category = Category()
        category.name = category_name
        self.db.add(category)
        self.db.commit()
        return {'status': True, 'msg': '分类添加成功!'}

    if tag_name != '':
        tag = Tag.by_name(tag_name)
        if tag is not None:
            return {'status': False, 'msg': '该分类名已存在!'}
        else:
            tag = Tag()
            tag.name = tag_name
        self.db.add(tag)
        self.db.commit()
        return {'status': True, 'msg': '分类添加成功!'}
    return {'status': False, 'msg': '请添加分类或标签!'}
def delete_tags_categorys_lib(self, c_uuid, t_uuid):
    '''删除分类和标签'''
    category = Category.by_uuid(c_uuid)
    tag = Tag.by_uuid(t_uuid)

    if category is None and tag is None:
        tags, categorys = get_tags_categorys_lib(self)
        return tags, categorys
    if category is not None:
        self.db.delete(category)
        self.db.commit()

    print 'tag:%s' % tag

    if tag is not None:
        self.db.delete(tag)
        self.db.commit()
    print 'test.....'
    tags, categorys = get_tags_categorys_lib(self)
    return tags, categorys
示例#15
0
def get_tags_categorys_lib(self):
    tags = Tag.all()
    categorys = Category.all()
    return tags, categorys
示例#16
0
def get_tags_categorys_lib(self):
    """02返回标签和分类"""
    tags = Tag.all()
    categorys = Category.all()
    return tags, categorys
示例#17
0
def get_categoryid_lib(self):
    try:
        data = Category.by_name('计算机网络')
        return data.id
    except Exception as e:
        return
示例#18
0
def get_tags_categorys_lib(self):
    ''' 上传文章 的页面需要的数据 '''
    tags = Tag.all()
    categorys = Category.all()
    return tags, categorys
示例#19
0
def get_article_lib(self):
    articles = Article.all_createtime_desc()
    categorys = Category.all()
    tags = Tag.all()
    return articles, categorys, tags
示例#20
0
def get_tags_categorys(self):
    categorys = Category.all()
    tags = Tag.all()
    return categorys, tags
def get_tags_categorys_lib(self):
    '''获取标签和分类'''
    tags = Tag.all()
    categorys = Category.all()
    return tags, categorys