def render_template(self, **kwargs): """ We need to render a different form based on whether the user is on a team or not. If account.team is None, we should let them create a new team using CreateTeamForm. Otherwise, we show all the options available to existing teams: Editing team details, adding/removing team members, or leaving the team. """ account = session_util.get_account() if not account.profile: flash('Please complete your profile before editing your team.', 'danger') return redirect(url_for('profile')) if not account.team: create_form = kwargs.get('create_form', None) or self.get_form() return super().render_template(create_form=create_form) else: updateTeamForm = kwargs.get('update_form', None) \ or UpdateTeamForm(team_name=account.team.team_name, division=account.team.division) addMemberForm = kwargs.get('add_form', None) \ or AddMemberForm() return super().render_template(edit_form=updateTeamForm, add_form=addMemberForm)
def get(self): account = session_util.get_account() # Try leaving the team. If they're not on one, that's fine too. if account.team: leave_team(account, account.team) return redirect(url_for('team'))
def get(self): uid = request.args.get('uid', None) account = session_util.get_account() if account.team and uid: rm_account = auth_util.get_account(uid) team_util.leave_team(rm_account, account.team) flash("Removed {} from your team".format(uid)) return redirect(url_for('team'))
def post(self): add_form = AddTeamMemberForm(request.form) if add_form.validate(): add_account = add_form.account user_account = session_util.get_account() if team_util.join_team(add_account, team=user_account.team): flash("Added {} to your team".format(add_account.email)) return redirect(url_for('team')) return self.render_template(add_form=add_form)
def get_form(self): account = session_util.get_account() form = EditAccountForm( first_name=account.first_name, last_name=account.last_name, fsuid=account.fsuid, ) # Show current extra credit courses form.courses.data = course_util.get_account_courses(account) return form
def post(self): update_form = UpdateTeamForm(request.form) if update_form.validate(): try: account = session_util.get_account() team_util.set_division(account.team, update_form.division.data) team_util.rename_team(account.team, update_form.team_name.data) return redirect(url_for('team')) except: flash('Error updating team information.') return self.render_template(update_form=update_form)
def post(self): create_form = CreateTeamForm(request.form) if create_form.validate(): try: account = session_util.get_account() team = team_util.create_team(account, create_form.team_name.data) team_util.set_division(team, create_form.division.data) return redirect(url_for('team')) except: flash('Error creating team.') return self.render_template(create_form=create_form)
def post(self): form = EditAccountForm(request.form) if form.validate(): account = session_util.get_account() data = {field.name: field.data for field in form} del data['csrf_token'] del data['submit'] account.update(**data) account.save() flash('Account updated') return self.render_template(form=form)
def post(self): form = UpdatePasswordForm(request.form) if form.validate(): old_pass = form.current_password.data new_pass = form.new_password.data account = session_util.get_account() if account.check_password(old_pass): account.set_password(new_pass) account.save() flash("New password saved", 'success') else: # flash("That's not your current password.", 'error') form.current_password.errors.append( "That's not your current password.") return self.render_template(form=form)
def post(self): form = ProfileForm(request.form) if form.validate(): account = session_util.get_account() data = {field.name: field.data for field in form} del data['csrf_token'] del data['submit'] if not account.profile: account.profile = Profile(**data) else: account.profile.update(**data) account.profile.save() account.save() if account.team: team_util.validate_division(account.team) flash('Profile updated') return self.render_template(form=form)
def post(self): form = EditAccountForm(request.form) if form.validate(): account = session_util.get_account() data = {field.name: field.data for field in form} del data['csrf_token'] del data['submit'] del data['courses'] # Set user's extra credit courses course_util.set_courses(account, form.courses.data) account.update(**data) account.save() # Check if team must be moved to upper division if account.team: if account.team.division == 2: team_util.set_division(account.team, account.team.division) flash('Account updated') return self.render_template(form=form)
def is_accessible(self): try: account = session_util.get_account() return account.is_admin == True except: return False
def get_form(self): account = session_util.get_account() if account.profile: return ProfileForm(obj=account.profile) else: return ProfileForm()
def get_form(self): account = session_util.get_account() return EditAccountForm(first_name=account.first_name, last_name=account.last_name, fsuid=account.fsuid)
def render_template(self, **kwargs): account = session_util.get_account() return super().render_template(account=account, **kwargs)
def authorize(self): account = session_util.get_account() return account.is_admin is True