def Decode():
    content = request.json
    user_id = decode_auth_token(content['token'])
    duser = getUserById(user_id)
    user = DObject()
    user.id = duser.id
    user.first_name = duser.first_name
    user.last_name = duser.last_name
    user.community_id = duser.community_id
    user.image = "https://d19rpgkrjeba2z.cloudfront.net/e82de29ec673c6fa/static/nextdoorv2/images/avatars/avatar-" + duser.first_name[
        0].lower() + ".png"
    return json.dumps({
        "userId": decode_auth_token(content['token']),
        'user': user.__dict__
    })
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 PostIntraPost():
    content = request.json

    IntraPostObj = DObject()
    IntraPostObj.title = content["title"]
    IntraPostObj.category = content['category']
    IntraPostObj.content = content["content"]
    IntraPostObj.timestamp = datetime.datetime.now()
    IntraPostObj.user_id = decode_auth_token(content['token'])
    IntraPostObj.community_id = content["communityId"]
    IntraPostObj.image_ids = content['image_ids']
    #IntraPostObj.post_type = content["postType"]

    InsertIntraPost(IntraPostObj)
    return json.dumps({"success": True})
def PostInterPost():
    content = request.json
    for c_id in content["communityIds"].split(','):
        InterPostObj = DObject()
        InterPostObj.title = content["title"]
        InterPostObj.content = content["content"]
        InterPostObj.category = content['category']
        InterPostObj.timestamp = datetime.datetime.now()
        InterPostObj.image_ids = content['image_ids']
        InterPostObj.user_id = decode_auth_token(content['token'])
        InterPostObj.community_id = c_id
        #InterPostObj.post_type = content["postType"]
        InterPostObj.admin_approved = False
        InterPostObj.image_ids = content['image_ids']
        InsertInterPost(InterPostObj)
    return json.dumps({"success": True})
def deleteComment():
    content = request.json
    if DeleteComment(content['id'], decode_auth_token(content['token'])):
        return json.dumps({"success": True})
    else:
        return json.dumps({"success": False})