def edit_champ(champ_id): if request.method == "GET": champ = Champ.objects().with_id(champ_id) return render_template("edit_champ.html", champ=Champ) else: form = request.form name = form["name"] role = form["role"] editchamp = Champ.objects().with_id(champ_id) editchamp.update(set__name=name) editchamp.update(set__role=role) flash("Edit Successful") return render_template("edit_champ.html", champ=editchamp)
def edit(champ_id): champ = Champ.objects().with_id(champ_id) if champ is None: return 'Not found!' else: if request.method == 'GET': return render_template('edit.html', champ=champ, champs=Champ.objects()) elif request.method == 'POST': form = request.form image = form['image'] name = form['name'] role = form['role'] champ.update(set__name=name, set__role=role, set__image=image) return redirect(url_for('admin'))
def info(champ_id): c_info = Champ.objects().with_id(champ_id) c_img = c_info.image c_role = c_info.role c_name = c_info.name return render_template("info.html", c_img=c_img, c_role=c_role, c_name=c_name)
def show(champ_id): champ = Champ.objects().with_id(champ_id) return render_template('show.html', champ=champ)
def delete(champ_id): Champ.objects(id=champ_id).delete() return redirect(url_for('admin'))
def admin(): return render_template('admin.html', champs=Champ.objects())
def all(): return render_template('all.html', champs=Champ.objects())
"Veigar", "Vel'Koz", "Vi", "Viktor", "Vladimir", "Volibear", # W "Warwick", "Wukong", # X "Xayah", "Xerath", "Xin Zhao", # Y "Yasuo", "Yorick", # Z "Zac", "Zed", "Ziggs", "Zilean", "Zoe", "Zyra" ] champ_role = ["Assassin", "Maskman", "Mage", "Support", "Tank", "Fighter"] for i in champ_name: champ = Champ(image=i + ".png", name=i, role=choice(champ_role)) champ.save()
def delete(champ_id): dels = Champ.objects(id=champ_id) dels.delete() return redirect("http://127.0.0.1:5000/admin", code=302)
def upload(): return render_template('upload.html', champs=Champ.objects())
def info(champ_id): champs = Champ.objects().with_id(champ_id) return render_template('info.html', champs=champs)
from flask import * from mlab import mlab_connect from models.champ import Champ mlab_connect() show_champ = Champ.objects().with_id('5a3931f054710a1728edddd9') champ_img = show_champ.image print(champ_img)