def friends_display(username, message=None): user = users.query.filter_by(username=username).first() x = [] friend_list = [] url_list = [] x = friends.query.filter_by(username=username).first() friend_list = x.friend.split(',') for y in friend_list: if y != '': z = users.query.filter_by(username=y).first() url_list.append(z) if request.method == 'POST': if 'search' in request.form: return redirect( url_for('app_blueprint.search_results', username=username, query=request.form['search_name'])) if 'logout' in request.form: return redirect(url_for('app_blueprint.sign_up')) if 'log' in request.form: return redirect(url_for('app_blueprint.log', username=username)) if 'friends' in request.form: return redirect( url_for('app_blueprint.friends_display', username=username)) if 'add_transaction' in request.form: if request.form['from_user'] == username: friend_list = [] x = friends.query.filter_by( username=request.form['from_user']).first() friend_list = x.friend.split(',') if request.form['to_user'] not in friend_list: message = request.form['to_user'] + " is not a friend" else: date_created = datetime.now().strftime('%Y-%m-%d %H:%M:%S') transaction = transactions( from_user=request.form['from_user'], to_user=request.form['to_user'], amount=request.form['amount'], settled="0", date_created=date_created) DB.session.add(transaction) DB.session.commit() elif request.form['to_user'] == username: friend_list = [] x = friends.query.filter_by( username=request.form['to_user']).first() friend_list = x.friend.split(',') if request.form['from_user'] not in friend_list: message = request.form['from_user'] + " is not a friend" else: date_created = datetime.now().strftime('%Y-%m-%d %H:%M:%S') transaction = transactions( from_user=request.form['from_user'], to_user=request.form['to_user'], amount=request.form['amount'], settled="0", date_created=date_created) DB.session.add(transaction) DB.session.commit() else: message = "You can only add your own transactions" if 'groups' in request.form: return redirect( url_for('app_blueprint.groups_display', username=username)) if 'group_submission' in request.form: group_name = request.form['group_name'] group_members = request.form['people_in_group'] group = groups(name=group_name, group_members=group_members) DB.session.add(group) DB.session.commit() return redirect( url_for('app_blueprint.group_page', username=username, group_name=group_name)) if "friend_request_accept" in request.form: friend_status = accept_friend_request(username, request) return render_template( 'friends.html', username=username, user=user, friend_list=url_list, message=message, friend_requests_list=friend_request_search(username)) if 'friend_request_delete' in request.form: delete_friend_request(username, request) return render_template( 'friends.html', username=username, user=user, friend_list=url_list, message=message, friend_requests_list=friend_request_search(username))
def search_results(username, query, message=None): url_dict = {} friend_list = [] fr1 = friends.query.filter_by(username=username).first() friend_list = fr1.friend.split(',') results = users.query.filter(users.username.startswith(query)).all() for res in results: if res.username == username: results.remove(res) break for x in results: url_dict[x.username] = x.profile_pic if not results: message = "Oops... No results found" friend_requests_from_username = [] friend_requests_to_username = [] friend_status = {} if request.method == 'POST': if 'search' in request.form: return redirect( url_for('app_blueprint.search_results', username=username, query=request.form['search_name'])) if 'logout' in request.form: return redirect(url_for('app_blueprint.sign_up')) if 'add_friend' in request.form: fr2 = friends.query.filter_by( username=request.form['friend_to_be_added']).first() # a = fr2.friend # z = fr1.friend # fr1.friend = z + request.form['friend_to_be_added'] + ',' # fr2.friend = a + username + ',' friend_list = fr1.friend.split(',') friend_request = friend_requests( from_user=username, to_user=request.form['friend_to_be_added']) DB.session.add(friend_request) DB.session.commit() friend_requests_from_username = friend_requests.query.filter_by( from_user=username).all() friend_requests_to_username = friend_requests.query.filter_by( to_user=username).all() for x in friend_requests_from_username: friend_status[x.to_user] = "Friend Request sent by me" for x in friend_requests_to_username: friend_status[x.from_user] = "Friend Request sent to me" for x in friend_list: friend_status[x] = "Friend" if "friend_request_accept" in request.form: friend_status = accept_friend_request(username, request) return render_template( 'search_results.html', username=username, results=results, message=message, profile_pic_dict=url_dict, friend_status=friend_status, friend_requests_list=friend_request_search(username)) if 'friend_request_delete' in request.form: delete_friend_request(username, request) if 'add_transaction' in request.form: if request.form['from_user'] == username: friend_list = [] x = friends.query.filter_by( username=request.form['from_user']).first() friend_list = x.friend.split(',') if request.form['to_user'] not in friend_list: message = request.form['to_user'] + " is not a friend" else: date_created = datetime.now().strftime('%Y-%m-%d %H:%M:%S') transaction = transactions( from_user=request.form['from_user'], to_user=request.form['to_user'], amount=request.form['amount'], settled=False, date_created=date_created) DB.session.add(transaction) DB.session.commit() elif request.form['to_user'] == username: friend_list = [] x = friends.query.filter_by( username=request.form['to_user']).first() friend_list = x.friend.split(',') if request.form['from_user'] not in friend_list: message = request.form['from_user'] + " is not a friend" else: date_created = datetime.now().strftime('%Y-%m-%d %H:%M:%S') transaction = transactions( from_user=request.form['from_user'], to_user=request.form['to_user'], amount=request.form['amount'], settled=False, date_created=date_created) DB.session.add(transaction) DB.session.commit() else: message = "You can only add your own transactions" if 'log' in request.form: return redirect(url_for('app_blueprint.log', username=username)) if 'friends' in request.form: return redirect( url_for('app_blueprint.friends_display', username=username)) if 'groups' in request.form: return redirect( url_for('app_blueprint.groups_display', username=username)) friend_requests_from_username = friend_requests.query.filter_by( from_user=username).all() friend_requests_to_username = friend_requests.query.filter_by( to_user=username).all() for x in friend_requests_from_username: friend_status[x.to_user] = "Friend Request sent by me" for x in friend_requests_to_username: friend_status[x.from_user] = "Friend Request sent to me" for x in friend_list: friend_status[x] = "Friend" print(friend_status) return render_template( 'search_results.html', username=username, results=results, message=message, profile_pic_dict=url_dict, friend_status=friend_status, friend_requests_list=friend_request_search(username))
def log(username, message=None): user = users.query.filter_by(username=username).first() if request.method == 'POST': if 'search' in request.form: return redirect( url_for('app_blueprint.search_results', username=username, query=request.form['search_name'])) if 'logout' in request.form: return redirect(url_for('app_blueprint.sign_up')) if 'add_transaction' in request.form: if request.form['from_user'] == username: friend_list = [] x = friends.query.filter_by( username=request.form['from_user']).first() friend_list = x.friend.split(',') if request.form['to_user'] not in friend_list: message = request.form['to_user'] + " is not a friend" else: date_created = datetime.now().strftime('%Y-%m-%d %H:%M:%S') transaction = transactions( from_user=request.form['from_user'], to_user=request.form['to_user'], amount=request.form['amount'], settled="0", date_created=date_created) DB.session.add(transaction) DB.session.commit() elif request.form['to_user'] == username: friend_list = [] x = friends.query.filter_by( username=request.form['to_user']).first() friend_list = x.friend.split(',') if request.form['from_user'] not in friend_list: message = request.form['from_user'] + " is not a friend" else: date_created = datetime.now().strftime('%Y-%m-%d %H:%M:%S') transaction = transactions( from_user=request.form['from_user'], to_user=request.form['to_user'], amount=request.form['amount'], settled="0", date_created=date_created) DB.session.add(transaction) DB.session.commit() else: message = "You can only add your own transactions" if 'log' in request.form: return redirect(url_for('app_blueprint.log', username=username)) if 'comment_add' in request.form: x = transactions.query.get(request.form['transaction_id']) x.comments = x.comments + ',' + request.form[ 'submitting_user'] + ' ' + request.form['comment'] DB.session.commit() if 'friends' in request.form: return redirect( url_for('app_blueprint.friends_display', username=username)) if 'groups' in request.form: return redirect( url_for('app_blueprint.groups_display', username=username)) if "friend_request_accept" in request.form: friend_status = accept_friend_request(username, request) to_list = transactions.query.filter_by(from_user=username).all() from_list = transactions.query.filter_by(to_user=username).all() return render_template( 'log.html', username=username, user=user, to_list=to_list, from_list=from_list, message=message, friend_requests_list=friend_request_search(username)) if 'friend_request_delete' in request.form: delete_friend_request(username, request) to_list = transactions.query.filter_by(from_user=username).all() from_list = transactions.query.filter_by(to_user=username).all() return render_template( 'log.html', username=username, user=user, to_list=to_list, from_list=from_list, message=message, friend_requests_list=friend_request_search(username))
# uid=780 # optype="deposit" # amount_involved =300.00 res = None try: if (optype == "deposit"): my_logger.info('inside deposit') accountNumberList = transaction_service.getAccountNoFromId( None, config_meta.Session_userAccountId, optype) if (accountNumberList != None and len(accountNumberList) > 0): payee_account_no = accountNumberList[0] payee_account_bank = "self" my_logger.info("DEPOSIT" + " " + payee_account_no + " " + payee_account_bank) transaction = transactions("DEPOSIT", amount_involved, payee_account_no, payee_account_bank, uid) my_logger.info('---deposit related queries in process id--') res = transaction_service.transaction_init(transaction, optype) elif (optype == "transfer"): transaction = transactions("FUND TRANSFER", amount_involved, payee_account_no, payee_account_bank, uid) my_logger.info('---fund transfer related queries in process id--') res = transaction_service.transaction_init(transaction, optype) else: my_logger.info('---fetch all transacion id--') res = transaction_service.get_all_transaction_service(uid) if ((optype == "deposit") or (optype == "transfer")):