Пример #1
0
def student_registered_exams():
    if 'email' in session:
        s = Student()
        if s.login(session['email'], session['password']):
            exams = s.registered_exams()
            return render_template('student_registered_exams.html',
                                   exams=exams)
    return '<script>alert("Retry Login!")</script>' + render_template(
        'student_login.html')
Пример #2
0
def student_hall_ticket():
    if 'email' in session:
        email = session['email']
        password = session['password']
        s = Student()
        if s.login(email, password):
            subjects = s.registered_exams()
            file = generate_hall_ticket(email, subjects)
            return send_file(file, attachment_filename="hall_ticket.pdf")
        return redirect(url_for('student_login'))
    return redirect(url_for('home'))
Пример #3
0
def get_task(lesson, tasknum, student_id):
    student = Student.select().where(Student.telegram_id == student_id)
    task = Task.select().where((Task.lyceum_group == student.lyceum_group)
                               & (Task.lesson == lesson)
                               & (Task.number == tasknum))
    if not task:
        add_tasks_from_lesson(lesson)
        return msg
    return msg
Пример #4
0
def student_register():
    if 'email' not in session:
        return redirect(url_for('student_login'))
    if request.method == 'GET':
        exams = get_all_exams()
        return render_template('student_register.html', exams=exams)
    else:
        sub_code = request.form['subject_code']
        s = Student()
        exams = get_all_exams()
        if s.login(session['email'], session['password']):
            if s.register(sub_code):
                return '<script>alert("Successfully Registered!")</script>' + render_template(
                    'student_register.html', exams=exams)
            return '<script>alert("Already Registered!")</script>' + render_template(
                'student_register.html', exams=exams)
        return '<script>alert("Session Expired! Retry Login..")</script>' + render_template(
            'student_login.html')
Пример #5
0
def change_password():
    if request.method == 'GET' and 'email' in session:
        return render_template('change_password.html')
    elif request.method == 'POST':
        s = Student()
        if s.login(session['email'], session['password']):
            pwd = request.form['password']
            new_pwd = request.form['new_password']
            if s.change_password(pwd, new_pwd):
                session['password'] = new_pwd
                exams = s.registered_exams()
                return '<script>alert("Password changed successfully!")</script>' + render_template(
                    'student_home.html', exams=exams)
            return '<script>alert("Wrong Password")</script>' + render_template(
                'change_password.html')
        return '<script>alert("Retry Login")</script>' + render_template(
            'student_login.html')
    else:
        return redirect(url_for("student_login"))
Пример #6
0
def try_login_pass():
    """indexová stránka s přihlášenim + kontrola přihlašovacích údajů
    """
    if request.method == "POST":
        password = request.form["password"]
        Login = request.form["name"]

        if ((Login == "user" and password == "user") or
            (Login == "doc32301" and password == "32301")): # pevně statovení studenti(pro test)
            print ("prihlasen Uživatel")
            session["user"] = Login
            ###DOČASNÉ!!! Vytvoření studenta v databázi, pokud tam již není
            if not exists(o for o in Student if o.login is Login):
                Student(login=Login, jmeno="adm", prijmeni="Das",
                        hash="13213156")
            i = datetime.now()
            p1 = select(o for o in Student if o.login is Login).get()
            Akce(cas=i.strftime('%Y/%m/%d %H:%M:%S'),
                 student=p1)
            select(c for c in Student).show()
            select(c for c in Akce).show()
            return redirect("Main_user")

        elif Login == "admin" and password == "aaaa": # pevně stanovená admin(pro test)
            print ("prihlášen Admin")
            session["user"] = Login
            ### DOČASNÉ!!! Vytvoření admina v databázi, pokud tam již není
            if not exists(o for o in Student if o.login is Login):
                Student(login=Login, jmeno="adasm", prijmeni="Das",
                        hash="13213156")
            i = datetime.now()
            p2 = select(o for o in Student if o.login is Login).get()
            print (p2)
            Akce(cas=i.strftime('%Y/%m/%d %H:%M:%S'), student=p2)
            select(c for c in Student).show()
            select(c for c in Akce).show()
            return redirect("Main_admin")

        else:
            flash("Neplatny Login nebo Heslo")
    citat = (random.choice(codecs.open("static/citaty.txt", 'r', 'UTF-8').readlines())).split('//')
    return render_template("index.html", citat=citat)
