def user(username): user = User.query.filter_by(username=username).first_or_404() if current_user.role != "Member": form = DeleteForm() form2 = ChangeRoleForm() form3 = MakePostForm() if form.submit.data and form.validate(): if form.confirm.data == "Confirm": db.session.delete(user) db.session.commit() if form2.submit2.data and form2.validate(): if form2.confirm2_1.data == "Confirm": print(form2.radio_buttons.data) user.role = form2.radio_buttons.data db.session.add(user) db.session.commit() return redirect(url_for('admin_settings')) if form3.submit3.data and form3.validate(): p = Post(body=form3.body.data, author=user) db.session.add(p) db.session.commit() return render_template('user.html', title=user.username, user=user, om_admin='ja', form=form, form2=form2, form3=form3) return redirect(url_for('admin_settings'))
def delete_student(): form = DeleteForm() if request.method == 'POST' and form.validate(): student = Students(idNum=form.id_number.data) if student.exist(): student.delete() flash("Deleted student with id number '{}'".format( form.id_number.data), category='success') return redirect(url_for('students')) else: flash("Student Does not exist.", category='danger') return redirect(url_for('delete_student')) else: return render_template('delete_student.html', form=form)
def game(group): # Get user session data user = current_user game = Game.query.filter_by(group=user.group).first() prompt = Prompt.query.all()[0] encounter = Encounter.query.filter_by(number=game.curEnc).first() # Update the user and the game time whenever this view is accessed user.updateTime() game.updateTime() user.compEnc = game.compEnc db.session.commit() # If the game isnt there log them out if game is None: return redirect(url_for('main.logout')) # If the game is marked for deletion, log out the user if game.mode == "VICTORY" or game.mode == "MARKDEL": return redirect(url_for('main.logout')) # Instance all the forms nextForm = NextForm() delForm = DeleteForm() # If the delete button has been pressed, mark the game for deletion if delForm.submit11.data and delForm.validate(): game.mode = 'MARKDEL' game.completedEncounter() db.session.commit() return redirect(url_for('main.logout')) # If next is hit by POC progress the game status if nextForm.submit3.data and nextForm.validate(): encounter = None # Update the game time game.updateTime() db.session.commit() # If the game isnt completed if int(game.compEnc) < int(game.goalEnc): game.selectEncounter() game.selectMarch() game.completedEncounter() # Get a random location from the list game.location = LOCATION_LIST[randint(0, len(LOCATION_LIST) - 1)] db.session.commit() # Get the next encounter encounter = Encounter.query.filter_by(number=game.curEnc).first() # If the game is completed, complete it elif int(game.compEnc) >= int(game.goalEnc): game.victory() game.completedEncounter() db.session.commit() # If the game is deleted at this point, logout if game.mode == "VICTORY" or game.mode == "MARKDEL": return redirect(url_for('main.logout')) # Get a random map if game.randMUpper == '0': map = 'DEFAULTTOERRORIMAGE' else: map = game.curMap + '.PNG' # Render the template return render_template(['game.html', 'base.html'], prompt=prompt, user=user, game=game, map=map, encounter=encounter, nextForm=nextForm, delForm=delForm)