def student_add_mac(): form = StudentForm() if form.validate_on_submit(): mac_addresses = form.mac_addresses.data email = form.email.data name = form.name.data if ',' in mac_addresses: mac_addresses_array = mac_addresses.split(',') else: mac_addresses_array = [mac_addresses] for mac_address in mac_addresses_array: if db.session.query( db.exists().where(Student.email == email)).scalar(): student = db.session.query(Student).filter( Student.email == email).first() SID = student.id new_mac = Mac(mac_address=mac_address, student_id=SID) db.session.add(new_mac) db.session.commit() else: new_student = Student(email=email, name=name) db.session.add(new_student) db.session.commit() SID = new_student.id new_mac = Mac(mac_address=mac_address, student_id=SID) db.session.add(new_mac) db.session.commit() flash('Mac Address has been updated!') return redirect(url_for('student_add_mac')) return render_template('studentaddmac.html', title='Student', form=form)
def index(): if Users.query.filter_by(net_id=cas.username).all() == []: abort(403) form = StudentForm(request.form) if form.validate_on_submit(): print(form.searchStudents.data) students = Examrequest.query.all() searchResults = [] for student in students: print( 'ID:{}, STUDENT_ID:{}, STUDENT_NETID:{}, STUDENT_NAME:{}, COURSE_ID:{}, COURSE_NAME:{}, EXAM_TYPE:{}, EXAM_FORMAT:{}, EXAM_TIME:{}, EXAM_CSD_TIME:{}, CSD_CAMPUS:{}, CSD_BUILDING:{}, CSD_ROOM:{}, CSD_SEAT:{}, INSTRUCTOR_NETID:{}, INSTRUCTOR_NAME:{}, INSTRUCTOR_PHONE:{}, INSTRUCTOR_EMAIL:{}, MATERIAL:{}, ACCOMMODATIONS:{}, INSTRUCTOR_NOTES:{}>' .format(student.id, student.student_id, student.student_netid, student.student_name, student.course_id, student.course_name, student.exam_type, student.exam_format, student.exam_time, student.exam_csd_time, student.csd_campus, student.csd_building, student.csd_room, student.csd_seat, student.instructor_netid, student.instructor_name, student.instructor_phone, student.instructor_email, student.material, student.accommodations, student.instructor_notes)) if student.student_name == form.searchStudents.data: searchResults.append(student) return render_template('index.html', form=form, results=searchResults) return render_template('index.html', form=form)
def update(request, sid): student = Student.objects.get(sid = sid) form = StudentForm(request.POST, instance = student) if form.is_valid(): form.save() return redirect('/') return render(request, 'edit.html', {'student' : student})
def saveEditStudent(course_id, student_id): """process edit student form""" form = StudentForm(request.form) student = {} if request.method == 'POST' and form.validate(): student["first_name"] = request.form['first_name'] student["last_name"] = request.form['last_name'] student["year"] = request.form['year'] student["email"] = request.form['email'] student["telephone"] = request.form['telephone'] db_conn = db_pool.getconn() cursor = db_conn.cursor() cursor.execute( f"UPDATE student SET first_name = %s, " f"last_name = %s, year = %s, email = %s, " f"telephone = %s WHERE student_id = %s;", (student['first_name'], student['last_name'], student['year'], student['email'], student['telephone'], student_id)) db_conn.commit() cursor.close() db_pool.putconn(db_conn) return redirect( url_for( 'student', student_id=student_id, course_id=course_id))
def index(): dept_form = DepartmentForm() if dept_form.validate_on_submit(): dept = Departments(dept_name=dept_form.dept_name.data, building=dept_form.building.data, budget=dept_form.budget.data) db.session.add(dept) db.session.commit() return redirect(url_for('index')) departments = Departments.query.all() form = StudentForm() form.dept_name.choices = [(i, i) for i in [ii.dept_name for ii in departments]] if form.validate_on_submit(): student = Students(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, dept_name=form.dept_name.data) db.session.add(student) db.session.commit() return redirect(url_for('index')) students = Students.query.all() return render_template('index.html', title='Home', dept_form=dept_form, form=form, departments=departments, students=students)
def add_details(): user = User.query.get_or_404(current_user.id) if user.student: print('Student exist') form = StudentForm(request.form, obj=user.student) else: print('new student') form = StudentForm(request.form) if request.method == 'POST': student = Student(name=form.name.data, email=form.email.data, phone=form.phone.data, perm_addr=form.perm_addr.data, qualification=form.qualification.data, passout=form.passout.data, stream=form.stream.data, college=form.college.data, tenth_percent=form.tenth_percent.data, plus2_percent=form.plus2_percent.data, degree_percent=form.degree_percent.data, n_backlogs=form.n_backlogs.data, courses=form.courses.data, skills=form.skills.data, hobbies=form.hobbies.data) #print(student.name) if user.student: print("updating") user.student.name = form.name.data user.student.email = student.email user.student.phone = student.phone user.student.perm_addr = student.perm_addr user.student.qualification = student.qualification user.student.passout = student.passout user.student.stream = student.stream user.student.college = student.college user.student.tenth_percent = student.tenth_percent user.student.plus2_percent = student.plus2_percent user.student.degree_percent = student.degree_percent user.student.n_backlogs = student.n_backlogs user.student.courses = student.courses user.student.skills = student.skills user.student.hobbies = student.hobbies else: print("Creating") student.user = user db.session.add(student) db.session.commit() flash('**** Congratulations, your details have been added! ****') return redirect(url_for('index')) elif request.method == 'GET': return render_template('v2student-details.html', title='Add Details', form=form)
def test_form_invalid(): form = StudentForm(data={ 'name': 'jack', 'email': '*****@*****.**', 'department': 'chemistry', }) assert form.is_valid() == False
def update_views(request, id): students = Student.objects.filter(id=id) form = StudentForm(request.POST or None, instance=students) if form.is_valid(): form.save() return redirect("/show") return render(request, 'edit.html', {'students': students})
def save(request): if request.method == 'POST': form = StudentForm(request.POST) if form.is_valid(): try: form.save() return redirect('/home') except: pass return redirect('/create')
def test_deprtmant_entry(): form = StudentForm( data={ 'name': 'andy', 'email': '*****@*****.**', 'department': 'phy', 'enrollment': '2333', }) assert form.is_valid() == False
def test_form_valid(): form = StudentForm( data={ 'name': 'jack', 'email': '*****@*****.**', 'department': 'chemistry', 'enrollment': '2421', 'grade': GradeFactory.create() }) assert form.is_valid()
def add_student(): form = StudentForm() if request.method == 'POST' and form.validate(): student = Students(form.firstname.data.title(), form.lastname.data.title(), form.gender.data, form.id_number.data, form.course.data) if student.exist() is False: student.add() flash("Student Added Successfully with ID number '{}'".format( form.id_number.data), category='success') return redirect(url_for('students')) else: flash("Student Already Exist!", category='danger') return redirect(url_for('add_student')) else: return render_template('add_student.html', form=form)
def delete_page(): result = DAL.read_one(usn=request.get_json()["id"]) if result: form = StudentForm() form.usn.data = result.usn return render_template("delete.html", form=form) return "Error", 404
def addStudent(course_id): "displays add student form" addStudentForm = StudentForm() return render_template( 'addstudent.html', addStudentForm=addStudentForm, course_id=course_id)
def student(): form = StudentForm() # years = ['Freshman', 'Sophomore', 'Junior', 'Senior'] app.logger.info('test') if form.validate_on_submit(): fname = form.firstname.data lname = form.firstname.data year_id = form.year.data db.session.add(Student(first_name=fname, last_name=lname, year_id=int(year_id))) db.session.commit() students = Student.query.all() return render_template('student.html', title='Students', form=form, students=students)
def student_view(request): if request.method == 'POST': sf = StudentForm(request.POST) if sf.is_valid(): sf.save() sf = StudentForm() else: sf = StudentForm() st_data = Student.objects.all() return render(request, 'app/student.html', {'form': sf, 'data': st_data})
def index(): addStudentForm = StudentForm() addAssignmentForm = AssignmentForm() return render_template('gradebook.html', addStudentForm=addStudentForm, addAssignmentForm=addAssignmentForm, students=students, assignments=assignments)
def studentprofile(request): if request.method == "GET": #return the profile page studentid = int(request.session['student_id']) student = Student.objects.get(pk=studentid) form = StudentForm(instance=student) return render(request, 'Studentprofile.html', { 'student': student, 'form': form }) if request.method == "POST": studentid = int(request.session['student_id']) student = Student.objects.get(pk=studentid) form = StudentForm(request.POST or None, instance=student) if form.is_valid(): form.save() allattendce = Attendence.objects.filter(student=student) return HttpResponseRedirect('/studentdetails') else: return render(request, 'Studentprofile.html', { 'student': student, 'form': form, 'error': True })
def addStudent(): addStudentForm = StudentForm() addAssignmentForm = AssignmentForm() if addStudentForm.validate_on_submit(): newstudent = Student(addStudentForm.first.data.strip(), addStudentForm.last.data.strip(), addStudentForm.email.data.strip()) students.append(newstudent) # anything you print here gets printed to your terminal print(newstudent.first, newstudent.last, newstudent.email) return redirect(url_for('index')) return render_template('gradebook.html', addStudentForm=addStudentForm, addAssignmentForm=addAssignmentForm, students=students, assignments=assignments)
def create(request): context = {} template_name = 'index.html' form = StudentForm() context['form'] = form context['show_edit_window'] = True students = Student.objects.all() context['students'] = students return render(request, template_name, context)
def student_create(): if 'username' in session: username = session['username'] if session['role'] == 2: form = StudentForm() if request.method == 'POST': if form.file.data <= 0: flash('El legajo debe ser mayor a cero', 'error') elif form.file.data > 2147483647: flash('El numero de legajo debe ser menor.', 'error') else: estudiante = Student.query.filter_by( file=form.file.data).count() mail = Student.query.filter_by( email=form.email.data).count() is_valid = validate_email(form.email.data) if estudiante > 0: flash('Ya existe un estudiante con el mismo legajo.', 'error') elif mail > 0: flash('Ya existe un estudiante con el mismo email.', 'error') elif not is_valid: flash('El campo "Email" contiene caracteres invalidos', 'error') elif re.match(r"\W", form.surname.data): flash('El campo "Apellido" tiene caracteres invalidos', 'error') elif re.match(r"\W", form.name.data): flash('El campo "Nombre" tiene caracteres invalidos', 'error') elif re.match(r"\W", form.degree.data): flash('El campo "Carrera" tiene caracteres invalidos', 'error') else: student = Student(file=form.file.data, email=form.email.data, surname=form.surname.data, name=form.name.data, degree=form.degree.data) if not student.file or not student.email or not student.surname or not student.name or not student.degree: flash('Debes completar todos los campos.', 'error') else: db.session.add(student) db.session.commit() flash('Estudiante agregado.', 'success') return redirect(url_for('students')) return render_template('student_create.html', title='Crear estudiante', form=form) else: return redirect(url_for('forbidden')) return redirect(url_for('login'))
def student(group_id): """Страничка для отображения студента из группы""" if group_id == 'new': new_student = Student() else: try: group_id = int(group_id) except ValueError: return 'Bad Request', 400 new_student = DB.session.query(Student).filter( Student.id == group_id).one_or_none() if new_student is None: return 'Not Found', 404 form = StudentForm(request.form, obj=new_student) if form.button_delete.data: form.validate() if DB.session.query(AttMark) \ .filter(AttMark.student_id == new_student.id) \ .count() > 0: form.button_delete.errors.append( 'Невозможно удалить студента, у которого есть оценки за аттестации' ) if len(form.button_delete.errors) == 0: DB.session.delete(new_student) DB.session.flush() return redirect(url_for('students')) if form.button_save.data and form.validate(): form.populate_obj(new_student) if new_student.stud_group is not None: new_student.semester = new_student.stud_group.semester new_student.alumnus_year = None new_student.expelled_year = None form = StudentForm(obj=new_student) DB.session.add(new_student) if group_id == 'new': DB.session.flush() # ??? if new_student.id != group_id: return redirect(url_for('student', id=new_student.id)) return render_template('public/student.html', student=new_student, form=form)
def studentform(request): if request.method == "POST": form = StudentForm(request.POST) if form.is_valid(): name = request.POST.get( 'key1') #request.POST.get('key') is to fetch data from server. rn = request.POST.get('key2') cls = request.POST.get('key3') marks = request.POST.get('key4') Student.objects.create(sname=name, srn=rn, sclass=cls, smarks=marks) print(request.POST) return HttpResponseRedirect('/index/') else: form = StudentForm() return render(request, "app/formsvalid.html", {'form': form})
def student_add(request): if request.method == 'POST': form = StudentForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('student')) else: form = StudentForm() context = {'form': form} return render(request, 'appTemp/student/student_add.html', context=context)
def update(request, id): context = {} template_name = 'index.html' request.session['id'] = id student = Student.objects.get(id=id) form = StudentForm(instance=student) context['form'] = form context['show_update_window'] = True students = Student.objects.all() context['students'] = students return render(request, template_name, context)
def update_page(): result = DAL.read_one(usn=request.get_json()["id"]) if result: form = StudentForm() form.usn.data = result.usn form.fname.data = result.fname form.lname.data = result.lname form.email.data = result.email form.gpa.data = result.gpa form.phone.data = result.phone_no return render_template("update.html", form=form) return "Error", 404
def editStudent(first, last, email): # replace this for loop with database query eventually to find unique studentID for i, student in enumerate(students): if student.email == email: studentID = i editStudentForm = StudentForm() return render_template('editstudent.html', editStudentForm=editStudentForm, first=first, last=last, email=email, studentID=studentID)
def create(request): if request.method == 'POST': form = StudentForm(request.POST) form.save() return redirect('/') else: form = StudentForm() return render(request, "create.html", {'form' : form})
def edit_student(student_id): form = StudentForm() db = Students(idNum=student_id) student = db.search('idNum', student_id) if request.method == 'POST' and form.validate(): newId = Students(idNum=form.id_number.data) if(newId.exist() and student_id != form.id_number.data): flash('ID number already taken please choose another ID NUMBER', category='danger') return redirect(url_for('edit_student', student_id=db.idNum)) else: db.update(form.firstname.data, form.lastname.data, form.gender.data, form.id_number.data, form.course.data) flash('Successfully Edited Student', category='success') return redirect(url_for('students')) else: for attribute in student: form.firstname.data = attribute[0] form.lastname.data = attribute[1] form.gender.data = attribute[2] form.id_number.data = attribute[3] form.course.data = attribute[4] return render_template('edit_student.html', form=form)
def add_student(): if current_user.is_authenticated and current_user.clearance == 3: form = StudentForm() form.group.choices = groups_query() if form.validate_on_submit(): student = Student(group_id=form.group.data, full_name=form.firstname.data + ' ' + form.lastname.data) db.session.add(student) db.session.flush() person = Person(first_name=form.firstname.data, last_name=form.lastname.data, student_id=student.id) db.session.add(person) db.session.commit() flash('Uusi oppilas lisätty!') return redirect('/admin/add_student') return render_template('student_management.html', title='Lisää oppilas', form=form) else: flash('Luvaton pääsy!') return redirect('/')