Пример #7
0
def student_signup():
    if 'email' in session:
        s = Student()
        if s.login(session['email'], session['password']):
            return render_template('student_home.html')
        return '<script>alert("Retry Login!")</script>' + render_template(
            'student_login.html')
    if request.method == 'GET':
        return render_template('student_signup.html')
    else:
        s = Student()
        roll_no = request.form['roll_no']
        password = request.form['password']
        name = request.form['name']
        email = request.form['email']
        phone = request.form['phone']
        dept = request.form['dept']
        college = request.form['college']
        if s.signup(roll_no, password, name, email, phone, dept, college):
            session['email'] = email
            session['password'] = password
            return '<script>alert("Account Created Successfully!")</script>' + render_template(
                'student_home.html')
        return '<script>alert("Retry Signup!")</script>' + render_template(
            'student_signup.html')
def student_registration(bot, update):
    params = [x.strip(' \t\n') for x in update.message.split('\n')[1:]]
    whois = update.message.from_user
    if len(params):
        bot.send_message(chat_id=update.message.chat_id, text=random.choice(INSTRUCTION))
        return

    student = Student.get(telegram_id=whois.id)
    if student:
        bot.send_message(chat_id=update.message.chat_id, text=random.choice(ALREADY))
        return

    all_kids = Student.filter()
    if params[0] not in [x.fullname for x in all_kids]:
        bot.send_message(chat_id=update.message.chat_id, text=random.choice(NO_SUCH))
        return

    student = Student.get(fullname=params[0]).join(LyceumGroup)
    student.telegram_id = whois.id
    student.approved = False
    send_notification_to_lecturer(bot, whois, student)
    bot.send_message(chat_id=update.message.chat_id, text=random.choice(APPROVE_WAIT))
def students_create(group, *argv):
    created = []
    for name in argv:
        student = Student()
        student.fullname = name
        student.lyceum_group = group
        student.save()
        created.append(student.fullname)
    return created
def approve_registration(bot, update):
    if update.message.from_user.id not in CONTRIBUTORS:
        return
    try:
        st_id = update.message.split()[1]
        student = Student.get(str(Student.id) == st_id)
        student.approved = True
        student.save()
        bot.send_message(chat_id=update.message.chat_id,
                         text='Регистрация студента {} подтверждена.'.format(
                             student.fullname))
    except Exception as e:
        bot.send_message(chat_id=update.message.chat_id,
                         text='Подтверждение упало с ошибкой: \n %s' % str(e))
    pass
Пример #11
0
def create_message(update):
    student = Student.select().where((Student.telegram_id == update.message.from_user.id))
    if not student:
        return random.choice(NOT_REGISTERED), False

    if not student.approved:
        return random.choice(WAIT_CHECK), False

    rating = get_common_data_from_web(student.lyceumgroup_id)
    position = find_kid_position(rating, student.fullname)

    message = random.choice(HEADERS).format(student.fullname) + '\n'
    pos = str(position[0]) if position[0] == position[1] else '{}--{}'.format(position[0], position[1])
    message += 'Вы занимате {} позицию из {}, с рейтингом {}\n'.format(pos, len(rating), position[2])
    message += random.choice(POST_WORDS).format(student.fullname)

    return message, True
Пример #12
0
def join(user_id, teacher_id):
    user = User.query.filter_by(id=user_id).first()
    teacher = User.query.filter_by(id=teacher_id).first()
    teachers = User.query.filter_by(role='教师').all()
    new_student = Student(stu_id=user.id,
                          name=user.name,
                          major=user.major,
                          address=user.address,
                          email=user.email,
                          phone=user.phone,
                          user_id=teacher_id)
    if Student.query.filter_by(stu_id=user.id, user_id=teacher_id).all():
        flash('加入失败,你已经是该老师的学生')
    else:
        db.session.add(new_student)
        flash('加入成功')
    return render_template('student.html', user=user, teachers=teachers)
