def account_detail(request, return_to=None, extra_context={}): # We edit current user's MUAccount account = get_object_or_404(MUAccount, owner=request.user) # but if we're inside a MUAccount, we only allow editing that muaccount. if getattr(request, 'muaccount', account) <> account: return HttpResponseForbidden() if return_to is None: return_to = reverse('muaccounts.views.account_detail') if 'domain' in request.POST: form = MUAccountForm(request.POST, request.FILES, instance=account) if form.is_valid(): form.save() return HttpResponseRedirect(return_to) else: form = MUAccountForm(instance=account) if 'user' in request.POST: uform = AddUserForm(request.POST, muaccount=account) if uform.is_valid(): account.add_member(uform.cleaned_data['user']) return HttpResponseRedirect(return_to) else: uform = AddUserForm() ctx = dict(object=account, form=form, add_user_form=uform) ctx.update(extra_context) return direct_to_template( request, template='muaccounts/account_detail.html', extra_context=ctx)
def users(): addUser = AddUserForm() if addUser.validate_on_submit(): login_db.add([addUser.username.data, addUser.password.data, addUser.type.data]) return redirect(url_for("users")) return render_template("user_management.html", subheading="User Management", addUser=addUser, table=user_table(), accounts=login_db.read(), page="user-management")
def add_user(): form = AddUserForm(request.form) if form.validate(): result = {} result['iserror'] = False if not form.id.data: if True: newuser = User(email=form.email.data) newuser.hash_password(form.password.data) db.session.add(newuser) db.session.commit() result['savedsuccess'] = True else: result['savedsuccess'] = False return json.dumps(result) else: edituser = User.query.get(form.id.data) edituser.email = form.email.data edituser.hash_password(form.password.data) db.session.commit() result['savedsuccess'] = True return json.dumps(result) else: form.errors['iserror'] = True print form.errors return json.dumps(form.errors)
def add_user(): form = AddUserForm() if 'username' not in session: return redirect(url_for('signin')) user = session['username'] if user is None: redirect(url_for('signin')) else: if request.method == 'POST': if not form.validate(): return render_template('adduser.html', form=form) else: newuser = Users(username=form.username.data.lower(), password_hash=form.password.data, role=form.role.data, timestamp=datetime.datetime.now()) db.session.add(newuser) db.session.commit() flash('User added.') return redirect(url_for('add_user')) elif request.method == 'GET': users = db.session.query(Users).filter(Users.role != 'admin').all() return render_template('adduser.html', form=form, users=users)
def adduser(): form=AddUserForm(request.form) #users=models.User.query.all() if request.method == 'POST' and form.validate(): u=User(username=request.form['username'],email=request.form['email'],password=form.password.data) db.session.add(u) db.session.commit() flash("user has been added.") return redirect(url_for('user')) return render_template('adduser.html',form=form)
def add_user(): form = AddUserForm() if form.validate_on_submit(): try: user = User(form.name.data, form.password.data, form.email.data) db.session.add(user) db.session.commit() return redirect(url_for('view_frontend')) except IntegrityError: form.email.errors.append('Email address is not unique') return render_template('user_add.html', form=form)
def team_management(): form = AddUserForm() allTeamMembers = teamMembers() allTeamMembers = allTeamMembers.get("members") if form.validate_on_submit(): member_email = form.member_email.data member_given_name = form.member_given_name.data member_surname = form.member_surname.data member_external_id = form.member_external_id.data newguy = addMember(member_email, member_given_name, member_surname, member_external_id) return redirect('/') return render_template('main/team_management.html', form=form, teamMembers=allTeamMembers)
def addUser(): form = AddUserForm() customer_choices = [(a.id, a.name) for a in Customer.query.filter_by(customer_type=CUSTOMER_TYPES['TYPE_CUSTOMER']).all()] customer_choices = [(0, '')] + customer_choices maker_choices = [(a.id, a.name) for a in Maker.query.all()] maker_choices = [(0, '')] + maker_choices form.customer.choices = customer_choices form.maker.choices = maker_choices if form.validate_on_submit(): if len(User.query.filter_by(nickname=form.nickname.data).all()) > 0: flash(gettext("Selected username already exists!")) return redirect(url_for('users')) new_email = form.email.data check_mail = User.query.filter_by(email=new_email).all() #user mail already exists if len(check_mail) > 0: flash(gettext('Selected email is already in use!')) return redirect(url_for('users')) user = User() user.nickname = form.nickname.data user.password = generate_password_hash(form.password.data) user.email = form.email.data user.role = form.role.data if int(form.role.data) == USER_ROLES['ROLE_CUSTOMER']: if form.customer.data and form.customer.data != '' and form.customer.data != 0: user.customer_id = form.customer.data else: user.customer_id = None elif int(form.role.data) == USER_ROLES['ROLE_MAKER']: if form.maker.data and form.maker.data != '' and form.maker.data != 0: user.maker_id = form.maker.data else: user.maker_id = None else: user.customer_id = None user.maker_id = None user.language = form.language.data db.session.add(user) db.session.commit() flash(gettext("New user successfully added.")) return redirect(url_for("users")) return render_template('settings/addUser.html', title=gettext("Add New User"), USER_ROLES=USER_ROLES, form=form)
def new_user(): form = AddUserForm(request.form, csrf_enabled=False) if form.validate_on_submit(): new_user = Users(form.firstname.data, form.lastname.data, form.username.data, form.password.data, session['user_id'], 0) try: db.session.add(new_user) db.session.commit() flash('New user was successfully added. Thanks.') except IntegrityError: error = 'Oh no! That username and/or email already exist. Please try again.' return render_template('register.html', form=form, error=error) else: # flash("All fields are required. Please try again.") flash_errors(form) return redirect(url_for('users'))
def adduser(): form = AddUserForm() if request.method == 'POST': if form.validate() == False: return render_template('addUser.html', form=form) else: #newuser = User('chas', '*****@*****.**', 'calico!', admin, secret) newuser = User(form.username.data, form.email.data, form.password.data, form.admin.data, form.secret.data) db.session.add(newuser) db.session.commit() flash("User has been added.") return redirect(url_for('listusers')) elif request.method == 'GET': return render_template('addUser.html', form=form)
def add_user(): form = AddUserForm(request.form) if request.method == "POST" and form.validate(): user = User(form.username.data, form.email.data, form.password.data) db.session.add(user) db.session.commit() flash("User added", "info") return redirect(url_for("add_user")) return render_template( "_add.html", form=form, rows=User.query.all(), target_model="User", fields=User.__mapper__.c.keys(), action="adduser", )
def entity_add_user(request, entity_id): entity = get_object_or_404(Entity, pk=entity_id) if request.POST: form = AddUserForm(request.POST) if form.is_valid(): #Lookup or create user, add to entity email = form.cleaned_data['email'] form.cleaned_data['username'] = email[:30] del form.cleaned_data['email'] user, created = User.objects.get_or_create(email=email, defaults=form.cleaned_data) if created: reset_form = PasswordResetForm({'email':user.email}) reset_form.is_valid() reset_form.save(email_template_name="registration/new_account.html", subject=_("Account created on %s")) assign('change_entity', user, entity) return HttpResponseRedirect(reverse('show_user',args=[user.pk])) else: form = AddUserForm() return render_to_response('scorecard_processor/entity/add_user.html', {'object':entity,'form':form}, RequestContext(request))
def add_user(request,template_name='form1.html'): adduserForm = AddUserForm(request.POST or None) if request.method == 'POST': if adduserForm.is_valid(): password = adduserForm.save_user() messages.success(request,'User successfully added') messages.success(request,password) return HttpResponseRedirect(reverse('club_main')) if request.user.get_profile().typ == 'Admin': adduserForm.fields['typ'].choices = [('Admin','Admin'),('Core','Core'),('Convener','Convener'),('Coordinator','Coordinator')] elif request.user.get_profile().typ == 'Core': adduserForm.fields['typ'].choices = [('Convener','Convener'),('Coordinator','Coordinator')] elif request.user.get_profile().typ == 'Convener': adduserForm.fields['typ'].choices = [('Coordinator','Coordinator')] return_url = reverse('add_user') to_return={ 'form' : adduserForm, 'title' : "Add User", 'return_url' : return_url, 'button' : 'Add', } return render(request,template_name,to_return)
def add_user(): if g.user.is_authenticated() and g.user.is_admin(): form = AddUserForm() if request.method == 'POST' and form.validate_on_submit(): user_email = form.user_email.data registered_user = User.query.filter_by(user_email = user_email).first() if registered_user is not None: flash("The email already exists" , "error") return redirect(url_for('add_user')) password = '******' if form.password.data == '' else form.password.data user = User(form.name.data, form.user_email.data, password, form.role.data) db.session.add(user) db.session.commit() flash("Added User : "******" with Email : " + form.user_email.data + ", password : "******", role : " + form.role.data) if form.add_user.data: return redirect(url_for('index')) else: return redirect(url_for('test')) return render_template("addUser.html", title = "Add User", form = form) flash("You are not authorised to view the page") return redirect(url_for('index'))
def admin(): form = AddUserForm(prefix="form") formUpdate = UpdateUserForm(prefix="formUpdate", idUser='******') u = Users.query.order_by(Users.id).all() formDelete = DeleteUserForm(prefix="formDelete") if form.validate_on_submit() and form.submit.data: a.createUser(session['author_id'], session['session_id'], form.login.data, form.email.data, form.password.data, form.admin.data) elif request.method == 'POST' and form.validate() == False and not formUpdate.submit.data and not formDelete.submit.data: flash("Error during the user creation!") if formUpdate.validate_on_submit() and formUpdate.submit.data: if formUpdate.idUser.data == '0': formUpdate.idUser.data = session['author_id'] a.updatePassword(session['author_id'], session['session_id'], int(formUpdate.idUser.data), formUpdate.oldPassword.data, formUpdate.password.data) if formDelete.validate_on_submit() and formDelete.submit.data: a.getUserByName(session['author_id'], session['session_id'], formDelete.name.data) time.sleep(1) u = Users.query.filter_by(name = formDelete.name.data).all() if not u: flash("User not found or the server don't send the user information!") else: u = u[0] print formDelete.password.data a.delUser(session['author_id'], session['session_id'], u.id, formDelete.password.data) return render_template('admin.html', form=form, formUpdate=formUpdate,u = u, formDelete=formDelete)
def adduser(): form = AddUserForm() if form.validate_on_submit(): client = MongoClient(MONGODB_URI) db = client.get_default_database() users = db.users newUser = { "username": form.username.data, "password": form.password.data } users.insert(newUser) users = db.users for user in users.find(): if user['username'] == form.username.data and user['password'] == form.password.data: u = User.get(str(user['_id'])) login_user(u, remember=True) return redirect('index') flash("Logged in successfully.") return redirect("/index") return redirect('/login') return render_template('adduser.html', title = 'Add New User', form = form)
def EditUser(request, users_id): try: obj_list = EmployeeUser.objects.get(id=users_id) if request.method == 'POST': form = AddUserForm(request.POST, instance=obj_list) if form.is_valid(): form.save() return HttpResponseRedirect('/users/') else: form = AddUserForm(instance=obj_list) return render(request, 'include/employee/edituser.html', {'form': form}) except EmployeeUser.DoesNotExist: raise PermissionDenied
def user_add(request): if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): user = form.save(commit=False) # 扩展user字段后,密码会变成明文密码,需要转储 user.set_password(form.cleaned_data['password']) # user.objects.filter(id=user.id).update(password=user.password) #使用update保存,或者直接save保存 form.save() messages.success(request, '注册成功') return HttpResponseRedirect(reverse('login')) else: form = AddUserForm() kwargs = { 'form': form, 'request': request, } return render(request, 'accounts/register.html', kwargs)
def user_add(request): temp_name = "accounts/accounts-header.html" if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(form.cleaned_data['password']) form.save() return HttpResponseRedirect(reverse('user_list'), RequestContext(request)) else: form = AddUserForm() kwargs = { 'form': form, 'request': request, 'temp_name': temp_name, } return render(request, 'accounts/user_add.html', kwargs)
def create_user(): form = AddUserForm() name = form.data.get('name') phone = form.data.get('phone') if not name or not phone: return redirect('/') u = User.query.filter((User.name == name) & (User.phone == phone)).first() if u: return redirect('/') else: new_u = User(name=name, phone=phone) db.session.add(new_u) db.session.commit() return redirect('/')
def user_add(request): temp_name = "accounts/accounts-header.html" if request.method == 'POST': form = AddUserForm(request.POST) print dir(form) print form.errors if form.is_valid(): print form.errors user = form.save(commit=False) user.set_password(form.cleaned_data['password']) form.save() return redirect(('user_list')) else: form = AddUserForm() args = { 'form':form, 'request':request, 'temp_name':temp_name } return render(request, 'accounts/user_add.html', args)
def user_add(request): temp_name = "accounts/accounts-header.html" if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(form.cleaned_data['password']) form.save() return HttpResponseRedirect(reverse('user_list')) else: form = AddUserForm() kwargs = { 'form': form, 'request': request, 'temp_name': temp_name, } return render(request, 'accounts/user_add.html', kwargs)
def settings(): user_status = current_user.status if user_status != 1: return render_template('profile.html') else: form = AddUserForm() form.select_kategori_wbs.choices = [("", "---")] + [ (i.id_kategori_wbs, i.kategori_wbs) for i in KategoriWbs.query.all() ] results = db.session.query( InputWbs, WbsLevel3, WbsLevel2, WbsSpesifik, KategoriWbs).select_from(InputWbs).join(WbsLevel3).join( WbsLevel2).join(WbsSpesifik).join(KategoriWbs).all() if request.method == 'POST': new_user = User(nama=form.nama.data, username=form.username.data, password=generate_password_hash(form.password.data), join_date=datetime.now(), divisi=form.select_divisi.data, kategori_wbs=form.select_kategori_wbs.data, wbs_spesifik=form.select_wbs_spesifik.data, status=form.select_status.data) db.session.add(new_user) db.session.commit() return 'sukses' return render_template('settings.html', form=form, results=results)
def create_user(): form = AddUserForm(meta={'csrf': False}) form.name = request.json['name'] form.email = request.json['email'] form.year = request.json['year'] form.color = request.json['color'] if not form.validate(): return (jsonify(errors = form.errors), 201) new_user = User(name=form.name, email=form.email, birth_year=form.year, color=form.color, lucky_num=random.randrange(1, 101, 1)) db.session.add(new_user) db.session.commit() api_year_response = requests.get( f'http://numbersapi.com/{new_user.birth_year}/year?json').json()['text'] api_num_response = requests.get( f'http://numbersapi.com/{new_user.lucky_num}?json').json()['text'] user_response_json = jsonify(num={'num': f'{new_user.lucky_num}', 'fact': f'{api_num_response}'}, year={'year': f'{new_user.birth_year}', 'fact': f'{api_year_response}'}) return (user_response_json, 201)
def display_register_form(): form = AddUserForm() return render_template("add_user_form.html", form=form)
def UserMain(request): rolename = utils.get_rolename_by_username(request.user) return_dict = {'rolename':rolename, 'username':request.user, 'windowname':'None'} #add user adduserform = AddUserForm() return_dict['addUserForm'] = adduserform edituserform = EditUserForm() return_dict['editUserForm'] = edituserform if request.method == "POST": if request.POST.get('formtype') == 'add': adduserform = AddUserForm(request.POST) if adduserform.is_valid(): if User.objects.filter(username=adduserform.fields.get('username')).count() == 0: user = User.objects.create_user(adduserform.fields.get('username'), adduserform.fields.get('email'),\ adduserform.fields.get('password')) user.save() userrole_list = UserRole.objects.filter(username=adduserform.fields.get('username')) if userrole_list.count() != 0: userrole_list.delete() userrole = UserRole(username=user.username, rolename=adduserform.fields.get('rolename'),\ domain=adduserform.fields.get('domain'),realname=adduserform.fields.get('realname')) userrole.save() return_dict['windowname'] = 'successwindow' return_dict['windowmessage'] = u'增加用户成功' else: return_dict['windowname'] = 'errorwindow' return_dict['windowmessage'] = u'用户名已存在,请更换用户名' else: return_dict['windowname'] = 'errorwindow' return_dict['windowmessage'] = adduserform.error_message if request.POST.get('formtype') == 'edit': edituserform = EditUserForm(request.POST) if edituserform.is_valid(): user = User.objects.get(username=edituserform.fields.get('username')) userrole = UserRole.objects.get(username=edituserform.fields.get('username')) user.email = edituserform.fields.get('email') userrole.rolename, userrole.domain, userrole.realname = \ edituserform.fields.get('rolename'),edituserform.fields.get('domain'),edituserform.fields.get('realname') user.save() userrole.save() return_dict['windowname'] = 'successwindow' return_dict['windowmessage'] = u'修改用户属性成功' else: return_dict['windowname'] = 'errorwindow' return_dict['windowmessage'] = edituserform.error_message if request.POST.get('formtype') == 'delete': deleteusername = request.POST.get('username','') print 'deleteusername:'******'windowname'] = 'errorwindow' return_dict['windowmessage'] = u'不能删除自己' User.objects.filter(username=deleteusername).delete() UserRole.objects.filter(username=deleteusername).delete() return_dict['windowname'] = 'successwindow' return_dict['windowmessage'] = u'删除用户成功' #list user users = User.objects.all() userinfos = [] for user in users: userinfos.append(UserInfo(user)) paginator = Paginator(userinfos, 25) try: page = request.GET.get('page','1') userinfos = paginator.page(page) except PageNotAnInteger: userinfos = paginator.page(1) except EmptyPage: userinfos = paginator.page(paginator.num_pages) except Exception: userinfos = paginator.page(1) return_dict['userlist'] = userinfos print userinfos.number return render_to_response('UserManage/user.html',return_dict, RequestContext(request))
def register(request,form_registration=None,college_name=None): #logged in user cannot register, but just in case dajax = Dajax() college = None new_coll = False if not college_name is None: try: college=College.objects.filter(name=str(college_name))[0] new_coll = True except: #impossible scenario!! dajax.script("$.bootstrapGrowl('You must have entered your college first!', {type:'danger',delay:10000});") dajax.script('$("#gif_registration").hide();$("#form_registration_submit").show()') return dajax.json() if request.user.is_authenticated(): msg_login = '******' % request.user.username dajax.script('$.bootstrapGrowl("Hi %s" , {type:"danger",delay:10000} );'% msg_login ) dajax.script('$("#gif_registration").hide();$("#form_registration_submit").show()') return dajax.json() if request.method=="POST" and (form_registration !=None or not college_name is None): form = AddUserForm(deserialize_form(form_registration)) if form.is_valid(): #TODO: if we change college to be a compulsory, then this must be changed dajax.remove_css_class('#form_registration input', 'error') data = form.cleaned_data new_user = User(first_name=data['first_name'],last_name=data['last_name'], username=data['username'], email=data['email']) new_user.set_password(data['password']) new_user.save() new_user.is_active = True new_user.save() x = 1400000 + new_user.id salt = sha.new(str(random.random())).hexdigest()[:5] activation_key = sha.new(salt + new_user.username).hexdigest() if college is None: userprofile = UserProfile(user=new_user,activation_key=activation_key,gender=data['gender'],age=data['age'],branch=data['branch'],mobile_number=data['mobile_number'],college=data['college'],college_roll=data['college_roll'],shaastra_id= ("SHA" + str(x)),key_expires = timezone.now()+datetime.timedelta(2)) else: userprofile = UserProfile(user=new_user,activation_key=activation_key,gender=data['gender'],age=data['age'],branch=data['branch'],mobile_number=data['mobile_number'],college=college,college_roll=data['college_roll'],shaastra_id= ("SHA" + str(x)),key_expires = timezone.now()+datetime.timedelta(2)) userprofile.save() #mail_template = get_template('email/activate.html') #body = mail_template.render( Context( { # 'username':new_user.username, # 'activationkey':userprofile.activation_key, # 'SITE_URL':settings.SITE_URL, # 'shaastra_id':userprofile.shaastra_id, # })) #TODO: empty the entire form!! #dajax.script("$('#form_registration').val('');")\ #dajax.script("$('#form_registration #id_email').val('');\ # $('#form_registration #id_password').val('');\ # $('#form_registration #id_password_again').val('');\ # $('#form_registration #id_mobile_number').val('');") #if settings.SEND_EMAILS: #subject, from_email, to = 'Your new Shaastra2014 account confirmation', '*****@*****.**', [new_user.email,] #html_content = body #text_content = strip_tags(body) #msg = EmailMultiAlternatives(subject, text_content, from_email, to) #msg.attach_alternative(html_content, "text/html") #msg.send() #send_mail('Your new Shaastra2014 account confirmation', body,'*****@*****.**', [new_user.email,], fail_silently=False) #msg='Hi, A mail has been sent to the mail id you provided. Please activate your account within 48 hours. Please also check your spam folder' msg = 'Successfully Registered ! <br /> Welcome !' # dajax.script('$(".modal-header").find(".close").click();') dajax.script('$.bootstrapGrowl("%s" , {type:"success",delay:20000} );'% msg ) dajax.script('$("#gif_registration").hide();$("#form_registration_submit").show();$("#login").modal("hide")') dajax.script('$("#form_registration #id_college_roll").attr("readonly", false);$("#form_registration #id_college_roll").val("");') return dajax.json() else: errdict=dict(form.errors) dajax.script('$.bootstrapGrowl("Oops : Following errors cropped up when you tried to register !", {type:"danger",timeout:50000} );') for error in form.errors: if str(errdict[error][0])!='This field is required.': dajax.script('$.bootstrapGrowl(" %s" , {type:"error",delay:20000} );'% str(errdict[error][0])) dajax.script("$('#form_registration #id_password').val('');") dajax.script("$('#form_registration #id_password_again').val('');") for error in form.errors: dajax.add_css_class('#form_registration #id_%s' % error, 'error') dajax.script('$("#gif_registration").hide();$("#form_registration_submit").show()') return dajax.json() if request.method == 'GET': form_registration = AddUserForm() dajax.script('$("#gif_registration").hide();$("#form_registration_submit").show()') return dajax.json() form_registration=AddUserForm() dajax.script('$("#gif_registration").hide();$("#form_registration_submit").show()') return dajax.json()
def register(): """registration page for a new user""" form = AddUserForm() return render_template("register.html", form=form)
def index(): form = AddUserForm() return render_template('index.html', form=form)
def add_user(username): form = AddUserForm() #session_user = User.query.filter_by(username=session['username']).first() session_user = User.query.filter(User.username == username).first() if request.method == 'GET': return render_template('add_user.html', form=form, title='Add User Information', session_username=session_user.username) else: #session_user.first_name= 'first_name' #session_user.last_name= 'last_name' #db.session.commit() #return redirect('/index') #session_user = User.query.filter_by(username=session['username']).first() if form.validate_on_submit(): first_name = request.form['first_name'] last_name = request.form['last_name'] state = request.form['state'] zipcode = request.form['zipcode'] age = request.form['age'] gender = request.form['gender'] drug_type = request.form['drug_type'] use_duration = request.form['use_duration'] med_insurer = request.form['med_insurer'] year_signed_up = request.form['year_signed_up'] years_from_first_litigation = request.form[ 'years_from_first_litigation'] copay_or_coinsurance = request.form['copay_or_coinsurance'] personal_spending_per_year = request.form[ 'personal_spending_per_year'] income = request.form['income'] if copay_or_coinsurance == 'copay': total_spending = float(personal_spending_per_year) / .11 else: total_spending = float(personal_spending_per_year) / .15 #return total_spending session_user.first_name = first_name session_user.last_name = last_name session_user.state = state session_user.zipcode = zipcode session_user.age = age session_user.gender = gender session_user.drug_type = drug_type session_user.use_duration = use_duration session_user.med_insurer = med_insurer session_user.year_signed_up = year_signed_up session_user.years_from_first_litigation = years_from_first_litigation session_user.copay_or_coinsurance = copay_or_coinsurance session_user.personal_spending_per_year = personal_spending_per_year session_user.total_spending = total_spending session_user.income = income if gender == "M": gender_1hot = np.array([0, 1]) else: gender_1hot = np.array([1, 0]) state_1hot = onehotState(state) years_int = int(years_from_first_litigation) years_1hot = onehotCategorical(years_int, 20) print(state_1hot) #test_pred = np.array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 56361, 305.5437079]) #test_pred = np.hstack([gender_1hot, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], years_1hot, [age, income, total_spending]]) test_pred = np.hstack([ gender_1hot, state_1hot, years_1hot, [age, income, total_spending] ]) #prediction = model.predict(test_pred.reshape(1, -1))*473.5694972 prediction = model.predict(test_pred.reshape(1, -1)) * total_spending session_user.est_settle = float(np.squeeze(prediction.round(2))) #settle = "$" + str(np.squeeze(prediction.round(2))) db.session.commit() #return redirect('/index') return redirect(url_for('profile', username=session_user.username))