Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 9
0
def get(name):
    return DBSession.query(User).filter(User.name == name).first()
Ejemplo n.º 10
0
def check_pwd(user):
    return DBSession().query(User).\
        filter(User.password == user.password).\
        filter(User.is_admin == 1).first() is not None
Ejemplo n.º 11
0
def incre_pv(post_id):
    post = DBSession().query(Post).get(post_id)
    if post:
        post.pv += 1
Ejemplo n.º 12
0
def add(tag_name, post_id):
    post_tag = Tag(name=tag_name, post_id=post_id)
    DBSession().add(post_tag)
Ejemplo n.º 13
0
def delete(tag_name, post_id):
    DBSession().query(Tag).\
        filter(Tag.name == tag_name).\
        filter(post_id=post_id).delete()
Ejemplo n.º 14
0
def delete(category_id):
    DBSession().query(Category).get(category_id).delete()
Ejemplo n.º 15
0
def query():
    return DBSession().query(Category).all()
Ejemplo n.º 16
0
def add(category_name):
    new_category = Category(name=category_name)
    DBSession().add(new_category)