示例#1
0
def save_vehicle(): 
	body = {}
	body['success'] = True
	error = False
	error_msgs = []

	data = request.get_json()
	
	errors = veh_save_errors(data)

	error = errors['error']
	if error:
		body['success'] = False
		body['error_msgs'] = errors['error_msgs']
		return jsonify(body)

	vehicle_id = request.get_json()['vehicle_id']
	description = request.get_json()['description']
	type_id = request.get_json()['type_id']
	size = request.get_json()['size']
	strength = request.get_json()['strength']
	speed = request.get_json()['speed']
	toughness = request.get_json()['toughness']
	defense = request.get_json()['defense']
	cost = request.get_json()['cost']
	feature = request.get_json()['feature']
	power = request.get_json()['power']

	vehicle_id = db_integer(vehicle_id)
	type_id = integer(type_id)
	size = integer(size)
	strength = integer(strength)
	speed = integer(speed)
	toughness = integer(toughness)
	defense = integer(defense)
	cost = integer(cost)

	entry = db.session.query(Vehicle).filter(Vehicle.id == vehicle_id).one()

	entry.description = description
	entry.type_id = type_id
	entry.size = size
	entry.strength = strength
	entry.speed = speed
	entry.toughness = toughness
	entry.defense = defense
	entry.cost = cost
	entry.feature = feature
	entry.power = power

	db.session.commit()

	body['success'] = True
			
	db.session.close()
	print(body)
	return jsonify(body)
示例#2
0
def armor_post_defensev():

    body = {}
    body['success'] = True
    errors = {'error': False, 'error_msgs': []}
    data = request.get_json()

    errors = arm_defense_post_errors(data)

    error = errors['error']
    if error:
        body['success'] = False
        body['error_msgs'] = errors['error_msgs']
        return jsonify(body)

    armor_id = request.get_json()['armor_id']
    columns = request.get_json()['columns']
    created = request.get_json()['created']
    font = request.get_json()['font']
    defense = request.get_json()['defense']
    bonus = request.get_json()['bonus']

    armor_id = integer(aemor_id)
    defense = db_integer(Defense, defense)
    bonus = integer(bonus)

    entry = ArmDefense(armor_id=armor_id, defense=defense, bonus=bonus)

    db.session.add(entry)
    db.session.commit()

    body = {}
    body['id'] = entry.id
    error = False
    error_msg = []
    body['success'] = True

    rows = columns
    mods = []
    cells = []
    table_id = 'defense'
    spot = table_id + '-spot'

    body['table_id'] = table_id
    body['spot'] = spot
    body['created'] = created
    body['title'] = ''
    body['rows'] = rows
    body['mods'] = []
    body['font'] = font

    body = arm_defense_post(entry, body, cells)

    db.session.close()

    return jsonify(body)
示例#3
0
def weapon_post_benefit():

    body = {}
    body['success'] = True
    errors = {'error': False, 'error_msgs': []}
    data = request.get_json()

    errors = weap_benefit_post_errors(data)

    error = errors['error']
    if error:
        body['success'] = False
        body['error_msgs'] = errors['error_msgs']
        return jsonify(body)

    weapon_id = request.get_json()['weapon_id']
    columns = request.get_json()['columns']
    created = request.get_json()['created']
    font = request.get_json()['font']
    benefit = request.get_json()['benefit']

    weapon_id = integer(weapon_id)
    benefit = db_integer(Benefit, benefit)

    entry = WeapBenefit(weapon_id=weapon_id, benefit=benefit)

    db.session.add(entry)
    db.session.commit()

    body = {}
    body['id'] = entry.id
    error = False
    error_msg = []
    body['success'] = True

    rows = columns
    mods = []
    cells = []
    table_id = 'benefit'
    spot = table_id + '-spot'

    body['table_id'] = table_id
    body['spot'] = spot
    body['created'] = created
    body['title'] = ''
    body['rows'] = rows
    body['mods'] = []
    body['font'] = font

    body = weap_benefit_post(entry, body, cells)

    db.session.close()

    return jsonify(body)
