Esempio n. 1
0
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'))
Esempio n. 2
0
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'))
Esempio n. 3
0
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'))
Esempio n. 4
0
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)
Esempio n. 5
0
def country_index():
    countries = Country.all()
    return render_template('country/index.html', countries=countries)
Esempio n. 6
0
def post(body):
    country_data = body
    country = Country.create(**country_data)

    return {'id': country.id}
Esempio n. 7
0
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')