def details(forum, related=None): if not related: related = [] query = Query.SELECT.format( columns='*', table=Tables.TABLE_NAMES['FORUM'] ) + Query.WHERE.format( clause='short_name = %r' % str(forum) ) connection = db_connect.get_connection() try: cursor = connection.cursor() cursor.execute(query) response = dictfetchall(cursor)[0] except Exception as e: return Codes.UNKNOWN_ERROR, str(e) finally: connection.close() code = Codes.OK if 'user' in related: code, response['user'] = User.details(response['user']) return code, response
def details(): request_data = get_json(request) code, response = User.details(request_data['user']) return json.dumps({ 'code': code, 'response': response })
def details(short_name, related=None): if not related: related = [] code, result = Forum.get_forum(short_name) if code == Codes.OK and 'user' in related: code, result['user'] = User.details(result['user']) return code, result
def list_by_forum(forum, request, related=None): if not related: related = [] code, result = Post.get_posts_by_forum(forum, related, request) if code != Codes.OK: return code, result for post in result: if 'user' in related: code, post['user'] = User.details(post['user']) return code, result
def details(post_id, related=None): if not related: related = [] code, result = Post.get_post(post_id) if code != Codes.OK: return code, result if code == Codes.OK and 'user' in related: code, result['user'] = User.details(result['user']) if code == Codes.OK and 'forum' in related: code, result['forum'] = Forum.details(result['forum']) if code == Codes.OK and 'thread' in related: code, result['thread'] = Thread.details(result['thread']) return code, result
def details(thread_id, related=None): if not related: related = [] if 'thread' in related: return Codes.NOT_CORRECT, 'Thread can\'t be in related' code, result = Thread.get_thread(thread_id) if code != Codes.OK: return code, result if code == Codes.OK and 'user' in related: code, result['user'] = User.details(result['user']) if code == Codes.OK and 'forum' in related: code, result['forum'] = Forum.details(result['forum'], None) return code, result
def details(post, related=None): if not related: related = [] columns = 'p.id, p.message, p.date, p.isApproved, p.isHighlighted, p.isEdited, p.isSpam, ' \ 'p.isDeleted, p.forum, p.thread, p.user, p.dislikes, p.likes, p.points, p.parent' if 'forum' in related: columns += ', f.name f_name, f.short_name f_short_name, f.user f_user, f.id f_id' if 'thread' in related: columns += ', t.id t_id, t.forum t_forum, t.title t_title, t.isClosed t_isClosed, ' \ 't.user t_user, t.date t_date, t.message t_message, t.slug t_slug, t.isDeleted t_isDeleted, ' \ 't.posts t_posts, t.likes t_likes, t.dislikes t_dislikes, t.points t_points' query = Query.SELECT.format( columns=columns, table=Tables.TABLE_NAMES['POST'] + ' as p' ) if 'forum' in related: query += Query.JOIN.format( table=Tables.TABLE_NAMES['FORUM'] + ' as f', clause='p.forum = f.short_name' ) if 'thread' in related: query += Query.JOIN.format( table=Tables.TABLE_NAMES['THREAD'] + ' as t', clause='p.thread = t.id' ) query += Query.WHERE.format( clause='p.id = %s' % post ) connection = db_connect.get_connection() try: cursor = connection.cursor() cursor.execute(query) response = dictfetchall(cursor)[0] except Exception as e: if 'list index out of range' in str(e): return Codes.NOT_FOUND, 'Post %s not found' % post else: return Codes.UNKNOWN_ERROR, str(e) finally: connection.close() response = Post.get_response_values(response) code = Codes.OK if 'thread' in related: response['t_date'] = str(response['t_date']) response['t_isDeleted'] = bool(response['t_isDeleted']) response['t_isClosed'] = bool(response['t_isClosed']) response['thread'] = {} keys = [] for val in response: if val[:2] == 't_': response['thread'][val[2:]] = response[val] keys.append(val) for key in keys: del response[key] if 'forum' in related: response['forum'] = {} keys = [] for val in response: if val[:2] == 'f_': response['forum'][val[2:]] = response[val] keys.append(val) for key in keys: del response[key] if 'user' in related: code, response['user'] = User.details(response['user']) return code, response
def list_by_forum(forum, request, related=None): if not related: related = [] if 'order' not in request: request['order'] = 'DESC' columns = 'p.id, p.message, p.date, p.likes, p.dislikes, p.points, p.isApproved, ' \ 'p.isHighlighted, p.isEdited, p.isSpam, p.isDeleted, p.forum, p.thread, p.user, p.parent' if 'forum' in related: columns += ', f.id f_id, f.name f_name, f.short_name f_short_name, f.user f_user' if 'thread' in related: columns += ', t.id t_id, t.title t_title, t.slug t_slug, t.message t_message, t.date t_date, ' \ 't.posts t_posts, t.likes t_likes, t.dislikes t_dislikes, t.points t_points, ' \ 't.isClosed t_isClosed, t.isDeleted t_isDeleted, t.forum t_forum, t.user t_user' query = Query.SELECT.format( columns=columns, table=Tables.TABLE_NAMES['POST'] + ' as p' ) if 'forum' in related: query += Query.JOIN.format( table=Tables.TABLE_NAMES['FORUM'] + ' as f', clause='p.forum = f.short_name' ) if 'thread' in related: query += Query.JOIN.format( table=Tables.TABLE_NAMES['THREAD'] + ' as t', clause='p.thread = t.id' ) query += Query.WHERE.format( clause='p.forum = %r' % str(forum) ) if 'since' in request: query += Query.AND_CLAUSE.format( clause='p.date > %r' % str(request['since']) ) query += Query.ORDER_BY.format( column='p.date', type=request['order'] ) if 'limit' in request: query += Query.LIMIT.format( count=request['limit'] ) connection = db_connect.get_connection() try: cursor = connection.cursor() cursor.execute(query) posts = dictfetchall(cursor) except Exception as e: return Codes.UNKNOWN_ERROR, str(e) finally: connection.close() response = [] code = Codes.OK for post in posts: if 'forum' in related: post['forum'] = {} keys = [] for val in post: if val[:2] == 'f_': post['forum'][val[2:]] = post[val] keys.append(val) for key in keys: del post[key] if 'thread' in related: post['thread'] = {} keys = [] for val in post: if val[:2] == 't_': post['thread'][val[2:]] = post[val] keys.append(val) for key in keys: del post[key] post['thread'] = Thread.get_response_values(post['thread']) if 'user' in related: code, post['user'] = User.details(post['user']) response.append(Post.get_response_values(post)) return code, response