def getInfoPost(id, related, cursor): id = int(id) query = '''select threadId, userEmail, parent, datePost, message, isEdited, isDeleted, isSpam, isHighlighted, isApproved, forumShortName, likes, dislikes, likes - dislikes from Post where postId = %s limit 1 ; ''' % (id) cursor.execute(query) rowPost = cursor.fetchone() isEdited = True if rowPost[5] == 1 else False isDeleted = True if rowPost[6] == 1 else False isSpam = True if rowPost[7] == 1 else False isHighlighted = True if rowPost[8] == 1 else False isApproved = True if rowPost[9] == 1 else False userEmail = rowPost[1] threadId = rowPost[0] forumShortName = rowPost[10] d = { "date": datetime.strftime(rowPost[3], '%Y-%m-%d %H:%M:%S'), "dislikes": rowPost[12], "likes": rowPost[11], "points": rowPost[13], "forum": forumShortName, "id": id, "isEdited": isEdited, "isDeleted": isDeleted, "isSpam": isSpam, "isHighlighted": isHighlighted, "isApproved": isApproved, "message": rowPost[4], "parent": rowPost[2], "thread": threadId, "user": userEmail } if 'user' in related: from views.User import getInfoUser d.update({'user': getInfoUser(userEmail, ['followers', 'following', 'subscriptions'], cursor)}) del getInfoUser if 'forum' in related: d.update({'forum': getInfoForum(forumShortName, [], cursor)}) if 'thread' in related: d.update({'thread': getInfoThread(threadId, [], cursor)}) return d
def getInfoThread(id, related, cursor): id = int(id) query = '''select date, forumShortName, isClosed, isDeleted, message, slug, title, userEmail, likes, dislikes, points, posts from Thread where threadId = %s limit 1 ; ''' % (id) cursor.execute(query) rowThread = cursor.fetchone() isClosed = True if rowThread[2] == 1 else False isDeleted = True if rowThread[3] == 1 else False forumShortName = rowThread[1] userEmail = rowThread[7] d = { "date": datetime.strftime(rowThread[0], '%Y-%m-%d %H:%M:%S'), "forum": forumShortName, "id": id, "isClosed": isClosed, "isDeleted": isDeleted, "message": rowThread[4], "slug": rowThread[5], "title": rowThread[6], "user": userEmail, "dislikes": rowThread[9], "likes": rowThread[8], "points": rowThread[10], "posts": rowThread[11] } if 'user' in related: from views.User import getInfoUser d.update({'user': getInfoUser(userEmail, ['followers', 'following', 'subscriptions'], cursor)}) del getInfoUser if 'forum' in related: from views.Forum import getInfoForum d.update({'forum': getInfoForum(forumShortName, [], cursor)}) del getInfoForum return d