def update_countries_page(key = None): page = Country(dsn = app.config['dsn']) if request.method == 'GET': return page.open_updatecountries(id = key) elif 'updatecountries' in request.form: country_name = request.form['country_name'] average = request.form['average'] gm = request.form['gm'] im = request.form['im'] total_titled = request.form['total_titled'] total_top = request.form['total_top'] country_rank = request.form['country_rank'] best_player = request.form['best_player'] highest_rating = request.form['highest_rating'] return page.update_countries(key, country_name, average, gm, im, total_titled, total_top, country_rank, best_player, highest_rating) else: return redirect(url_for('home_page'))
def country_edit(country_id): if request.method == 'GET': return render_template('country_edit.html', key=country_id, country=app.countries.get_country(country_id)) else: name = request.form['name'] abbreviation = request.form['abbreviation'] app.countries.update_country(country_id, Country(name, abbreviation)) return render_template('countries.html', countries=app.countries.get_countries())
def countries(): if request.method == 'GET': return render_template('countries.html', countries=app.countries.get_countries()) else: if 'Add' in request.form: name = request.form['name'] abbreviation = request.form['abbreviation'] app.countries.add_country(Country(name, abbreviation)) return render_template('countries.html', countries=app.countries.get_countries()) elif 'Delete' in request.form: id = request.form['id'] app.countries.delete_country(id) return render_template('countries.html', countries=app.countries.get_countries()) elif 'Search' in request.form: search_terms = request.form['search_terms'] return render_template( 'countries.html', countries=app.countries.search_countries(search_terms))
# d = {} # for i in tab: # image = i[7] # a = image.find('"') # path = image[a+1:] # b = path.find('"') # path = path[:b] # path = 'maps/' + path.replace('.png', '') # d[i[0]] = path # List files of starting_data folder folder = 'data/0_starting_data/' files = os.listdir(folder) files = [a.replace('.json', '') for a in files] for country_name in files: c = Country(folder, country_name) # try: # file_name = d[country_name] # except KeyError: # file_name = country_name # # if file_name == '': # file_name = 'maps/' + country_name c.simplify('polygon_display/', thresh=0.1, nb_points=10) # c.draw(file_name + '1') c.simplify('polygon_collision/', thresh=1.5) # c.draw(file_name + '2')
def countries_page(key = None): page = Country(dsn = app.config['dsn']) if key == 1: return page.open_page("country_name") elif key == 2: return page.open_page("average") elif key == 3: return page.open_page("gm") elif key == 4: return page.open_page("im") elif key == 5: return page.open_page("total_titled") elif key == 6: return page.open_page("total_top") elif key == 7: return page.open_page("country_rank") elif key == 8: return page.open_page("best_player") elif key == 9: return page.open_page("highest_rating") elif request.method == 'GET': return page.open_page() elif 'initializeTable' in request.form: return page.init_table() elif 'addcountry' in request.form: country_name = request.form['country_name'] average = request.form['average'] gm = request.form['gm'] im = request.form['im'] total_titled = request.form['total_titled'] total_top = request.form['total_top'] country_rank = request.form['country_rank'] best_player = request.form['best_player'] highest_rating = request.form['highest_rating'] return page.add_country(country_name, average, gm, im, total_titled, total_top, country_rank, best_player, highest_rating) elif 'deletecountry' in request.form: country_name = request.form['country_name'] return page.delete_country(country_name) elif 'findcountry' in request.form: country_name = request.form['country_name'] return page.find_country(country_name) else: return redirect(url_for('home_page'))
def test_country_object(self): country = Country('CA', 'Canada') self.assertEqual(country.code, 'CA') self.assertEqual(country.name, 'Canada')
from cities import City from users import User from travels import Travels, Travel from votes import Vote from login import Login cors = CORS(allow_origins_list=['http://localhost:9000']) api = falcon.API(middleware=[cors.middleware]) api.add_route('/countries', Countries()) api.add_route('/country/{country}', Country()) api.add_route('/country/{country}/city/{city}', City()) api.add_route('/users/{query}', User()) api.add_route('/travel', Travel()) api.add_route('/travels', Travels()) api.add_route('/travel/vote', Vote()) api.add_route('/login', Login())
def add_country(country: str, continent_id: int): session.add(Country(country, continent_id)) session.commit()