def list(request): forum = request.GET.get("forum") thread = request.GET.get("thread") since = request.GET.get("since") limit = request.GET.get("limit") order = request.GET.get("order") sql = "SELECT * from Post where 1=1 " if forum != None: sql += "and forum='%s' " % forum elif thread != None: sql += "and thread='%s' " % thread if since != None: sql += "and date>'%s' " % since if order != None: if order == "asc": sql += "order by date ASC " else: sql += "order by date DESC " if limit != None: sql += "limit %s" % limit result = sql_select(sql) resultSet = [] for data in result: params = { "user": data[1], "thread": data[2], "forum": data[3], "date": data[4].strftime("%Y-%m-%d %H:%M:%S"), "message": data[5], "isApproved": data[6], "isHighlighted": data[7], "isEdited": data[8], "isSpam": data[9], "isDeleted": data[10], } post = Post(params) post.id = data[0] post.likes = data[11] post.dislikes = data[12] post.points = post.likes - post.dislikes post.parent = ( Converter.from_hex_to_dec(data[13][-10:-5]) if data[13] != Converter.from_dec_to_hex(int(post.id)) else None ) resultSet.append(post.serialize()) resp = {"code": 0, "response": resultSet} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json")
def listPosts(request): user = request.GET.get('user') since = request.GET.get('since') limit = request.GET.get('limit') order = request.GET.get('order') sql = "SELECT * from Post where 1=1 " sql += "and user='******' " % user if since != None: sql += "and date>'%s' " % since if order != None: if order == "asc": sql += "order by date ASC " else: sql += "order by date DESC " if limit != None: sql += "limit %s" % limit result = sql_select(sql) resultSet = [] for data in result: params = {'user': data[1], 'thread': data[2], 'forum': data[3], 'date': data[4].strftime("%Y-%m-%d %H:%M:%S"), 'message': data[5], 'isApproved': data[6], 'isHighlighted': data[7], 'isEdited': data[8], 'isSpam': data[9], 'isDeleted': data[10], } post = Post(params) post.id = data[0] post.likes = data[11] post.dislikes = data[12] post.points = post.likes - post.dislikes post.parent = Converter.from_hex_to_dec(data[13][-10:-5]) if data[13] != Converter.from_dec_to_hex( int(post.id)) else None resultSet.append(post.serialize()) resp = {"code": 0, "response": resultSet} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json")
def listPosts(request): forum = request.GET.get('forum') since = request.GET.get('since') limit = request.GET.get('limit') order = request.GET.get('order') related = request.GET.getlist('related') sql = "SELECT * from Post " if "thread" in related: sql += "join Thread on Post.thread=Thread.id " sql += "where Post.forum='%s' " % forum if since is not None: sql += "and Post.date>='%s' " % since if order is not None: if order == "asc": sql += "order by Post.date ASC " else: sql += "order by Post.date DESC " if limit is not None: sql += "limit %s" % limit result = sql_select(sql) if result == (): resp = {"code": 0, "response": []} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json") resultset = [] if "forum" in related: forum = ForumManager.get(forum) for data in result: params = {'user': data[1], 'thread': data[2], 'forum': data[3], 'date': data[4].strftime("%Y-%m-%d %H:%M:%S"), 'message': data[5], 'isApproved': data[6], 'isHighlighted': data[7], 'isEdited': data[8], 'isSpam': data[9], 'isDeleted': data[10], } post = Post(params) post.id = data[0] post.likes = data[11] post.dislikes = data[12] post.points = post.likes - post.dislikes post.parent = Converter.from_hex_to_dec(data[13][-10:-5]) if data[13] != Converter.from_dec_to_hex( int(post.id)) else None serialized_post = post.serialize() if "thread" in related: params = {'forum': data[17], 'user': data[18], 'title': data[19], 'message': data[20], 'slug': data[21], 'date': data[22].strftime("%Y-%m-%d %H:%M:%S"), 'isClosed': data[23], 'isDeleted': data[24]} thread = Thread(params) thread.id = data[16] thread.likes = data[25] thread.dislikes = data[26] thread.posts = data[27] thread.points = thread.likes - thread.dislikes serialized_post["thread"] = thread.serialize() if "user" in related: user = UserManager.get(post.user) serialized_post["user"] = user.serialize() if "forum" in related: serialized_post["forum"] = forum.serialize() resultset.append(serialized_post) resp = {"code": 0, "response": resultset} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json")
def listPosts(request): thread = request.GET.get('thread') since = request.GET.get('since') limit = request.GET.get('limit') order = request.GET.get('order') if order == None: order = "desc" sort = request.GET.get('sort') if sort == None: sort = 'flat' if sort != None: if sort == "tree": sql = "SELECT * from Post where thread='%s' " % thread if since != None: sql += "and date>'%s' " % since if order == 'asc': sql += "order by path asc" if order == 'desc': sql += "order by left(path,5) desc, path asc" if limit != None: sql += " limit %s" % limit elif sort == "flat": sql = "SELECT * from Post where thread='%s' " % thread if since != None: sql += "and date>'%s' " % since sql += "order by date " + order if limit != None: sql += " limit %s" % limit elif sort == "parent_tree": sql = "SELECT DISTINCT left(path,5) as col from Post where thread='%s' " % thread if since != None: sql += "and date>'%s' " % since if order == 'asc': sql += "order by left(path,5) asc" if limit != None: sql += " limit %s" % limit sql = "SELECT * from POST JOIN ("+ sql + ") as t2 on t2.col=left(Post.path,5) where Post.thread='%s' order by Post.path asc" % thread elif order == 'desc': sql += "order by left(path,5) desc" if limit != None: sql += " limit %s" % limit sql = "SELECT * from POST JOIN ("+ sql + ") as t2 on t2.col=left(Post.path,5) where Post.thread='%s' order by left(Post.path,5) desc, path asc" % thread result = sql_select(sql) resultSet = [] for data in result: params = {'user': data[1], 'thread': data[2], 'forum': data[3], 'date': data[4].strftime("%Y-%m-%d %H:%M:%S"), 'message': data[5], 'isApproved': data[6], 'isHighlighted': data[7], 'isEdited': data[8], 'isSpam': data[9], 'isDeleted': data[10], } post = Post(params) post.id = data[0] post.likes = data[11] post.dislikes = data[12] post.points = post.likes - post.dislikes post.parent = Converter.from_hex_to_dec(data[13][-10:-5]) if data[13] != Converter.from_dec_to_hex( int(post.id)) else None resultSet.append(post.serialize()) resp = {"code": 0, "response": resultSet} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json")