def head_post_():

	body = {}
	body['success'] = True
	errors = {'error': False, 'error_msgs': []}
	data = request.get_json()

	errors = head__post_errors(data)

	error = errors['error']
	if error:
		body['success'] = False
		body['error_msgs'] = errors['error_msgs']
		return jsonify(body)

	head_id = request.get_json()['head_id']
	columns = request.get_json()['columns']
	created = request.get_json()['created']
	font = request.get_json()['font']

	head_id = db_integer(head_id)

	entry = Headquarters(head_id = head_id)

	db.session.add(entry)
	db.session.commit()

	body = {}
	body['id'] = entry.id
	error = False
	error_msg = []
	body['success'] = True

	rows = columns	
	mods = []
	cells = []
	table_id = ''
	spot = table_id + '-spot'

	body['table_id'] = table_id
	body['spot'] = spot
	body['created'] = created
	body['title'] = ''
	body['rows'] = rows
	body['mods'] = []
	body['font'] = font
	
	body = head__post(entry, body, cells)

	db.session.close()

	return jsonify(body)
def primary_exist(check_type,
                  check_table,
                  opposed_table,
                  column,
                  id,
                  power=False):
    error_msgs = errors['error_msgs']
    error = False

    check_convert = db_integer(Check, check_type)
    check_title = get_name(Check, check_convert)

    if check_type == 'x':
        attribute = getattr(check_table, column)
        the_filter = attribute == id
        if power == False:
            check = db.session.query(check_table).filter(
                the_filter, check_table.primary == True).first()
        else:
            check = db.session.query(check_table).filter(
                the_filter, check_table.primary == True,
                check_table.extra_id == None).first()
        if check is None:
            error = True
            message = 'You set this base powers check to Variable Check but you never set a primary check for the base power with the Variable Check Form.  Either create a primary check for the base power with the variable check form or make a different selection on the base powers Check Type field.'
            error_msgs.append(message)
    if check_type == '2' or check_type == '7':
        attribute = getattr(check_table, column)
        the_filter = attribute == id
        if power == False:
            check = db.session.query(opposed_table).filter(
                the_filter, opposed_table.primary == True).first()
        else:
            check = db.session.query(opposed_table).filter(
                the_filter, opposed_table.primary == True,
                opposed_table.extra_id == None).first()
        if check is None:
            error = True
            message = 'You set this base powers check to ' + check_title + ' Check but you never set a primary check for the base power with the Opponent Check Form.  Either create a primary check for the base power with the Opponent check form or make a different selection on the base powers Check Type field.'
            error_msgs.append(message)

    errors['error_msgs'] = error_msgs
    if error:
        errors['error'] = error

    return (errors)
def head_post_adddon():

	body = {}
	body['success'] = True
	errors = {'error': False, 'error_msgs': []}
	data = request.get_json()

	errors = head_addon_post_errors(data)

	error = errors['error']
	if error:
		body['success'] = False
		body['error_msgs'] = errors['error_msgs']
		return jsonify(body)

	head_id = request.get_json()['head_id']
	columns = request.get_json()['columns']
	created = request.get_json()['created']
	font = request.get_json()['font']
	feature = request.get_json()['feature']
	equipment = request.get_json()['equipment']
	weapon = request.get_json()['weapon']
	addon = request.get_json()['addon']
	head_feature = request.get_json()['head_feature']
	
	head_id = db_integer(head_id)
	feature = db_integer(feature)
	equipment = db_integer(equipment)
	weapon = db_integer(weapon)
	head_feature = db_integer(head_feature)

	entry = HeadFeatAddon(head_id = head_id,
					feature = feature,
					equipment = equipment,
					weapon = weapon,
					addon = addon,
					head_feature = head_feature)

	db.session.add(entry)
	db.session.commit()


	body = {}
	body['id'] = entry.id
	error = False
	error_msg = []
	body['success'] = True

	rows = columns	
	mods = []
	cells = []
	table_id = 'addon'
	spot = table_id + '-spot'

	body['table_id'] = table_id
	body['spot'] = spot
	body['created'] = created
	body['title'] = ''
	body['rows'] = rows
	body['mods'] = []
	body['font'] = font
	
	body = head_addon_post(entry, body, cells)

	db.session.close()

	return jsonify(body)
