def update_user(uid): form = UsersForm() #uid = "Test ID" users = User.query.all() user_up = User.query.filter(User.uid == uid).first() if request.method == 'GET': return render_template('update_user.html', title='Update', uid=uid, users=users, form=form) else: if form.validate_on_submit(): username = request.form['username'] first_name = request.form['first_name'] last_name = request.form['last_name'] prog_lang = request.form['prog_lang'] experience_yr = request.form['experience_yr'] age = request.form['age'] hw1_hrs = request.form['hw1_hrs'] user_up.username = username user_up.first_name = first_name user_up.last_name = last_name user_up.prog_lang = prog_lang user_up.experience_yr = experience_yr user_up.age = age user_up.hw1_hrs = hw1_hrs db.session.commit() return redirect(url_for('index'))
def add_user(): form = UsersForm() if request.method == 'GET': return render_template('add_user.html', form=form) else: if form.validate_on_submit(): first_name = request.form['first_name'] age = request.form['age'] new_user = User(first_name=first_name, age=age) db.session.add(new_user) db.session.commit() return redirect(url_for('index'))
def delete(): form = UsersForm() if request.method == 'GET': return render_template('delete.html', form=form) else: if form.validate_on_submit(): user_id = request.form['user_id'] deluser = User.query.filter_by(user_id=user_id).one() db.session.delete(deluser) db.session.commit() return redirect(url_for('index'))
def index(): form = UsersForm() if form.validate_on_submit(): result = request.form input_selection = result.get('input_type') if input_selection == 'username': user1 = result.get('user1') user2 = result.get('user2') else: user1 = result.get('user1') user1 = user1.split('?')[0].split('/')[-1] user2 = result.get('user2') user2 = user2.split('?')[0].split('/')[-1] return redirect('/result/{}/{}/'.format(user1, user2)) return render_template('userinput.html', form=form)
def user_add(request): if request.method == 'POST': f = UsersForm(request.POST) if f.is_valid(): f.save() users=Users.objects.all() print "*"*99 # return render(request, 'users_manage/user_all.html', {'users':users }) return render_to_response('users_manage/user_all.html', {'users':users }, context_instance=RequestContext(request)) else: f = UsersForm() # An unbound form # return render(request, 'users_manage/user_add.html', {'form':f, }) return render(request, 'users_manage/user_add.html', {'form':f, })
def login(): form = UsersForm() if request.method == 'GET': return render_template('login.html', form=form) else: return render_template("dashboard.html")
def add_user(): form = UsersForm() if request.method == "GET": return render_template('add_user.html', form=form) else: if form.validate_on_submit(): first_name = request.form['first_name'] age = request.form['age'] new_user = User(first_name=first_name, age=age) db.session.add(new_user) db.session.commit() flash('Congrats. New user added: ' + first_name) return redirect(url_for('index')) flash('Invalid input') return render_template('add_user.html')
def add_user(): form = UsersForm() if request.method == 'GET': return render_template('add_user.html', form=form) else: if form.validate_on_submit(): username = request.form['username'] first_name = request.form['first_name'] last_name = request.form['last_name'] prog_lang = request.form.get('prog_lang') experience_yr = request.form['experience_yr'] age = request.form['age'] hw1_hrs = request.form['hw1_hrs'] new_user = Users(username=username, first_name=first_name, last_name=last_name, prog_lang=prog_lang, experience_yr=experience_yr, age=age, hw1_hrs=hw1_hrs) db.session.add(new_user) db.session.commit() return redirect(url_for('index'))
def edit_annotations(trackid): my_annotations = Annotations.query.filter_by(trackid=trackid).first() my_users = Users.query.all() my_techs = Technologies.query.all() my_detects = Detections.query.all() form = AnnotationsForm(obj=my_annotations) form_users = UsersForm(obj=my_users) form_tech = TechForm(obj=my_techs) form_detect = DetectForm(obj=my_detects) if form.validate_on_submit(): try: form.populate_obj(my_annotations) db.session.commit() flash('Saved successfully', 'success') if form_tech.validate_on_submit() or form_detect.validate_on_submit(): current_logged_user = str(current_user.get_id()) current_annotation = int(trackid) tech_tmp1 = [] for i in form_tech.tech_choices.data: tech_tmp1.append(i) tech_tmp = ', '.join(tech_tmp1) # tech_tmp = str(tech_tmp) detect_tmp1 = [] for i in form_detect.detect_choices.data: detect_tmp1.append(i) # detect_tmp = str(detect_tmp) detect_tmp = ', '.join(detect_tmp1) conn = sqlite3.connect('annotations.sqlite') cur = conn.cursor() # Check if already annotated current annotation (trackid) and # if currently logged-in-user already annotated: annotation_already_completed_tmp = cur.execute("select trackannotation from annotated where trackannotation = ?", [current_annotation]) annotation_already_completed_tmp2 = [i for i in annotation_already_completed_tmp] if len(annotation_already_completed_tmp2) != 0: annotation_already_completed = [i for i in annotation_already_completed_tmp2][0][0] else: annotation_already_completed = 0 user_already_annotated_tmp = cur.execute("select trackuser from annotated where trackuser = ? and trackannotation = ?", [current_logged_user,current_annotation]) user_already_annotated_tmp2 = [i for i in user_already_annotated_tmp] if len(user_already_annotated_tmp2) != 0: user_already_annotated = [i for i in user_already_annotated_tmp2][0][0] else: user_already_annotated = 0 if current_logged_user == str(user_already_annotated) and int(annotation_already_completed) == current_annotation: cur.execute('update annotated set tracktech = ? where trackannotation = ? and trackuser = ?', [tech_tmp, current_annotation, current_logged_user]) cur.execute('update annotated set trackdetect = ? where trackannotation = ? and trackuser = ?', [detect_tmp, current_annotation, current_logged_user]) conn.commit() else: cur.execute('insert into annotated (trackannotation,trackuser,tracktech,trackdetect) values (?,?,?,?)', [current_annotation,current_logged_user,tech_tmp,detect_tmp]) conn.commit() except: db.session.rollback() flash('Error update annotation.', 'danger') edit_annotation = Annotations.query.filter_by(trackid=trackid).all() annotated = Annotated.query.filter_by(trackannotation=trackid).all() logged_in_user = current_user.get_id() return render_template('web/edit_annotations.html', form=form, edit_annotation=edit_annotation, logged_in_user=logged_in_user, form_users=form_users, form_tech=form_tech, form_detect=form_detect, annotated=annotated)
def adduser(): if current_user.group != 'admin': abort(401) form = UsersForm() if form.validate_on_submit(): uc = UserController() hashed_pw = generate_password_hash(form.password.data, method='pbkdf2:sha256:260000', salt_length=16) user_data = { 'user': form.username.data, 'group': form.group.data, 'password': hashed_pw } uc.adduser(user_data) return redirect(url_for('users', page_num=1)) return render_template('register.html', form=form)
def edit_user(): form = UsersForm() if request.method == 'GET': my_user = User.query.filter( User.user_id == request.args.get('userId')).first() form.first_name.data = my_user.first_name form.last_name.data = my_user.last_name form.email.data = my_user.email form.age.data = my_user.age return render_template('edit_user.html', form=form, user=my_user) else: if form.validate_on_submit(): updated_user = User.query.filter( User.user_id == request.args.get('userId')).first() updated_user.first_name = request.form['first_name'] updated_user.last_name = request.form['last_name'] updated_user.age = request.form['age'] updated_user.email = request.form['email'] db.session.commit() userslist = User.query.all() return render_template('view_users.html', users=userslist)