def get(self): post_id = self.get_argument('post_id') if not post_id: self.write(comments) self.finish() return query = 'select id, content, member_id, post_id, created, updated from comment where post_id = %s' _comments = db.query(query, post_id) if _comments: authors_id = [] for _comment in _comments: authors_id.append(str(_comment['member_id'])) _authors = db.query('select id, nick from member where id in (' + ','.join(authors_id) + ')') for _author in _authors: for _comment in _comments: if _comment['member_id'] == _author['id']: _comment['author'] = _author _comments = json.dumps(_comments, cls=modules.utils.JSONEncoder) comments = {'comments': _comments} self.write(comments) self.finish()
def __list(table_name, visible=1, deleted=0, user_id=None, category_id=None, offset=0, size=10): list_sql = """ select id, title, content, user_id, category_id, public, visible, if(updated is NULL, created, updated) last_modified from {0} where visible = %s and deleted = %s """.format(table_name) list = None if user_id and category_id: list_sql += 'and user_id = %s and category_id = %s order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, user_id, category_id, offset, size) elif user_id: list_sql += 'and user_id = %s order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, user_id, offset, size) elif category_id: list_sql += 'and category_id = %s order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, category_id, offset, size) else: list_sql += 'order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, offset, size) if list: for post in list: post['last_modified_format'] = post.last_modified.strftime( '%Y-%m-%d %H:%M:%S') post['last_modified'] = time.mktime( post.last_modified.timetuple()) return list
def get(self): query_category = 'select id, name from tb_category where user_id = %s' categories_id = [] categories = db.query(query_category, str(self.current_user.id)) if categories: for cate in categories: categories_id.append(str(cate.id)) cate_post_count_mapper = [] if len(categories_id) > 1: query_posts = 'select category_id, count(1) count from tb_post where category_id in {0} group by category_id'.format(tuple(categories_id)) elif len(categories_id) == 1: query_posts = 'select category_id, count(1) count from tb_post where category_id = {0}'.format(int(categories_id[0])) cate_post_count_mapper = db.query(query_posts) for cate in categories: for mapper in cate_post_count_mapper: cate['post_count'] = 0 if mapper.category_id == cate.id: cate['post_count'] = mapper.count self.render('setting.html', categories=categories)
def get(self, post_id=None): user_id = self.current_user.id post = None if post_id: _post = Post.get_post(post_id) if _post and _post.user_id == user_id: post = _post get_categories = 'select id, name from tb_category where visible = 1 and user_id = %s' categories = db.query(get_categories, user_id) referer = self.request.headers.get('Referer') or '/' self.render('edit.html', categories=categories, post=post, referer=referer)
def get(self): query_category = 'select id, name from tb_category where user_id = %s' categories_id = [] categories = db.query(query_category, str(self.current_user.id)) if categories: for cate in categories: categories_id.append(str(cate.id)) cate_post_count_mapper = [] if len(categories_id) > 1: query_posts = 'select category_id, count(1) count from tb_post where category_id in {0} group by category_id'.format( tuple(categories_id)) elif len(categories_id) == 1: query_posts = 'select category_id, count(1) count from tb_post where category_id = {0}'.format( int(categories_id[0])) cate_post_count_mapper = db.query(query_posts) for cate in categories: for mapper in cate_post_count_mapper: cate['post_count'] = 0 if mapper.category_id == cate.id: cate['post_count'] = mapper.count self.render('setting.html', categories=categories)
def post(self): post_id = self.get_body_argument('post_id', None) if post_id: query = 'select id, user_id from tb_post where id = %s and deleted = 0' _post = db.query(query) if _post and _post.id == post_id: update_public = 'update tb_post set public = 1 where id = %s' row_count = db.update(update_public, post_id) if row_count: self.send_result(True, error_code=None) return self.send_result() return self.send_result(error_code=constants.error_code['missing_parameters'])
def __list(table_name, visible=1, deleted=0, user_id=None, category_id=None, offset=0, size=10): list_sql = """ select id, title, content, user_id, category_id, public, visible, if(updated is NULL, created, updated) last_modified from {0} where visible = %s and deleted = %s """.format(table_name) list = None if user_id and category_id: list_sql += 'and user_id = %s and category_id = %s order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, user_id, category_id, offset, size) elif user_id: list_sql += 'and user_id = %s order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, user_id, offset, size) elif category_id: list_sql += 'and category_id = %s order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, category_id, offset, size) else: list_sql += 'order by last_modified desc limit %s, %s' list = db.query(list_sql, visible, deleted, offset, size) if list: for post in list: post['last_modified_format'] = post.last_modified.strftime('%Y-%m-%d %H:%M:%S') post['last_modified'] = time.mktime(post.last_modified.timetuple()) return list
def list(cls, user_id): query_list = 'select id, name from tb_category where user_id = %s' categories = db.query(query_list, user_id) return categories
def get(self): query_invite_record = 'select id, invitee_id, code, created, used from tb_invite where inviter_id = %s' records = db.query(query_invite_record, self.current_user.id) self.render('invite.html', records=records)