Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editing teacher session html file #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
Binary file added __pycache__/run.cpython-311.pyc
Binary file not shown.
Binary file modified instance/site.db
Binary file not shown.
Binary file modified learnlogs/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/data.cpython-311.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/data.cpython-38.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/routes.cpython-311.pyc
Binary file not shown.
Binary file modified learnlogs/__pycache__/routes.cpython-38.pyc
Binary file not shown.
3 changes: 1 addition & 2 deletions learnlogs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def get_by_grade(grade):
total_mark_for_student += mark.mark / mark.full_mark
else:
continue
total_mark_precision = total_mark_for_student/len(all_session) * 100

total_mark_precision = total_mark_for_student/len(all_session) * 100
all_student_data[student.id]=[{'student_name':student.student_name, 'email':student.email,
'grade':student.grade, 'student_phone':student.student_phone,
'parent_phone': student.parent_phone, 'address':student.address,
Expand Down
12 changes: 10 additions & 2 deletions learnlogs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class EnrollForm(FlaskForm):
address = StringField('Address',
validators=[DataRequired()])
photo_link = FileField('Update Profile Picture', validators=[FileAllowed(['jpg', 'png'])])
grade = SelectField('Grade', choices=[('first', 'first'),
('second', 'second'), ('third', 'third')], validators=[InputRequired()])
grade = SelectField('Grade', choices=[('first', 'First'),
('second', 'Second'), ('third', 'Third')], validators=[InputRequired()])

enroll = SubmitField('enroll')
def validate_email(self, email):
Expand All @@ -48,6 +48,14 @@ class Submit_Student_mark(FlaskForm):
students_list = FieldList(FormField(QuizForm),min_entries=1000)
submit = SubmitField('Submit')

class SessionForm(FlaskForm):
title = StringField('Session Title', validators=[DataRequired()])
description = StringField('Description', validators=[DataRequired()])
attachment_link = FileField('Add Attachment', validators=[FileAllowed(['pdf', 'docx', 'pptx'])])
submit = SubmitField('Submit')




# def validate_quiz_mark(self, quiz_mark):
# if self.absent.data == False and self.quiz_mark.data > self.quiz_full_mark.data:
Expand Down
5 changes: 4 additions & 1 deletion learnlogs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Student(db.Model, UserMixin):
parent_name = db.Column(db.String(60), nullable=False)
parent_phone = db.Column(db.String(11), nullable=False)
address = db.Column(db.String(100), nullable=False)
photo_link = db.Column(db.String(100))
photo_link = db.Column(db.String(100), default='default.jpg')
grade = db.Column(db.String(10), nullable=False)
attended = db.relationship('Session', secondary=Student_Session, backref='attended_student')

Expand All @@ -31,6 +31,9 @@ def __repr__(self):

class Session(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
description = db.Column(db.String(1000), nullable=False)
attachment_link = db.Column(db.String(100))
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
grade = db.Column(db.String(10), nullable=False)
students = db.relationship('Student', secondary=Student_Session, backref='sessions')
Expand Down
62 changes: 45 additions & 17 deletions learnlogs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
from PIL import Image
from flask import render_template, url_for, flash, redirect, request, abort
from learnlogs import app, db, bcrypt
from learnlogs.forms import EnrollForm, LoginForm, QuizForm, Submit_Student_mark
from learnlogs.forms import EnrollForm, LoginForm, Submit_Student_mark, SessionForm
from learnlogs.models import Student, Session, Student_Session
from flask_login import login_user, current_user, logout_user, login_required
from learnlogs.data import get_by_grade




@app.route("/")
@app.route("/home")
@app.route("/", methods=['GET', 'POST'])
@app.route("/home", methods=['GET', 'POST'])
def home():
return render_template('home.html')

Expand Down Expand Up @@ -65,10 +63,11 @@ def dashboard():
session_first = len(Session.query.filter_by(grade='first').all())
session_second = len(Session.query.filter_by(grade='second').all())
session_third = len(Session.query.filter_by(grade='third').all())

return render_template('dashboard.html', student_first=student_first,
student_second=student_second, student_third=student_third,
session_first=session_first, session_second=session_second,
session_third=session_third)
session_third=session_third, title='Dashboard')
else :
return "this page is only for teacher", 403
else:
Expand All @@ -82,7 +81,9 @@ def dashboard_grade(grade):
all_data = get_by_grade(grade)
students = Student.query.filter_by(grade=grade).all()
session = Session.query.filter_by(grade=grade).all()
return render_template('dashboard_grade.html', all_students=all_data, students=students, sessions=session)
return render_template('dashboard_grade.html', all_students=all_data,
students=students, sessions=session,
title='dashboard_grade')
else:
return "Unauthorized access", 403
else:
Expand All @@ -99,22 +100,22 @@ def profile(id):
student_marks = db.session.query(Student_Session).filter(Student_Session.c.student_id==id).order_by(Student_Session.c.session_id).all()
if student:
return render_template('student_profile.html', student=student,
marks=student_marks, attended=student_attended, sessions=all_session)
marks=student_marks, attended=student_attended,
sessions=all_session, title='Profile')
else :
return "you can only view your profile", 403
else:
return "you can only view your profile", 403

@login_required
@app.route('/create_session/<string:grade>', methods=['GET', 'POST'])

def create_session(grade):
def evaluate(grade):
if current_user.is_authenticated:
if current_user.email==('[email protected]'):
students = Student.query.filter_by(grade=grade).all()

form = Submit_Student_mark()
new_session = Session(grade=grade)

if form.validate_on_submit():
db.session.add(new_session)
db.session.commit()
Expand All @@ -131,28 +132,55 @@ def create_session(grade):
else:
print("Form validation failed!")
print(form.errors)
return render_template('create_session.html', form=form, session=new_session, students=students)
return render_template('evalute.html', form=form, session=new_session,
students=students, title='create_session')
else:
return "Unauthorized access", 403


@app.route('/session/<string:grade>', methods=['GET', 'POST'])
def create_session(grade):
if current_user.is_authenticated:
if current_user.email==('[email protected]'):
form = SessionForm()
if form.validate_on_submit():
session = Session(title=form.title.data,
description=form.description.data,
attachment_link=form.attachment_link.data,
grade=grade)
db.session.add(session)
db.session.commit()
return redirect(url_for('dashboard_grade', grade=grade))
else:
print("Form validation failed!")
print(form.errors)
return render_template('session_info_form.html', form=form, title='session_info_form')
else:
return "Unauthorized access", 403

@app.route('/session/<int:id>', methods=['GET', 'POST'])
def session_info_for_student(id):
if current_user.is_authenticated:
session = Session.query.filter_by(id=id).first()
return render_template('session_info.html', session=session, title='session_info')
else:
return "Unauthorized access", 403

@login_required
@app.route("/logout")
def logout():
logout_user()
return redirect(url_for('home'))

return redirect(url_for('login'))

def save_picture(form_picture):
random_hex = secrets.token_hex(8)
_, f_ext = os.path.splitext(form_picture.filename)
_, f_ext = os.path.splitext(form_picture.photo_link)
picture_fn = random_hex + f_ext
picture_path = os.path.join(app.root_path, 'static/profile_pics', picture_fn)

output_size = (125, 125)
i = Image.open(form_picture)
i.thumbnail(output_size)
i.save(picture_path)

return picture_fn

"""
Expand Down
Loading