Example #1
0
def update(category_id, category_name):
    category = DBSession().query(Category).get(category_id)

    if not category:
        raise PostExc('Category with id {} is not exist.'.format(category_id))

    category.name = category_name
Example #2
0
def delete(post_id):
    session = DBSession()
    post = session.query(Post).get(post_id)

    if not post:
        raise PostExc(
            'Delete Error! Post with id {} is not exist.'.format(post_id))

    # Do not actually delete the post
    post.status = Post.STATUS_DELETED
Example #3
0
def delete(post_id):
    session = DBSession()
    post = session.query(Post).get(post_id)

    if not post:
        raise PostExc('Delete Error! Post with id {} is not exist.'
                      .format(post_id))

    # Do not actually delete the post
    post.status = Post.STATUS_DELETED
Example #4
0
def add(title, content, status=Post.STATUS_DRAFT, category_id=-1, tag=''):
    session = DBSession()
    new_post = Post(
        author_id=-1,#current_user.id,
        title=title,
        content=content,
        status=status,
        category_id=category_id,
    )
    session.add(new_post)
    session.flush()

    if tag:
        tag_base.add(tag, new_post.id)

    return new_post.id
Example #5
0
def get(post_id, count_pv=False):
    post = DBSession().query(Post).get(post_id)

    if not post:
        raise PostExc('Post with id {} is not exist.'.format(post_id))

    if count_pv:
        incre_pv(post.id)

    return post
Example #6
0
def query(category_id=None, status=None, tag=None, offset=0, limit=20):
    session = DBSession()
    q = session.query(Post)

    if category_id is not None:
        q = q.filter(Post.category_id == category_id)

    if status is not None:
        q = q.filter(Post.status == status)

    if tag is not None:
        q = q.filter(Post.tag == tag)

    if offset is not None:
        q = q.offset(offset)

    if limit is not None:
        q = q.limit(min(limit, max_query_size))

    return q.all()
Example #7
0
def query(category_id=None, status=None, tag=None, offset=0, limit=20):
    session = DBSession()
    q = session.query(Post)

    if category_id is not None:
        q = q.filter(Post.category_id == category_id)

    if status is not None:
        q = q.filter(Post.status == status)

    if tag is not None:
        q = q.filter(Post.tag == tag)

    if offset is not None:
        q = q.offset(offset)

    if limit is not None:
        q = q.limit(min(limit, max_query_size))

    return q.all()
Example #8
0
def add(title, content, status=Post.STATUS_DRAFT, category_id=-1, tag=''):
    session = DBSession()
    new_post = Post(
        author_id=-1,  #current_user.id,
        title=title,
        content=content,
        status=status,
        category_id=category_id,
    )
    session.add(new_post)
    session.flush()

    if tag:
        tag_base.add(tag, new_post.id)

    return new_post.id
Example #9
0
def get(name):
    return DBSession.query(User).filter(User.name == name).first()
Example #10
0
def check_pwd(user):
    return DBSession().query(User).\
        filter(User.password == user.password).\
        filter(User.is_admin == 1).first() is not None
Example #11
0
def incre_pv(post_id):
    post = DBSession().query(Post).get(post_id)
    if post:
        post.pv += 1
Example #12
0
def add(tag_name, post_id):
    post_tag = Tag(name=tag_name, post_id=post_id)
    DBSession().add(post_tag)
Example #13
0
def delete(tag_name, post_id):
    DBSession().query(Tag).\
        filter(Tag.name == tag_name).\
        filter(post_id=post_id).delete()
Example #14
0
def delete(category_id):
    DBSession().query(Category).get(category_id).delete()
Example #15
0
def query():
    return DBSession().query(Category).all()
Example #16
0
def add(category_name):
    new_category = Category(name=category_name)
    DBSession().add(new_category)