def add_subject(): form = AddSubjectForm() page = request.args.get('page', 1, type=int) admin = Admin.query.filter_by(id=current_user.id).first_or_404() historys = History.query.filter_by(admin=admin).order_by(History.date_created.desc()).paginate(page=page, per_page=5) if form.validate_on_submit(): sub=Subject.query.filter_by(admin=admin,standard=form.standard.data,subject=form.subject.data).first() if sub: flash('Subject already exist in this Standard','warning') else: subject = Subject(subject=form.subject.data, standard=form.standard.data, min_marks=form.min_marks.data, max_marks=form.max_marks.data, institute_subject=form.institute_subject.data, admin=current_user) history = History(name_of_module=f'Added Subject {form.subject.data}', activity='add', admin=current_user) db.session.add(history) db.session.commit() db.session.add(subject) db.session.commit() flash('Subject added successfully', 'success') return redirect(url_for('all_subjects')) return render_template('add-subject.html', title='Add Subject', st1='Subject', st2='Add subject',form=form,historys=historys)
def delete_sport(game_id, student_id): game = GameAndSports.query.get_or_404(game_id) student = Student.query.get_or_404(student_id) if game.student.admin != current_user: flash("Sorry you can't Delete this student", 'danger') return redirect(url_for('all_student')) history = History( name_of_module= f'Deleted Game/sport for Student {game.student.fname} {game.student.lname}', activity='delete', admin=current_user) db.session.add(history) db.session.commit() if game.level == 'Other': student.credit_score -= 5 elif game.level == 'Club Level': student.credit_score -= 10 elif game.level == 'District Level': student.credit_score -= 10 elif game.level == 'State Level': student.credit_score -= 50 elif game.level == 'National Level': student.credit_score -= 100 elif game.level == 'International Level': student.credit_score -= 500 db.session.commit() db.session.delete(game) db.session.commit() flash('Game/Sports successfully Deleted', 'success') return redirect(url_for('student_details', student_id=student.id))
def reset_token(token): if current_user.is_authenticated: logout_user() return redirect(url_for('reset_password')) admin = Admin.verify_reset_token(token) if admin is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') admin.password = hashed_password db.session.commit() login_user(admin) history = History(name_of_module='Password Updated', activity='update', admin=current_user) db.session.add(history) db.session.commit() flash('Your password has been updated, You can now login', 'success') return redirect(url_for('dashboard')) return render_template('reset-password.html', title='Reset Password', form=form)
def subject_update(subject_id): subject = Subject.query.get_or_404(subject_id) page = request.args.get('page', 1, type=int) admin = Admin.query.filter_by(id=current_user.id).first_or_404() historys = History.query.filter_by(admin=admin).order_by(History.date_created.desc()).paginate(page=page, per_page=5) if subject.admin != current_user: flash("Sorry you can't Update this subject",'danger') return redirect(url_for('all_subjects')) form = UpdateSubjectForm() if form.validate_on_submit(): subject.subject = form.subject.data subject.standard = form.standard.data subject.min_marks = form.min_marks.data subject.max_marks = form.max_marks.data subject.institute_subject = form.institute_subject.data db.session.commit() history = History(name_of_module=f'Updated Subject {form.subject.data}', activity='update', admin=current_user) db.session.add(history) db.session.commit() flash('Subject Updated Successfully', 'success') return redirect(url_for('all_subjects')) elif request.method == 'GET': form.subject.data = subject.subject form.standard.data = subject.standard form.max_marks.data = subject.max_marks form.min_marks.data = subject.min_marks form.institute_subject.data = subject.institute_subject return render_template('subject-update.html', title='Subject Update', st1='Subject', st2='Subject Update', form=form,subject=subject,historys=historys)
def logout(): history = History(name_of_module='Logout', activity='logout', admin=current_user) db.session.add(history) db.session.commit() logout_user() return redirect(url_for('home'))
def general_question_update(question_id): que = GeneralQuestion.query.get_or_404(question_id) page = request.args.get('page', 1, type=int) admin = Admin.query.filter_by(id=current_user.id).first_or_404() historys = History.query.filter_by(admin=admin).order_by( History.date_created.desc()).paginate(page=page, per_page=5) if que.student.admin != current_user: flash("Sorry you can't Update this student", 'danger') return redirect(url_for('all_students')) form = AddGeneralQuestionForm() if form.validate_on_submit(): que.no_of_graduate_in_family = form.no_of_graduate_in_family.data que.no_of_siblings = form.no_of_siblings.data que.scholarship = form.scholarship.data que.school_type = form.school_type.data que.type_of_friend_zone = form.type_of_friend_zone.data que.memorizing_power = form.memorizing_power.data que.medical_history = form.medical_history.data que.maths_knowledge = form.maths_knowledge.data que.physics_knowledge = form.physics_knowledge.data que.bio_knowledge = form.bio_knowledge.data que.creative_knowledge = form.creative_knowledge.data que.technology_interest = form.technology_interest.data que.subject_interested = form.subject_interested.data que.level_of_understanding = form.level_of_understanding.data que.behaviour_with_others = form.behaviour_with_others.data db.session.commit() history = History( name_of_module= f'Updated Student question {que.student.fname} {que.student.lname}', activity='update', admin=current_user) db.session.add(history) db.session.commit() flash('Account Updated Successfully', 'success') return redirect(url_for('student_details', student_id=que.student.id)) elif request.method == 'GET': form.no_of_graduate_in_family.data = que.no_of_graduate_in_family form.no_of_siblings.data = que.no_of_siblings form.scholarship.data = que.scholarship form.school_type.data = que.school_type form.type_of_friend_zone.data = que.type_of_friend_zone form.memorizing_power.data = que.memorizing_power form.medical_history.data = que.medical_history form.maths_knowledge.data = que.maths_knowledge form.physics_knowledge.data = que.physics_knowledge form.bio_knowledge.data = que.bio_knowledge form.creative_knowledge.data = que.creative_knowledge form.technology_interest.data = que.technology_interest form.subject_interested.data = que.subject_interested form.level_of_understanding.data = que.level_of_understanding form.level_of_understanding.data = que.level_of_understanding return render_template('general-question.html', title='Account', st1='Account', st2='Account Update', form=form, historys=historys)
def add_student(): form = AddStudentForm() page = request.args.get('page', 1, type=int) admin = Admin.query.filter_by(id=current_user.id).first_or_404() historys = History.query.filter_by(admin=admin).order_by( History.date_created.desc()).paginate(page=page, per_page=5) if form.validate_on_submit(): if form.profile_img.data: picture_file1 = save_picture(form.profile_img.data) img = picture_file1 student = Student(fname=form.fname.data, father_name=form.father_name.data, mother_name=form.mother_name.data, lname=form.lname.data, email=form.email.data, roll_no=form.roll_no.data, father_occupation=form.father_occupation.data, father_income=form.father_income.data, father_phone_no=form.father_phone_no.data, mother_occupation=form.mother_occupation.data, mother_income=form.mother_income.data, mother_phone_no=form.mother_phone_no.data, p_address=form.p_address.data, l_address=form.l_address.data, phone_no=form.phone_no.data, dob=form.dob.data, standard='1st', religion=form.religion.data, caste=form.caste.data, gender=form.gender.data, blood_group=form.blood_group.data, profile_img=img, admin=current_user) history = History( name_of_module= f'Added Student {form.fname.data} {form.lname.data}', activity='add', admin=current_user) db.session.add(history) db.session.commit() db.session.add(student) db.session.commit() flash('Student added successfully', 'success') return redirect(url_for('all_students')) return render_template( 'add-student.html', title=f'{current_user.fname} {current_user.lname} account', st1='Student', st2='Add Student', form=form, historys=historys)
def account_update(): form = AccountUpdateForm() if form.validate_on_submit(): if form.profile_img.data: picture_file1 = save_picture(form.profile_img.data) current_user.profile_img = picture_file1 if form.institution_logo.data: picture_file2 = save_picture(form.institution_logo.data) current_user.institution_logo = picture_file2 current_user.email = form.email.data current_user.status = form.status.data current_user.fname = form.fname.data current_user.mname = form.mname.data current_user.lname = form.lname.data current_user.dob = form.dob.data current_user.institution_name = form.institution_name.data current_user.institution_email = form.institution_email.data current_user.phone_no = form.phone_no.data current_user.institution_address = form.institution_address.data current_user.institution_website_link = form.institution_website_link.data current_user.linkedin_link = form.linkedin_link.data current_user.instagram_link = form.instagram_link.data current_user.facebook_link = form.facebook_link.data db.session.commit() history = History(name_of_module='Account Update', activity='update', admin=current_user) db.session.add(history) db.session.commit() flash('Your Account Updated Successfully', 'success') return redirect(url_for('account_info')) elif request.method == 'GET': form.email.data = current_user.email form.status.data = current_user.status form.fname.data = current_user.fname form.mname.data = current_user.mname form.lname.data = current_user.lname form.dob.data = current_user.dob form.institution_name.data = current_user.institution_name form.institution_email.data = current_user.institution_email form.phone_no.data = current_user.phone_no form.institution_address.data = current_user.institution_address form.institution_website_link.data = current_user.institution_website_link form.linkedin_link.data = current_user.linkedin_link form.instagram_link.data = current_user.instagram_link form.facebook_link.data = current_user.facebook_link return render_template( 'account-update.html', title=f'{current_user.fname} {current_user.lname} account', st1='Account', st2='Account Update', form=form)
def delete_subject(subject_id): subject = Subject.query.get_or_404(subject_id) if subject.admin != current_user: flash("Sorry you can't Delete this subject",'danger') return redirect(url_for('dashboard')) history = History(name_of_module=f'Deleted Subject {subject.subject}', activity='delete', admin=current_user) db.session.add(history) db.session.commit() db.session.delete(subject) db.session.commit() flash('Your subject successfully Deleted', 'success') return redirect(url_for('all_subjects'))
def general_question(student_id): student = Student.query.get_or_404(student_id) que = GeneralQuestion.query.filter_by(student=student).first() page = request.args.get('page', 1, type=int) admin = Admin.query.filter_by(id=current_user.id).first_or_404() historys = History.query.filter_by(admin=admin).order_by( History.date_created.desc()).paginate(page=page, per_page=5) if student.admin != current_user: flash("Sorry you can't add questions for this student", 'danger') return redirect(url_for('all_subjects')) form = AddGeneralQuestionForm() if que: flash('question Already exist', 'warning') return redirect(url_for('student_details', student_id=student.id)) elif form.validate_on_submit(): question = GeneralQuestion( no_of_graduate_in_family=form.no_of_graduate_in_family.data, no_of_siblings=form.no_of_siblings.data, scholarship=form.scholarship.data, school_type=form.school_type.data, type_of_friend_zone=form.type_of_friend_zone.data, memorizing_power=form.memorizing_power.data, medical_history=form.medical_history.data, maths_knowledge=form.maths_knowledge.data, physics_knowledge=form.physics_knowledge.data, bio_knowledge=form.bio_knowledge.data, creative_knowledge=form.creative_knowledge.data, technology_interest=form.technology_interest.data, subject_interested=form.subject_interested.data, level_of_understanding=form.level_of_understanding.data, behaviour_with_others=form.behaviour_with_others.data, student=student) db.session.add(question) db.session.commit() history = History( name_of_module= f'Added Questions for {student.fname} {student.lname}', activity='add', admin=current_user) db.session.add(history) db.session.commit() flash('Subject Updated Successfully', 'success') return redirect(url_for('student_details', student_id=student.id)) return render_template('general-question.html', title='Questions', st1='Student', st2='General Question', form=form, historys=historys)
def login(): form = LoginForm() if form.validate_on_submit(): admin = Admin.query.filter_by(email=form.email.data).first() if admin and bcrypt.check_password_hash(admin.password, form.password.data): login_user(admin) history = History(name_of_module='Login', activity='login', admin=current_user) db.session.add(history) db.session.commit() next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('dashboard')) flash('Unsuccessful login', 'danger') return render_template('login.html', form=form, title='Login')
def delete_exam(exam_id): exam = Exam.query.get_or_404(exam_id) if exam.student.admin != current_user: flash("Sorry you can't Delete this student", 'danger') return redirect(url_for('all_student')) history = History( name_of_module= f'Deleted Exam for Student {exam.student.fname} {exam.student.lname}', activity='delete', admin=current_user) db.session.add(history) db.session.commit() cs = ((int(exam.marks_opt) / int(exam.subject.max_marks)) * 100) / 10 exam.student.credit_score -= cs db.session.commit() db.session.delete(exam) db.session.commit() flash('Your Subject successfully Deleted', 'success') return redirect(url_for('exam_view', student_id=exam.student_id))
def admin_register(): form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') admin = Admin(email=form.email.data, status='Head of Department', password=hashed_password) db.session.add(admin) db.session.commit() login_user(admin) history = History(name_of_module='Registration', activity='register', admin=current_user) db.session.add(history) db.session.commit() flash('Your Account has been created, You can now login', 'success') return redirect(url_for('register2')) return render_template('admin_register.html', form=form, title='Register')
def student_game(student_id): student = Student.query.get_or_404(student_id) if student.admin != current_user: flash("Sorry you can't Update this student", 'danger') return redirect(url_for('all_students')) sports = SportsAndGameForm() if sports.validate_on_submit(): game_and_sports = GameAndSports( name_of_sport=sports.name_of_sport.data, level=sports.level.data, date_of_starting=sports.date_of_starting.data, student=student) history = History( name_of_module= f'Added Sports and game for {student.fname} {student.lname}', activity='add', admin=current_user) db.session.add(history) db.session.commit() db.session.add(game_and_sports) db.session.commit() if sports.level.data == 'Other': student.credit_score += 5 elif sports.level.data == 'Club Level': student.credit_score += 10 elif sports.level.data == 'District Level': student.credit_score += 10 elif sports.level.data == 'State Level': student.credit_score += 50 elif sports.level.data == 'National Level': student.credit_score += 100 elif sports.level.data == 'International Level': student.credit_score += 500 db.session.commit() flash('Sports and Game added successfully', 'success') return redirect(url_for('student_details', student_id=student.id))
def register2(): form = RegistrationForm2() if form.validate_on_submit(): current_user.fname = form.fname.data current_user.mname = form.mname.data current_user.lname = form.lname.data current_user.dob = form.dob.data current_user.institution_name = form.institution_name.data current_user.institution_email = form.institution_email.data current_user.phone_no = form.phone_no.data current_user.institution_address = form.institution_address.data current_user.institution_website_link = form.institution_website_link.data current_user.linkedin_link = form.linkedin_link.data current_user.instagram_link = form.instagram_link.data current_user.facebook_link = form.facebook_link.data db.session.commit() history = History(name_of_module='2 step Registration', activity='register', admin=current_user) db.session.add(history) db.session.commit() logout_user() return redirect(url_for('login')) return render_template('register2.html', form=form, title='Step two')
def student_details(student_id): student = Student.query.get_or_404(student_id) que = GeneralQuestion.query.filter_by(student=student).first() admin = Admin.query.filter_by(id=current_user.id).first_or_404() exams = Exam.query.filter_by(student=student, standard=student.standard) subjects = Subject.query.filter_by(admin=admin).all() games = GameAndSports.query.filter_by(student=student) subjects1 = Subject.query.filter_by(admin=admin, standard=student.standard).all() e = [] for exam in exams: e.append(exam.subject.subject) e.sort() s = [] for subject2 in subjects1: s.append(subject2.subject) s.sort() promote = PromoteStudent() form = AddExamForm() sports = SportsAndGameForm() form.subject.choices = [ (subject.id, f'{subject.subject}({subject.standard})') for subject in subjects if subject.standard == student.standard ] ######################################################################################################################## # 6th std future prediction exam1 = Exam.query.filter_by(student=student) future_list = [] improvement_list = [] maths = [] english = [] science = [] phy_edu = [] drawing = [] computer = [] if student.standard == '1st': pass else: for m in exam1: if m.subject.subject.lower() == 'maths': maths.append( int((int(m.marks_opt) * 100) / int(m.subject.max_marks))) for eng in exam1: if eng.subject.subject.lower() == 'english': english.append( int((int(eng.marks_opt) * 100) / int(eng.subject.max_marks))) for sci in exam1: if sci.subject.subject.lower() == 'science': science.append( int((int(sci.marks_opt) * 100) / int(sci.subject.max_marks))) for pe in exam1: if pe.subject.subject.lower() == 'physical education': phy_edu.append( int((int(pe.marks_opt) * 100) / int(pe.subject.max_marks))) for draw in exam1: if draw.subject.subject.lower() == 'drawing': drawing.append( int((int(draw.marks_opt) * 100) / int(draw.subject.max_marks))) for comp in exam1: if comp.subject.subject.lower() == 'computer': computer.append( int((int(comp.marks_opt) * 100) / int(comp.subject.max_marks))) maths1 = 0 english1 = 0 science1 = 0 phy_edu1 = 0 drawing1 = 0 computer1 = 0 if maths: maths1 = sum(maths) / len(maths) if english: english1 = sum(english) / len(english) if science: science1 = sum(science) / len(science) if phy_edu: phy_edu1 = sum(phy_edu) / len(phy_edu) if drawing: drawing1 = sum(drawing) / len(drawing) if computer: computer1 = sum(computer) / len(computer) if int(que.bio_knowledge) <= 3: if maths1 >= 75: if science1 >= 60: if computer1 >= 70: future_list.append('ICT') if int(que.technology_interest) >= 4: if english1 >= 60: future_list.append('Programming') else: if english: improvement_list.append('Improve English') else: improvement_list.append('Need Technology Interest') else: if computer: improvement_list.append( 'Improve Computer Knowledge') else: if science: improvement_list.append('Improve Science') else: if maths: improvement_list.append('Improve Mathematics') if int(que.bio_knowledge) >= 4: if int(que.level_of_understanding) >= 4: if maths1 <= 60: if int(que.maths_knowledge) < 3: if int(que.medical_history) < 4: if int(que.memorizing_power) < 4: if science1 >= 80: future_list.append('Botany') else: if science: if 'Improve Science' not in improvement_list: improvement_list.append( 'Improve Science') else: improvement_list.append( 'Improve Memorizing Power') else: improvement_list.append('Improve Medical History') elif science1 >= 70: if computer1 >= 70: future_list.append('ICT') if int(que.technology_interest) >= 4: if english1 >= 60: if 'Programing' not in future_list: future_list.append('Programming') else: if english: if 'Improve English' not in future_list: improvement_list.append( 'Improve English') else: if 'Need Technology Interest' not in future_list: improvement_list.append( 'Need Technology Interest') else: if computer: if 'Improve Computer Knowledge' not in future_list: improvement_list.append( 'Improve Computer Knowledge') else: if science: if 'Improve Science' not in future_list: improvement_list.append('Improve Science') else: if 'Improve Understanding Level' not in future_list: improvement_list.append('Improve Understanding Level') else: if 'Programming' not in future_list: improvement_list.append('Biology Interest') if int(que.creative_knowledge) >= 3: if int(que.bio_knowledge) <= 4: future_list.append('Artist') else: if "Botany" not in future_list: improvement_list.append('Improve Creativity') if drawing1 >= 70: future_list.append('Painting') if games: if phy_edu1 >= 65: if (int(student.father_income) + int(student.mother_income)) >= 85000: for game in games: future_list.append(game.name_of_sport) if english1 >= 65: if que.subject_interested == "English": future_list.append('Writer') else: if english: if 'Improve English' not in improvement_list: improvement_list.append('Improve English') if science1 >= 75: pass else: if science: if 'Improve Science' not in improvement_list: improvement_list.append('Improve Science') if maths1 >= 75: pass else: if maths: if 'Improve Mathematics' not in improvement_list: improvement_list.append('Improve Mathematics') if int(que.creative_knowledge) >= 3: if (int(student.father_income) + int(student.mother_income)) >= 100000: future_list.append('Music') if (int(student.father_income) + int(student.mother_income)) >= 200000: future_list.append('Dance') #################################################################################################################### if student.admin != current_user: flash("Sorry you can't view this student", 'danger') return redirect(url_for('all_students')) if form.validate_on_submit(): sub = Subject.query.get(form.subject.data) subj = Exam.query.filter_by(student=student, standard=student.standard, subject=sub).first() if subj: flash( "Sorry Student already have this subject, If You need to add new marks delete The subject and retry", 'warning') elif int(form.marks_opt.data) > int(sub.max_marks): flash('invalid data', 'warning') else: exam = Exam(subject=sub, exam_name=f'{student.standard} Exam', marks_opt=form.marks_opt.data, standard=f'{student.standard}', institution_name=form.institution_name.data, subjects=[sub], student=student) history = History( name_of_module= f'Added exam for {student.fname} {student.lname}', activity='add', admin=current_user) db.session.add(history) db.session.commit() db.session.add(exam) db.session.commit() cs = ((int(form.marks_opt.data) / int(sub.max_marks)) * 100) / 10 student.credit_score += cs db.session.commit() flash('Student Exam added successfully', 'success') return redirect(url_for('exam_view', student_id=student.id)) elif promote.validate_on_submit(): if student.standard == '1st': student.standard = '2nd' elif student.standard == '2nd': student.standard = '3rd' elif student.standard == '3rd': student.standard = '4th' elif student.standard == '4th': student.standard = '5th' elif student.standard == '5th': student.standard = '6th' elif student.standard == '6th': student.standard = '7th' elif student.standard == '7th': student.standard = '8th' elif student.standard == '8th': student.standard = '9th' elif student.standard == '9th': student.standard = '10th' db.session.commit() history = History( name_of_module=f'{student.fname} {student.lname} student promoted', activity='update', admin=current_user) db.session.add(history) db.session.commit() flash('Student Promoted successfully', 'success') return redirect(url_for('student_details', student_id=student.id)) return render_template('account-info.html', title='account', st1='Account', st2='Student Account Info', student=student, form=form, subjects=subjects, exams=exams, e=e, s=s, promote=promote, que=que, sports=sports, games=games, future_list=future_list, improvement_list=improvement_list)
def student_update(student_id): student = Student.query.get_or_404(student_id) if student.admin != current_user: flash("Sorry you can't Update this student", 'danger') return redirect(url_for('all_students')) form = UpdateStudentForm() if form.validate_on_submit(): if form.profile_img.data: picture_file1 = save_picture(form.profile_img.data) student.profile_img = picture_file1 student.fname = form.fname.data student.father_name = form.father_name.data student.mother_name = form.mother_name.data student.lname = form.lname.data student.email = form.email.data student.roll_no = form.roll_no.data student.father_occupation = form.father_occupation.data student.mother_occupation = form.mother_occupation.data student.father_income = form.father_income.data student.mother_income = form.mother_income.data student.father_phone_no = form.father_phone_no.data student.mother_phone_no = form.mother_phone_no.data student.l_address = form.l_address.data student.p_address = form.p_address.data student.phone_no = form.phone_no.data student.dob = form.dob.data student.religion = form.religion.data student.caste = form.caste.data student.gender = form.gender.data student.blood_group = form.blood_group.data db.session.commit() history = History( name_of_module= f'Updated Student {form.fname.data} {form.lname.data}', activity='update', admin=current_user) db.session.add(history) db.session.commit() flash('Account Updated Successfully', 'success') return redirect(url_for('student_details', student_id=student.id)) elif request.method == 'GET': form.fname.data = student.fname form.father_name.data = student.father_name form.mother_name.data = student.mother_name form.lname.data = student.lname form.email.data = student.email form.roll_no.data = student.roll_no form.father_occupation.data = student.father_occupation form.mother_occupation.data = student.mother_occupation form.father_income.data = student.father_income form.mother_income.data = student.mother_income form.father_phone_no.data = student.father_phone_no form.mother_phone_no.data = student.mother_phone_no form.p_address.data = student.p_address form.l_address.data = student.l_address form.phone_no.data = student.phone_no form.dob.data = student.dob form.religion.data = student.religion form.caste.data = student.caste form.gender.data = student.gender form.blood_group.data = student.blood_group return render_template('student-account-update.html', title='Account', st1='Account', st2='Account Update', form=form)