def delete_scope(character_id, scope): """ Remove a scope for a given character_id from the database """ if request.is_xhr: allowed_character_id = [ alt.character_id for alt in current_user.alts_characters.all() ] if (character_id == current_user.character_id or character_id in allowed_character_id): try: TokenScope.query.filter( TokenScope.user_id == character_id, TokenScope.scope == scope ).delete() db.session.commit() return json_response('success', '', 200) except: logger.exception('Cannot delete scope %s for user_id %s' % ( scope, character_id, )) db.session.rollback() return json_response('danger', 'Error while trying to delete scope', 500) else: return json_response('danger', 'This character does not belong to you', 500) else: return 'Cannot call this page directly', 403
def update_production_preference(preferences): """ Called by update_user_industry_preference, update the production preferences """ if preferences: pref = current_user.pref try: solar_system, check_main = check_solar_system_name_index( preferences['system'] ) solar_system_subcomp, check_sub = check_solar_system_name_index( preferences['componentSystem'] ) if check_main: pref.prod_system = solar_system if check_sub: pref.prod_sub_system = solar_system_subcomp pref.prod_facility = preferences['facility'] pref.prod_me_rig = preferences['meRig'] pref.prod_te_rig = preferences['teRig'] pref.prod_security = preferences['security'] pref.prod_sub_facility = preferences['componentFacility'] pref.prod_sub_me_rig = preferences['componentMeRig'] pref.prod_sub_te_rig = preferences['componentTeRig'] pref.prod_sub_security = preferences['componentSecurity'] pref.prod_price_region_minerals = preferences['priceMineralRegion'] pref.prod_price_type_minerals = preferences['priceMineralType'] pref.prod_price_region_pi = preferences['pricePiRegion'] pref.prod_price_type_pi = preferences['pricePiType'] pref.prod_price_region_moongoo = preferences['priceMoongooRegion'] pref.prod_price_type_moongoo = preferences['priceMoongooType'] pref.prod_price_region_others = preferences['priceOtherRegion'] pref.prod_price_type_others = preferences['priceOtherType'] pref.prod_character_id = preferences['characterId'] pref.prod_te_implant = preferences['teImplant'] db.session.commit() check = check_main and check_sub return json_response( 'success' if check else 'warning', ("Production preferences updated, solarsystem not updated " "as the system does not exist or does not have any index." if not check else "Production preferences successfuly saved."), 200 ) except: logger.exception('Cannot update preferences') db.session.rollback() return json_response('danger', 'Error while updating preferences', 500) else: return json_response('danger', 'Error: preferences are empty', 500)
def update_reaction_preference(preferences): """ Called by update_user_industry_preference, update the reaction preferences """ if preferences: pref = current_user.pref try: solar_system, check_main = check_solar_system_name_index( preferences['reactionSystem'] ) manuf_solar_system, check_manuf = check_solar_system_name_index( preferences['manufSystem'] ) if check_main: pref.reaction_system = solar_system if check_manuf: pref.reaction_manuf_system = manuf_solar_system pref.reaction_facility = preferences['reactionFacility'] pref.reaction_me_rig = preferences['reactionMeRig'] pref.reaction_te_rig = preferences['reactionTeRig'] pref.reaction_security = preferences['reactionSecurity'] pref.reaction_manuf_facility = preferences['manufFacility'] pref.reaction_manuf_me_rig = preferences['manufMeRig'] pref.reaction_manuf_te_rig = preferences['manufTeRig'] pref.reaction_manuf_security = preferences['manufSecurity'] pref.reaction_price_regions = preferences['priceRegion'] pref.reaction_price_type = preferences['priceType'] pref.reaction_character_id = preferences['characterId'] pref.reaction_manuf_te_implant = preferences['manufTeImplant'] db.session.commit() check = check_main and check_manuf return json_response( 'success' if check else 'warning', ("Reaction preferences updated, solarsystem not updated " "as the system does not exist or does not have any index." if not check else "Reaction preferences successfuly saved."), 200 ) except: logger.exception('Cannot update preferences') db.session.rollback() return json_response('danger', 'Error while updating preferences', 500) else: return json_response('danger', 'Error: preferences are empty', 500)
def delete_characters_skills(): """ remove all character skills for current user """ if is_xhr(request): try: purge_characters_skill(current_user) return json_response('success', 'Characters skills deleted.', 200) except: logger.exception('Cannot delete characters skills [u:%d]' % current_user.character_id) db.session.rollback() return json_response('danger', 'Error while trying to delete skills', 500) else: return 'Cannot call this page directly', 403
def delete_user_account(): """ remove all character blueprint for current user """ if is_xhr(request): char_id = current_user.character_id try: delete_account(current_user) flash("Your account have been deleted.", 'info') return json_response('success', '', 200) except: logger.exception('Cannot delete user account [u:%d]' % char_id) db.session.rollback() return json_response( 'danger', 'Error while trying to delete corporation blueprints', 500) else: return 'Cannot call this page directly', 403
def delete_corporation_blueprint(): """ remove all character blueprint for current user """ if is_xhr(request): try: purge_corporation_blueprints(current_user) return json_response('success', 'Corporations blueprints deleted.', 200) except: logger.exception('Cannot delete corporation blueprints [u:%d]' % current_user.character_id) db.session.rollback() return json_response( 'danger', 'Error while trying to delete corporation blueprints', 500) else: return 'Cannot call this page directly', 403
def get_index_activity(solar_system_names): """ Return all indexes for a given solarsystem name """ ss_name_list = solar_system_names.split(',') # get the solar systems solar_systems = SolarSystem.query.filter( func.lower(SolarSystem.name).in_(ss_name_list) ).all() if not solar_systems: return json_response( 'warning', 'Solar systems (%s) does not exist' % solar_system_names, 404 ) # put the solar system in a dict solar_systems_list = {} for system in solar_systems: solar_systems_list[system.id] = system.name # get the index from the list of solar system industry_index = IndustryIndex.query.filter( IndustryIndex.solarsystem_id.in_(solar_systems_list.keys()), ).all() if not industry_index: return json_response( 'warning', ('There is no index for Solar System (%s).' % solar_system_names), 404 ) # and then put that index list into a dict[solar_system_name] = cost_index index_list = {} for index in industry_index: ss = solar_systems_list[index.solarsystem_id].lower() if ss not in index_list: index_list[ss] = {} index_list[ss][index.activity] = index.cost_index return jsonify(index=index_list)
def update_research_preference(preferences): """ Called by update_user_industry_preference, update the research preferences """ if preferences: pref = current_user.pref try: solar_system, check = check_solar_system_name_index( preferences['system'] ) if check: pref.research_system = solar_system pref.research_facility = preferences['facility'] pref.research_me_rig = preferences['meRig'] pref.research_te_rig = preferences['teRig'] pref.research_copy_rig = preferences['copyRig'] pref.research_security = preferences['security'] pref.research_character_id = preferences['characterId'] pref.research_me_implant = preferences['meImplant'] pref.research_te_implant = preferences['teImplant'] pref.research_copy_implant = preferences['copyImplant'] db.session.commit() return json_response( 'success' if check else 'warning', ("Research preferences updated, solarsystem not updated " "as the system does not exist or does not have any index." if not check else "Research preferences successfuly saved."), 200 ) except: logger.exception('Cannot update preferences') db.session.rollback() return json_response('danger', 'Error while updating preferences', 500) else: return json_response('danger', 'Error: preferences are empty', 500)