def create_request(): post_body = json.loads(request.data) sender_netid = post_body.get('sender_netid', "") receiver_netid = post_body.get('receiver_netid', "") sender = User.query.filter_by(netid=sender_netid).first() receiver = User.query.filter_by(netid=receiver_netid).first() if not sender: return json.dumps({ 'success': False, 'error': 'Sender not found!' }), 404 elif not receiver: return json.dumps({ 'success': False, 'error': 'Recipient not found!' }), 404 else: for f in sender.met_users: if receiver.netid == f.netid: return json.dumps({ 'success': False, 'error': 'You are already friends with this user!' }), 409 req = Request() req.sender.append(sender) req.receiver.append(receiver) db.session.add(req) db.session.commit() return json.dumps({'success': True, 'data': req.serialize()}), 201
def create_request(kind, sender_id, receiver_id): if kind == "friend": sender = User.query.filter_by(id=sender_id).first() if sender is None: return "The sending user does not exist!", 404 receiver = User.query.filter_by(id=receiver_id).first() if receiver is None: return "The receiving user does not exist!", 404 if sender_id == receiver_id: return "You can’t send a friend request to yourself!", 403 if check_friend_pending(sender_id, receiver_id): return "There is already a pending friend request between these users!", 403 if receiver in sender.friends: return "You are already friends!", 403 elif kind == "battle": sender = Character.query.filter_by(id=sender_id).first() if sender is None: return "The sending character does not exist!", 404 receiver = Character.query.filter_by(id=receiver_id).first() if receiver is None: return "The receiving character does not exist!", 404 if check_battle_pending(sender_id, receiver_id): return "There is already a pending battle request between these characters!", 403 if is_battling(sender_id): return "The sender is already in a battle!", 403 if is_battling(receiver_id): return "The receiver is already in a battle!", 403 if sender.user_id == receiver.user_id: return "The provided characters belong to the same user!", 403 new_request = Request(kind=kind, sender_id=sender_id, receiver_id=receiver_id) db.session.add(new_request) db.session.commit() return new_request.serialize(), 201
def create_queue_request(user_id): post_body = json.loads(request.data) user_id = user_id course_id = post_body.get('course_id') time_posted = str(datetime.utcnow()) request_topic = post_body.get('request_topic') user = User.query.filter_by(id = user_id).first() user_ser = user.get_netid() if not request_topic: return json.dumps({'success': False, 'issue': "There must be a request topic entered"}), 201 #checks to see if this user is already in a queue user_requests = Request.query.filter_by(user_id = user_id).filter_by(course_id = course_id).first() #if the user is already in a queue it does not allow them to make another request if not user_requests is None: return json.dumps({'success': False, 'user': "******"}), 201 #tracking existing requests under the course_id in order to find current queue length existing_requests = Request.query.filter_by(course_id = course_id) if not existing_requests: queue_pos = 1 else: length = 0 for u in existing_requests: length += 1 queue_pos = length + 1 queue_request = Request( user_id = user_id, course_id = course_id, time_posted = time_posted, queue_pos = queue_pos, request_topic = request_topic ) db.session.add(queue_request) db.session.commit() return json.dumps({'success': True, 'user': user_ser, 'data' : queue_request.__repr__()}), 201
def create_request(requesting_id, receiving_id, event_id): session = Session() request = Request() if session.query(func.max(Request.rid)).first()[0] != None: request.rid = session.query(func.max(Request.rid)).first()[0] + 1 else: request.rid = 1 request.requesting_id = requesting_id request.receiving_id = receiving_id request.event_id = event_id request.status = "default" session.add(request) session.commit() session.close()
def from_new( cls, requesting_id, receiving_id, event_id): # you can use this or the one in the functionuser class session = Session() request = Request() rid = next_id("request") request.rid = rid request.requesting_id = requesting_id request.receiving_id = receiving_id request.event_id = event_id request.status = "default" session.add(request) session.commit() session.close() return cls(rid, requesting_id, receiving_id, event_id, "default")
def im(reqs, body_id): session = get_session() for req in reqs: if len( session.query(Request).filter( Request.body_req_id == req['iden']).all()) == 0: r = Request(body=body_id, body_req_id=req['iden'], title=req['title'], type=req['type']) session.add(r) session.commit() doc = Document(request=r.id, url=req['doc']) session.add(doc) session.commit() for tag in req['tags']: t = RequestTag(request=r.id, tag=tag) session.add(t) session.commit()
def create_request(): #result = request.get_json() request_data = json.loads(request.data) validator = Validator(request_data) email = validator.email() if validator.has_errors(): return validator.error_response() requested_date = datetime.strptime(request_data['requested_date'], "%Y-%m-%d") key = db.create_unique_key() req = Request(email, requested_date, key) db.insert_request(config, req) conf_link = "http://127.0.0.1:5000/confirm_request?key={0}&email={1}".format( key, email) subject = 'Please confirm your email' message = 'Please click on {} to confirm your email.'.format(conf_link) #sender.send_email_to_request(email, key, subject, message) return jsonify(success=True)