예제 #1
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)
예제 #2
0
def save_headquarters(): 
	body = {}
	body['success'] = True
	error = False
	error_msgs = []

	data = request.get_json()
	
	errors = head_save_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']
	description = request.get_json()['description']
	size = request.get_json()['size']
	toughness = request.get_json()['toughness']
	cost = request.get_json()['cost']
	shared = request.get_json()['shared']
	addon = request.get_json()['addon']
	feature = request.get_json()['feature']

	head_id = integer(head_id)
	size =  integer(size)
	toughness = integer(toughness)
	cost = integer(cost)

	entry = db.session.query(Headquarters).filter(Headquarters.id == head_id).one()

	entry.description = description
	entry.size = size
	entry.toughness = toughness
	entry.cost = cost
	entry.shared = shared
	entry.addon = addon
	entry.feature = feature


	db.session.commit()

	body['success'] = True
			
	db.session.close()
	print(body)
	return jsonify(body)
예제 #3
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)
예제 #4
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)
예제 #5
0
def variable_required_rules(value,
                            field,
                            rulename,
                            required,
                            table_name,
                            table,
                            column,
                            id,
                            errors,
                            second_column=False,
                            second_value=False,
                            any=False,
                            int_convert=False):
    error_msgs = errors['error_msgs']
    error = False

    if value != field:
        return (errors)

    try:
        id = int(id)
        attribute = getattr(table, column)
        the_filter = attribute == id
        if second_column == False:
            check = db.session.query(table).filter(the_filter).first()
        else:
            if any != False:
                second_attribute = getattr(table, second_column)
                second_filter = second_attribute != second_value
            else:
                second_attribute = getattr(table, second_column)
                if int_convert:
                    second_value = integer(second_value)
                second_filter = second_attribute == second_value
            check = db.session.query(table).filter(the_filter,
                                                   second_filter).first()
        if check is None:
            error = True
            message = 'If this rule involves ' + rulename + ' you must fill out the ' + required + ' on the ' + table_name + " form first."
            error_msgs.append(message)
    except:
        error = True
        message = 'There was an error proceessing this request.'
        error_msgs.append(message)

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

    return (errors)
예제 #6
0
def save_armor():
    body = {}
    body['success'] = True
    error = False
    error_msgs = []

    data = request.get_json()

    errors = arm_save_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']
    description = request.get_json()['description']
    type_id = request.get_json()['type_id']
    cost = request.get_json()['cost']
    material = request.get_json()['material']
    toughness = request.get_json()['toughness']
    active = request.get_json()['active']
    subtle = request.get_json()['subtle']
    perception = request.get_json()['perception']
    impervious = request.get_json()['impervious']
    defense = request.get_json()['defense']
    descriptor = request.get_json()['descriptor']

    type_id = integer(type_id)
    cost = integer(cost)
    material = integer(material)
    toughness = integer(toughness)
    active = integer(active)
    perception = integer(perception)

    entry = db.session.query(Armor).filter(Armor.id == armor_id).one()

    entry.description = description
    entry.type_id = type_id
    entry.cost = cost
    entry.material = material
    entry.toughness = toughness
    entry.active = active
    entry.subtle = subtle
    entry.perception = perception
    entry.impervious = impervious
    entry.defense = defense
    entry.descriptor = descriptor

    db.session.commit()

    body['success'] = True

    db.session.close()
    print(body)
    return jsonify(body)
예제 #7
0
def required_link_field(table,
                        column,
                        id,
                        field,
                        table_name,
                        trait,
                        fieldname,
                        errors,
                        second_column=False,
                        second_value=False,
                        int_convert=False):

    error_msgs = errors['error_msgs']
    error = False

    try:
        id = int(id)
        attribute = getattr(table, column)
        the_filter = attribute == id
        if second_column == False:
            check = db.session.query(table).filter(the_filter).first()
        else:
            second_attribute = getattr(table, second_column)
            if int_convert:
                second_value = integer(second_value)
            second_filter = second_attribute == second_value
            check = db.session.query(table).filter(the_filter,
                                                   second_filter).first()
        if check is None:
            return (errors)

        if field == '':
            error = True
            message = 'You have created a ' + table_name + ' for this ' + trait + ' so you must set the ' + fieldname + " before you can save this " + trait + '.'
            error_msgs.append(message)
    except:
        error = True
        message = 'There was an error proceessing this request.'
        error_msgs.append(message)

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

    return (errors)
예제 #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 required_subrule(value,
                     field,
                     values,
                     table,
                     column,
                     name,
                     required,
                     trait_name,
                     trait_id,
                     trait_column,
                     errors,
                     multiple=False,
                     second_column=False,
                     second_value=False,
                     int_convert=False):

    error_msgs = errors['error_msgs']
    error = True
    count = 0
    add = ''

    message = 'If this ' + name + ' you musr create a ' + required + ' for this ' + trait_name

    if value != '' and value != True:
        return (errors)

    for v in values:
        if v == field:
            return (errors)

    id = int(trait_id)
    trait = getattr(table, trait_column)
    trait_filter = trait == id
    if second_column != False:
        second_attr = getattr(table, second_column)
        if int_convert:
            second_value = integer(second_value)
        second_filter = second_attr == second_value
        check = db.session.query(table).filter(trait_filter,
                                               second_filter).first()
    else:
        check = db.session.query(table).filter(trait_filter).first()
    if check is None:
        error = True
    else:
        if second_column != False:
            check = db.session.query(table).filter(trait_filter,
                                                   second_filter).all()
        else:
            check = db.session.query(table).filter(trait_filter).all()
        for c in check:
            value_field = getattr(c, column)
            for v in values:
                if v == value_field:
                    count += 1
    if multiple:
        if count > 1:
            error = False
    else:
        if count > 0:
            error = False

    if error:
        error_msgs.append(message)
        errors['error_msgs'] = error_msgs
        errors['error'] = error

    return (errors)
예제 #11
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)
예제 #12
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)