def head_post_feature():

	body = {}
	body['success'] = True
	errors = {'error': False, 'error_msgs': []}
	data = request.get_json()

	errors = head_feature_post_errors(data)

	error = errors['error']
	if error:
		body['success'] = False
		body['error_msgs'] = errors['error_msgs']
		return jsonify(body)

	head_id = request.get_json()['head_id']
	columns = request.get_json()['columns']
	created = request.get_json()['created']
	font = request.get_json()['font']
	name = request.get_json()['name']
	description = request.get_json()['description']
	feature = request.get_json()['feature']

	head_id = db_integer(head_id)
	feature = db_integer(feature)

	if name != '':
		entry = HeadFeature(name = name,
							description = description)

		db.session.add(entry)
		db.session.commit()

		feature = entry.id

		db.session.close()

	entry = HeadCharFeat(head_id = head_id,
						feature = feature)

	db.session.add(entry)
	db.session.commit()

	total_cost = db.session.query(HeadCharFeat).filter(HeadCharFeat.head_id == head_id).count()

	print('\n\n\n')
	print(total_cost)
	print('\n\n')

	body = {}
	body['id'] = entry.id
	body['select_id'] = feature
	body['cost'] = total_cost
	error = False
	error_msg = []
	body['success'] = True

	rows = columns	
	mods = []
	cells = []
	table_id = 'feature'
	spot = table_id + '-spot'

	body['table_id'] = table_id
	body['spot'] = spot
	body['created'] = created
	body['title'] = ''
	body['rows'] = rows
	body['mods'] = []
	body['font'] = font
	
	body = head_feature_post(entry, body, cells)

	db.session.close()

	return jsonify(body)
示例#8
0
def weapon_post_condition():

    body = {}
    body['success'] = True
    errors = {'error': False, 'error_msgs': []}
    data = request.get_json()

    errors = weap_condition_post_errors(data)

    error = errors['error']
    if error:
        body['success'] = False
        body['error_msgs'] = errors['error_msgs']
        return jsonify(body)

    weapon_id = request.get_json()['weapon_id']
    columns = request.get_json()['columns']
    created = request.get_json()['created']
    font = request.get_json()['font']
    condition_type = request.get_json()['condition_type']
    condition = request.get_json()['condition']
    condition_null = request.get_json()['condition_null']
    condition1 = request.get_json()['condition1']
    condition2 = request.get_json()['condition2']
    damage_value = request.get_json()['damage_value']
    damage = request.get_json()['damage']

    try:
        weapon_id = integer(weapon_id)
        condition = db_integer(Condition, condition)
        condition_null = db_integer(Condition, condition_null)
        condition1 = db_integer(Condition, condition1)
        condition2 = db_integer(Condition, condition2)

        damage_value = integer(damage_value)
        damage = integer(damage)

        entry = WeapCondition(weapon_id=weapon_id,
                              condition_type=condition_type,
                              condition=condition,
                              condition_null=condition_null,
                              condition1=condition1,
                              condition2=condition2,
                              damage_value=damage_value,
                              damage=damage)

        db.session.add(entry)
        db.session.commit()

        body = {}
        body['id'] = entry.id
        error = False
        error_msg = []
        body['success'] = True

        rows = columns
        mods = []
        cells = []
        table_id = 'condition'
        spot = table_id + '-spot'

        body['table_id'] = table_id
        body['spot'] = spot
        body['created'] = created
        body['title'] = ''
        body['rows'] = rows
        body['mods'] = []
        body['font'] = font

        body = weap_condition_post(entry, body, cells)
    except:
        error = True
        body['success'] = False
        body['error'] = 'There was an error processing the request'
        db.session.rollback()

    finally:
        db.session.close()

    return jsonify(body)
