def create(cls, name, country): country_rec = Country.get(country) if country_rec: id = int(datetime.timestamp(datetime.now()) * 1000) body = {"name": name, "country": country_rec["name"]} res = es.index(index=os.environ.get("INDEX"), doc_type='state', id=id, parent=country_rec["id"], body=body) if "created" in res and res["created"]: return True return False
def edit(cls, id, name, country): country_rec = Country.get(country) if country_rec: res = es.index(index=os.environ.get("INDEX"), doc_type='state', id=id, parent=country_rec["id"], body={ "name": name, "country": country_rec["name"] }) if "result" in res and res["result"] == "updated": return True return False
def country_edit(id): country_form = EditCountryForm() if request.method == 'POST': if not country_form.validate(): flash('All fields are required.') return render_template('crud/country/edit.html', form=country_form) else: result = Country.edit_country(request.form["id"], request.form["name"]) if result: flash('Country edited successfully!!!') return redirect(url_for('country')) else: flash('Unable to edit country.') return render_template('crud/country/edit.html', form=country_form) else: country = Country.get(id) if not country: return redirect(url_for('country')) country_form.name.data = country["name"] country_form.id.data = country["id"] return render_template('crud/country/edit.html', form=country_form)