def edit_headquarters_name(): 
	body = {}
	error = False
	error_msgs = []

	head_id = request.get_json()['id']
	name = request.get_json()['name']
	print(name)

	name_split = name.split(' ')
	name = name_split[0].capitalize()
	i = 1
	while i < len(name_split):
		name += ' ' 
		name += name_split[i].capitalize()
		i += 1

	try:
		edit_head = db.session.query(Headquarters).filter(Headquarters.id == head_id).one()
		edit_head.name = name
		db.session.commit()
		body['success'] = True
		body['id'] = edit_head.id
		body['name'] = edit_head.name
	except:
		error = True
		body['success'] = False
		error_msgs.append('There was an error processing the request')
		body['error_msgs'] = error_msgs
		db.session.rollback()
	finally:
		db.session.close()
		print(body)
		return jsonify(body)
def post_headquarters(): 
	body = {}
	error = False
	error_msgs = []

	name = request.get_json()['name']
	print(name)

	name_split = name.split(' ')
	name = name_split[0].capitalize()
	i = 1
	while i < len(name_split):
		name += ' ' 
		name += name_split[i].capitalize()
		i += 1

	try:
		new_head = Headquarters(name=name)
		db.session.add(new_head)
		db.session.commit()
		body['success'] = True
		body['id'] = new_head.id
		body['name'] = new_head.name
	except:
		error = True
		errors['success'] = False
		error_msgs.append('There was an error processing the request')
		errors['error_msgs'] = error_msgs
		db.session.rollback()
	finally:
		db.session.close()
		print(body)
		return jsonify(body)
Beispiel #3
0
def edit_weapon_name():
    body = {}
    error = False
    error_msgs = []

    weapon_id = request.get_json()['id']
    name = request.get_json()['name']
    print(name)

    name_split = name.split(' ')
    name = name_split[0].capitalize()
    i = 1
    while i < len(name_split):
        name += ' '
        name += name_split[i].capitalize()
        i += 1

    weapon = db.session.query(Weapon).filter(Weapon.name == name).first()

    if weapon is not None:
        error = True
        body['success'] = False
        error_msgs.append('There is already a weapon with that name')
        body['error'] = error_msgs

    if error:
        return jsonify(body)
    try:
        edit_weapon = db.session.query(Weapon).filter(
            Weapon.id == weapon_id).one()
        edit_weapon.name = name
        db.session.commit()
        body['success'] = True
        body['id'] = edit_weapon.id
        body['name'] = edit_weapon.name
    except:
        error = True
        body['success'] = False
        error_msgs.append('There was an error processing the request')
        body['error'] = error_msgs
        db.session.rollback()
    finally:
        db.session.close()
        print(body)
        return jsonify(body)
Beispiel #4
0
def post_vehicle(): 
	body = {}
	error = False
	error_msgs = []

	name = request.get_json()['name']
	print(name)

	name_split = name.split(' ')
	name = name_split[0].capitalize()
	i = 1
	while i < len(name_split):
		name += ' ' 
		name += name_split[i].capitalize()
		i += 1

	vehicle = db.session.query(Vehicle).filter(Vehicle.name == name).first()

	if vehicle is not None:
		error = True
		body['success'] = False
		message = 'There is already a vehicle with that name'
		error_msgs.append(message)
		body['error_msgs'] = error_msgs

	if error:
		return jsonify(body)
	try:
		new_vehicle = Vehicle(name=name)
		db.session.add(new_vehicle)
		db.session.commit()
		body['success'] = True
		body['id'] = new_vehicle.id
		body['name'] = new_vehicle.name
	except:
		error = True
		errors['success'] = False
		error_msgs.append('There was an error processing the request')
		errors['error_msgs'] = error_msgs
		db.session.rollback()
	finally:
		db.session.close()
		print(body)
		return jsonify(body)