def accountsNew(): if request.method == 'POST': form = AccountForm(request.form) if form.validate(): db.accounts.insert_one(form.data) flash('New account %s added' %(form.name.data)) return redirect('/admin/accounts') else: return render_template('backend/accounts/edit.html', form=form, title='New account') form = AccountForm() return render_template('backend/accounts/edit.html', form=form, title='New account')
def accountsEdit(id): account = db.accounts.find_one({ '_id': ObjectId(id) }) if account: if request.method == 'POST': form = AccountForm(request.form) if form.validate(): db.accounts.update({ '_id': ObjectId(id) }, form.data) return redirect('/admin/accounts') else: return render_template('backend/accounts/edit.html', form=form, title='account: ' + account['name']) form=accountForm(data=account) return render_template('backend/accounts/edit.html', form=form, title='account: ' + account['name']) else: flash('account %s not found' %id) return redirect('/admin/accounts')
def account(): """ Route for url: server/settings/account/ """ if 'username' in session: form = AccountForm() if request.method == 'GET': cur = get_cursor() user_data = get_user_data(cur, session['username']) form.first_name.data = user_data['first_name'] form.last_name.data = user_data['last_name'] form.email.data = user_data['email'] return render_template('account.html', form = form, username = session['username']) if request.method == 'POST': if form.validate(): cur = get_cursor() update_user_data(cur, form, session['username']) flash('Your account information has been successfully updated!') return redirect(url_for('account')) return render_template('account.html', form = form, username = session['username']) return abort(404)