示例#9
0
def save_weapon():
    body = {}
    body['success'] = True
    error = False
    error_msgs = []

    data = request.get_json()

    errors = weap_save_errors(data)

    error = errors['error']
    if error:
        body['success'] = False
        body['error_msgs'] = errors['error_msgs']
        return jsonify(body)

    weapon_id = request.get_json()['weapon_id']
    cat_id = request.get_json()['cat_id']
    type_id = request.get_json()['type_id']
    cost = request.get_json()['cost']
    description = request.get_json()['description']
    critical = request.get_json()['critical']
    damage = request.get_json()['damage']
    toughness = request.get_json()['toughness']
    material = request.get_json()['material']
    length = request.get_json()['length']
    length_units = request.get_json()['length_units']
    resist_dc = request.get_json()['resist_dc']
    resistance = request.get_json()['resistance']
    power_rank = request.get_json()['power_rank']
    power = request.get_json()['power']
    hands = request.get_json()['hands']
    strength = request.get_json()['strength']
    thrown = request.get_json()['thrown']
    unarmed = request.get_json()['unarmed']
    reach = request.get_json()['reach']
    ranged_attack_bonus = request.get_json()['ranged_attack_bonus']
    protect = request.get_json()['protect']
    ranged_area = request.get_json()['ranged_area']
    ranged_burst = request.get_json()['ranged_burst']
    ranged_area_damage = request.get_json()['ranged_area_damage']
    penetrate = request.get_json()['penetrate']
    attack_bonus = request.get_json()['attack_bonus']
    subtle = request.get_json()['subtle']
    perception_dc = request.get_json()['perception_dc']
    advantage = request.get_json()['advantage']
    grenade_area = request.get_json()['grenade_area']
    grenade_burst = request.get_json()['grenade_burst']
    grenade_area_damage = request.get_json()['grenade_area_damage']
    conceal = request.get_json()['conceal']
    sense = request.get_json()['sense']
    double = request.get_json()['double']
    double_mod = request.get_json()['double_mod']
    benefit = request.get_json()['benefit']
    condition = request.get_json()['condition']
    descriptor = request.get_json()['descriptor']

    weapon_id = integer(weapon_id)

    cat_id = db_integer(WeaponCat, cat_id)
    type_id = db_integer(WeaponType, type_id)
    material = db_integer(Material, material)
    length_units = db_integer(Unit, length_units)
    resistance = db_integer(Defense, resistance)
    power = db_integer(Power, power)
    advantage = db_integer(Advantage, advantage)
    conceal = db_integer(Conceal, conceal)
    sense = db_integer(Sense, sense)

    cost = integer(cost)
    critical = integer(critical)
    damage = integer(damage)
    toughness = integer(toughness)
    length = integer(length)
    resist_dc = integer(resist_dc)
    power_rank = integer(power_rank)
    hands = integer(hands)
    reach = integer(reach)
    ranged_attack_bonus = integer(ranged_attack_bonus)
    protect = integer(protect)
    ranged_burst = integer(ranged_burst)
    ranged_area_damage = integer(ranged_area_damage)
    attack_bonus = integer(attack_bonus)
    perception_dc = integer(perception_dc)
    grenade_burst = integer(grenade_burst)
    grenade_area_damage = integer(grenade_area_damage)
    double_mod = integer(double_mod)

    entry = db.session.query(Weapon).filter(Weapon.id == weapon_id).one()

    entry.cat_id = cat_id
    entry.type_id = type_id
    entry.cost = cost
    entry.description = description
    entry.critical = critical
    entry.damage = damage
    entry.toughness = toughness
    entry.material = material
    entry.length = length
    entry.length_units = length_units
    entry.resist_dc = resist_dc
    entry.resistance = resistance
    entry.power_rank = power_rank
    entry.power = power
    entry.hands = hands
    entry.strength = strength
    entry.thrown = thrown
    entry.unarmed = unarmed
    entry.reach = reach
    entry.ranged_attack_bonus = ranged_attack_bonus
    entry.protect = protect
    entry.ranged_area = ranged_area
    entry.ranged_burst = ranged_burst
    entry.ranged_area_damage = ranged_area_damage
    entry.penetrate = penetrate
    entry.attack_bonus = attack_bonus
    entry.subtle = subtle
    entry.perception_dc = perception_dc
    entry.advantage = advantage
    entry.grenade_area = grenade_area
    entry.grenade_burst = grenade_burst
    entry.grenade_area_damage = grenade_area_damage
    entry.conceal = conceal
    entry.sense = sense
    entry.double = double
    entry.double_mod = double_mod
    entry.benefit = benefit
    entry.condition = condition
    entry.descriptor = descriptor

    db.session.commit()

    body['success'] = True

    db.session.close()
    print(body)
    return jsonify(body)
