def individuals_remove(individual_id): i = Individual.query.filter_by(id=individual_id).first() if i.account_id != current_user.id: return login_manager.unauthorized() db.session.delete(i) db.session.commit() return redirect(url_for("individuals_index"))
def individuals_show(individual_id): i = Individual.query.get(individual_id) if i.account_id != current_user.id: return login_manager.unauthorized() species = Species.query.get(i.species_id) return render_template("individuals/edit.html", individual=i, species=species, form=EditIndividualForm())
def delete_comment(thread_id, comment_id): comment = db.session.query(Comment).filter(Comment.id==comment_id).first() #TODO: tee tämä if comment.user != current_user.get_id(): return login_manager.unauthorized() comment.text = "Poistettu" comment.is_deleted = True db.session.commit() return redirect(url_for("read_thread", id=id, thread_id=thread_id))
def ryhmat_remove(ryhma_id): r = Ryhma.query.get(ryhma_id) if r.vastuuvalmentaja_id != current_user.id: return login_manager.unauthorized() if request.method == "POST": db.session().delete(r) db.session().commit() return redirect(url_for("ryhmat_index")) return render_template("ryhmat/poistovahvistus.html")
def individuals_set_favourite(individual_id): i = Individual.query.get(individual_id) if i.account_id != current_user.id: return login_manager.unauthorized() if i.favourite: i.favourite = False else: i.favourite = True db.session().commit() return redirect(url_for("individuals_index"))
def ryhmat_update(ryhma_id): form = RyhmanimiForm(request.form) if not form.validate(): return render_template("ryhmat/uusinimi.html", form=form, ryhma_id=ryhma_id) r = Ryhma.query.get(ryhma_id) if r.vastuuvalmentaja_id != current_user.id: return login_manager.unauthorized() r.ryhma = form.ryhma.data db.session().commit() return redirect(url_for("ryhmat_index"))
def edit_comment(comment_id): #TODO: tee tämä form = CommentForm(request.form) comment = db.session.query(Comment).filter(Comment.id==comment_id).first() if comment.user != current_user.get_id(): return login_manager.unauthorized() if request.method == "POST" and form.validate(): text = form.text.data db.session.query(Comment)\ .filter(Comment.id==comment_id)\ .update({Comment.text: text}, synchronize_session=False) db.session.commit() return redirect(url_for("read_thread", id=id, thread_id=comment.thread_id)) form.text.data = comment.text return render_template("threads/edit.html", form=form, comment=comment)
def individuals_edit(individual_id): i = Individual.query.get(individual_id) if i.account_id != current_user.id: return login_manager.unauthorized() form = EditIndividualForm(request.form) species = Species.query.get(i.species_id) if not form.validate(): return render_template("individuals/edit.html", form=form, individual=i, species=species) species = Species.query.filter_by(name=form.species.data.lower()).first() i.nickname = form.nickname.data i.level = form.level.data i.species_id = species.id db.session.commit() return redirect(url_for("individuals_index"))