def GetIntraPostUserId(): user_id = request.args.get('user_id') data = GetIntraPostsByUserId(user_id) ret_data = [] if data is None: return json.dumps([]) user = getUserById(user_id) for p in data: print p obj = DObject() obj.user_id = user.id obj.post_id = p[0].id obj.first_name = user.first_name obj.last_name = user.last_name obj.community_name = p[1].name obj.title = p[0].title obj.message = p[0].content obj.category = p[0].category obj.timestamp = str(p[0].timestamp) if p[0].file_id: k = get_file_obj(p[0].file_id).key if k is None: obj.file_id = None else: file_id = (k).split(",")[0] obj.file_id = "https://s3.amazonaws.com/s3-cmpe-281/" + file_id else: obj.file_id = None obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + user.first_name[ 0].lower() + ".png" ret_data.append(obj.__dict__) return json.dumps(ret_data)
def PostComment(): content = request.json print content CommentObj = DObject() CommentObj.content = content["content"] CommentObj.user_id = decode_auth_token(content['token']) CommentObj.post_id = content["postId"] res, id = InsertComment(CommentObj) print res if res: return json.dumps({"success": True, "id": id}) else: return json.dumps({"success": False, "id": 0})
def GetComment(): post_id = request.args.get('post_id') data = GetCommentsByPostId(post_id) if not data: return json.dumps([]) else: ret_comments = [] for d in data: comment = d[0] user = d[1] dcomment = DObject() dcomment.id = comment.id dcomment.content = comment.content dcomment.user_id = comment.user_id dcomment.post_id = comment.post_id dcomment.first_name = user.first_name dcomment.last_name = user.last_name ret_comments.append(dcomment.__dict__) return json.dumps(ret_comments)
def getInterPost(): community_id = request.args.get('community_id') offset = request.args.get('offset') limit = request.args.get('limit') filter_category = request.args.get('category') if filter_category: posts = GetIntraPostsByCommunityId(community_id, limit, offset, filter_category) else: posts = GetIntraPostsByCommunityId(community_id, limit, offset) post_obj = [] for p in posts: print p obj = DObject() obj.user_id = p[0].id obj.post_id = p[1].id obj.first_name = p[0].first_name obj.last_name = p[0].last_name obj.community_name = p[2].name obj.title = p[1].title obj.message = p[1].content obj.category = p[1].category obj.timestamp = str(p[1].timestamp) if p[1].file_id: k = get_file_obj(p[1].file_id).key if k is None: obj.file_id = None else: file_id = (k).split(",")[0] obj.file_id = "https://s3.amazonaws.com/s3-cmpe-281/" + file_id else: obj.file_id = None obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + p[ 0].first_name[0].lower() + ".png" post_obj.append(obj.__dict__) if filter_category: posts = GetInterPostsByCommunityId(community_id, filter_category, limit, offset) else: posts = GetInterPostsByCommunityId(community_id, None, limit, offset) for p in posts: print p obj = DObject() obj.user_id = p[0].id obj.post_id = p[1].id obj.first_name = p[0].first_name obj.last_name = p[0].last_name obj.community_name = (GetCommunity(p[0].community_id)).name obj.title = p[1].title obj.message = p[1].content obj.category = p[1].category obj.timestamp = str(p[1].timestamp) if p[1].file_id: k = get_file_obj(p[1].file_id).key if k is None: obj.file_id = None else: file_id = (k).split(",")[0] obj.file_id = "https://s3.amazonaws.com/s3-cmpe-281/" + file_id else: obj.file_id = None obj.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + p[ 0].first_name[0].lower() + ".png" post_obj.append(obj.__dict__) return json.dumps(post_obj)