def get_account_info(): context = {} user = load_user(current_user.get_id()) context['friends'] = [x.id for x in user.friends] print(context) return jsonify(**context)
def get_timeline(): if not current_user.is_authenticated: return redirect(url_for('login')) user = load_user(current_user.get_id()) posts_access = user.access_posts posts = user.own_posts print(user.timeline_posts()) return jsonify(**{'entry_ids': user.timeline_posts()})
def get_friend(friend_id): # user = User.get(friend_id) print("Getting friend_id", friend_id) friend_list = load_user(current_user.get_id()).friends for friend in friend_list: if friend.id == friend_id: return jsonify(**{'friend_username': friend.username}) return jsonify(**{}), 404
def delete_comment(): save_data = json.loads(request.data.decode('utf8')) comment = Comment.query.get(save_data['comment_id']) if comment.user_id != load_user(current_user.get_id()).id: return jsonify(**{'successful_delete': False}) comment.delete_file() db.session.delete(comment) db.session.flush() db.session.commit() return jsonify(**{"successful_delete": True})
def get_comment(comment_id): context = {} comment = Comment.query.get(comment_id) if comment.has_file(): commenter = User.query.get(comment.user_id) context['editor_state'] = getFile(comment.get_full_filename()) context['user_id'] = commenter.username # if commenter.id == load_user(current_user.get_id()).id: context['owner'] = True if commenter.id == load_user( current_user.get_id()).id else False print(context) # return jsonify(**{'editor_state': getFile(comment.get_full_filename()), # 'user_id': commenter.username}) return jsonify(**context)
def share_journal_entry(): share_data = json.loads(request.data.decode('utf8')) user = load_user(current_user.get_id()) friend = User.query.filter_by(username=share_data['sharingName']).first() post = Post.query.get(share_data['post_id']) if friend in user.friends: print("is friend") friend.access_posts.append(post) db.session.add(friend) db.session.commit() context = {"successful_add": True} return jsonify(**context) else: return jsonify(**{}), 404
def delete_friend(): print("deleting friend") user = load_user(current_user.get_id()) data = json.loads(request.data.decode('utf8')) print(data) # friend = User.query.filter_by(username=data['friend_use']).first() friendship = Friendship.query.filter_by(friend_a_id=user.id, friend_b_id=data['friend_id']).first() # friendship = Friendship(friend_a_id=user.id, friend_b_id=data['friend_id']) print(friendship) db.session.delete(friendship) db.session.flush() db.session.commit() context = {"successful_delete": True} return jsonify(**context)
def delete_journal_entry(entry_id): print("deleting journal entry {}\n".format(entry_id)) post = Post.query.get(entry_id) user = load_user(current_user.get_id()) if post.user_id != user.id: # make sure only post owner is editting it print("post id", post.id) print("post user id", post.user_id, type(post.user_id)) print("current user id", current_user.get_id(), type(current_user.get_id())) return jsonify(**{'successful_delete': False}) post.delete_file() db.session.delete(post) db.session.flush() db.session.commit() context = {"successful_delete": True} return jsonify(**context)
def delete_entry_access_share(): share_data = json.loads(request.data.decode('utf8')) print(share_data) user = load_user(current_user.get_id()) post = Post.query.get(share_data['post_id']) if post.user_id == user.id: friend = User.query.filter_by( username=share_data['sharingName']).first() if friend in user.friends: if friend in post.accessors: post.accessors.remove(friend) db.session.add(post) db.session.commit() return jsonify(**{"successful_share_delete": True}) return jsonify(**{"successful_share_delete": False})
def new_friend(): print("\n\nAdding new friend") data = json.loads(request.data.decode('utf8')) print(data) user = load_user(current_user.get_id()) friend = User.query.filter_by(username=data['friend_username']).first() # if 'friend_username' in data else load_user(data['friend_id']) print(user) print(friend) if friend: # user = User(username=form.username.data) friends = Friendship(friend_a_id=user.id, friend_b_id=friend.id) # friends = Friendship(friend_a_id=user.id, friend_b_id=data['friend_id']) print(friends) db.session.add(friends) db.session.flush() db.session.commit() return jsonify(**{'added_friend': friend.id}) else: return jsonify(**{}), 404
def save_journal_entry(): save_data = json.loads(request.data.decode('utf8')) print('\n') print(save_data, end=debug_space) user = load_user(current_user.get_id()) p = Post(user_id=user.id) if save_data['new_entry'] else Post.query.get( save_data['entry_id']) if p.user_id != user.id: # make sure only post owner is editting it return jsonify(**{'successful_save': False}) p.title = save_data['title'] p.save_post(save_data['editor_state']) db.session.add(p) db.session.commit() context = {} context['successful_save'] = True context['entry_id'] = p.id print(context) return jsonify(**context)