예제 #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
예제 #2
0
파일: post.py 프로젝트: petercuichen/cblog
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
예제 #3
0
파일: post.py 프로젝트: pycuichen/cblog
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
예제 #4
0
파일: post.py 프로젝트: pycuichen/cblog
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
예제 #5
0
파일: post.py 프로젝트: petercuichen/cblog
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
예제 #6
0
파일: post.py 프로젝트: petercuichen/cblog
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()
예제 #7
0
파일: post.py 프로젝트: pycuichen/cblog
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()
예제 #8
0
파일: post.py 프로젝트: petercuichen/cblog
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
예제 #9
0
파일: user.py 프로젝트: petercuichen/cblog
def get(name):
    return DBSession.query(User).filter(User.name == name).first()
예제 #10
0
파일: user.py 프로젝트: petercuichen/cblog
def check_pwd(user):
    return DBSession().query(User).\
        filter(User.password == user.password).\
        filter(User.is_admin == 1).first() is not None
예제 #11
0
파일: post.py 프로젝트: petercuichen/cblog
def incre_pv(post_id):
    post = DBSession().query(Post).get(post_id)
    if post:
        post.pv += 1
예제 #12
0
def add(tag_name, post_id):
    post_tag = Tag(name=tag_name, post_id=post_id)
    DBSession().add(post_tag)
예제 #13
0
def delete(tag_name, post_id):
    DBSession().query(Tag).\
        filter(Tag.name == tag_name).\
        filter(post_id=post_id).delete()
예제 #14
0
def delete(category_id):
    DBSession().query(Category).get(category_id).delete()
예제 #15
0
def query():
    return DBSession().query(Category).all()
예제 #16
0
def add(category_name):
    new_category = Category(name=category_name)
    DBSession().add(new_category)