示例#10
0
def vehicle_post_feature():

	body = {}
	body['success'] = True
	errors = {'error': False, 'error_msgs': []}
	data = request.get_json()

	errors = veh_feature_post_errors(data)

	error = errors['error']
	if error:
		body['success'] = False
		body['error_msgs'] = errors['error_msgs']
		return jsonify(body)

	vehicle_id = request.get_json()['vehicle_id']
	columns = request.get_json()['columns']
	created = request.get_json()['created']
	font = request.get_json()['font']
	feature = request.get_json()['feature']
	cost = request.get_json()['cost']
	equipment = request.get_json()['equipment']
	weapon = request.get_json()['weapon']
	addon = request.get_json()['addon']
	
	vehicle_id = db_integer(vehicle_id)
	feature = db_integer(feature)
	equipment = db_integer(equipment)
	weapon = db_integer(weapon)
	cost = integer(cost)

	entry = VehFeature(vehicle_id = vehicle_id,
					feature = feature,
					cost = cost,
					equipment = equipment,
					weapon = weapon,
					addon = addon)

	db.session.add(entry)
	db.session.commit()

	items = db.session.query(VehFeature).filter(VehFeature.vehicle_id == vehicle_id).all()

	total_cost = 0

	for i in items:
		total_cost += i.cost

	body = {}
	body['id'] = entry.id
	body['cost'] = total_cost
	error = False
	error_msg = []
	body['success'] = True

	rows = columns	
	mods = []
	cells = []
	table_id = 'feature'
	spot = table_id + '-spot'

	body['table_id'] = table_id
	body['spot'] = spot
	body['created'] = created
	body['title'] = ''
	body['rows'] = rows
	body['mods'] = []
	body['font'] = font
	
	body = veh_feature_post(entry, body, cells)

	db.session.close()

	return jsonify(body)
示例#11
0
def vehicle_post_powers():

	body = {}
	body['success'] = True
	errors = {'error': False, 'error_msgs': []}
	data = request.get_json()
	print(data)

	errors = veh_powers_post_errors(data)

	error = errors['error']
	if error:
		body['success'] = False
		body['error_msgs'] = errors['error_msgs']
		return jsonify(body)

	vehicle_id = request.get_json()['vehicle_id']
	columns = request.get_json()['columns']
	created = request.get_json()['created']
	font = request.get_json()['font']
	cost = request.get_json()['cost']
	ranks  = request.get_json()['ranks']
	power = request.get_json()['power']

	vehicle_id = db_integer(vehicle_id)
	cost = integer(cost)
	ranks = integer(ranks)
	power = integer(power)

	entry = VehPower(vehicle_id = vehicle_id,
					cost = cost,
					ranks = ranks,
					power = power)

	db.session.add(entry)
	db.session.commit()

	total_cost = 0
	total_rank = 0

	powers = db.session.query(VehPower).filter(VehPower.vehicle_id == vehicle_id).first()
	if powers is not None:
		powers = db.session.query(VehPower).filter(VehPower.vehicle_id == vehicle_id).all()
		for p in powers:
			total_cost += p.cost
			total_rank += p.ranks

	body = {}
	body['id'] = entry.id
	body['cost'] = total_cost
	body['rank'] = total_rank
	error = False
	error_msg = []
	body['success'] = True

	rows = columns	
	mods = []
	cells = []
	table_id = 'powers'
	spot = table_id + '-spot'

	body['table_id'] = table_id
	body['spot'] = spot
	body['created'] = created
	body['title'] = ''
	body['rows'] = rows
	body['mods'] = []
	body['font'] = font
	
	body = veh_powers_post(entry, body, cells)

	db.session.close()

	return jsonify(body)