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