Пример #13
0
def student_unregister():
    if 'email' not in session:
        return redirect(url_for('student_login'))
    if request.method == 'POST':
        sub_code = request.form['subject_code']
        s = Student()
        if s.login(session['email'], session['password']):
            exams = s.registered_exams()
            if s.cancel_exam(sub_code):
                return '<script>alert("Exam Cancelled Successfully!")</script>' + render_template(
                    'student_registered_exams.html',
                    exams=s.registered_exams())
            return '<script>alert("Retry!")</script>' + render_template(
                'student_registered_exams.html', exams=exams)
        return '<script>alert("Session Expired... Retry Login!")</script>' + render_template(
            'student_login.html')
Пример #14
0
def add(id):
    if session.get('user_id') is None or id != session.get('user_id'):
        session['user_id'] = None
        flash("未登录")
        return redirect(url_for('login'))
    user = User.query.filter_by(id=id).first()
    if user.role != '教师':
        abort(400)
    form = AddForm()
    if form.validate_on_submit():
        # 构建新学生并保存
        new_student = Student(stu_id=form.stu_id.data,
                              name=form.name.data,
                              major=form.major.data,
                              address=form.address.data,
                              phone=form.phone.data,
                              email=form.email.data,
                              user_id=id)
        db.session.add(new_student)
        flash("添加成功")
        return redirect('/u/' + str(id) + '/add')
    return render_template('form.html', form=form, user=user)
Пример #15
0
def student_login():
    if 'email' in session:
        s = Student()
        if s.login(session['email'], session['password']):
            return render_template('student_home.html')
        return '<script>alert("Retry Login!")</script>' + render_template(
            'student_login.html')
    if request.method == 'GET':
        return render_template('student_login.html')
    else:
        email = request.form['email']
        pwd = request.form['password']
        stu = Student()
        if stu.login(email, pwd):
            session['email'] = stu.email
            session['password'] = stu.password
            return render_template('student_home.html')
        return '<script>alert("Retry Login!")</script>' + render_template(
            'student_login.html')
Пример #16
0
from database import Database, Session, Student
import datetime as dt

mydb = Database()

stud = Student('*****@*****.**', '1234', 'wilson', 'd', 'temple', 'junior', 'ist')
mydb.addStudent(stud)
stud = Student('*****@*****.**', '1234', 'jack', 'daniels', 'temple', 'senior', 'cs')
mydb.addStudent(stud)
stud = Student('*****@*****.**', '1234', 'hoop', 'farm', 'temple', 'freshman', 'cj')
mydb.addStudent(stud)


sesh = Session('le petit groupe de francais', 'French', 'temple', 3, dt.datetime(2019, 10, 19))
mydb.addSession(sesh)
sesh.addStudent(mydb.studentDict['*****@*****.**'])
sesh.addStudent(mydb.studentDict['*****@*****.**'])

sesh = Session('le grand groupe de francais', 'French', 'temple', 10, dt.datetime(2019, 10, 21))
mydb.addSession(sesh)

sesh = Session('calculus clowns', 'Math', 'temple', 5, dt.datetime(2019, 10, 22))
mydb.addSession(sesh)
sesh.addStudent(mydb.studentDict['*****@*****.**'])

sesh = Session('mighty math hour', 'Math', 'temple', 10, dt.datetime(2019, 10, 19))
mydb.addSession(sesh)

sesh = Session('bio bros', 'Biology', 'temple', 4, dt.datetime(2019, 10, 19))
mydb.addSession(sesh)
Пример #17
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database import Course, Student

# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
engine = create_engine('sqlite:///database.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()

# Insert Courses in course tables
newCourse = Course(title="", semester="")
session.add(newCourse)
session.commit()

# Insert Student in student tables
newStudent = Student(id="")
session.add(newStudent)
session.commit()
session = DBSession()


# Create Dummy user
User1 = User(
    name="Chandu Siddartha",
    email="*****@*****.**",
    picture='https://lh5.googleusercontent.com/-8jCWuoDqb2I'
            '/AAAAAAAAAAI/AAAAAAAAAAc/m0qr01JjGFg/photo.jpg')
session.add(User1)
session.commit()

# Each Student details
student1 = Student(
    user_id = 1,
    name = "Ajay",
    rollno = "164g1a0501",
    gmail = "*****@*****.**",
    phoneno = "987654321")

session.add(student1)
session.commit()

student1 = Student(
    user_id = 1,
    name = "Alekhya",
    rollno = "164g1a0502",
    gmail = "*****@*****.**",
    phoneno = "987654321")

session.add(student1)
session.commit()