def create_country(): if request.method == 'GET': return render_template('country/create.html') else: country = Country.create(name=request.form['name'], code=request.form['code'], status=request.form['status']) flash("Country has created", 'success') return redirect(url_for('.country_index'))
def delete_country(id): country = Country.get(id=id) if country: country.delete() flash("Country has deleted", 'success') else: flash("Something went wrong", 'danger') return redirect(url_for('.country_index'))
def edit_country(id): country = Country.get(id=id) if country: if request.method == 'GET': return render_template('country/edit.html', country=country) else: country.update(name=request.form['name'], code=request.form['code'], status=request.form['status']) flash("Country has updated", 'success') return redirect(url_for('.country_index')) else: flash("Something went wrong", 'danger') return redirect(url_for('.country_index'))
def put(country_id, body): existing_country = Country.get(id=country_id) if existing_country: country_data = body body.pop('created') body.pop('updated') existing_country.update(**body) else: return problem(status=404, title='Do not exists', detail='Driver with given ID do not exists') return serializer.dump(existing_country)
def country_index(): countries = Country.all() return render_template('country/index.html', countries=countries)
def post(body): country_data = body country = Country.create(**country_data) return {'id': country.id}
def get(country_id): country = Country.get(id=country_id) return serializer.dump(country) or problem( status=404, title='Do not exists', detail='Driver with given ID do not exists')