コード例 #1
0
def main_teacher():
    tid = flask.session['id']
    if request.method == 'GET':
        index = index_model.Index(tid)
        if (not index.is_teacher()):
            return render_template('error.html')
    tm = teachers_model.Teachers(tid)
    ssm = sessions_model.Sessions()
    if request.method == 'POST':
        if "close" in request.form.keys():
            cid = request.form["close"]
            ssm.open_session(cid)
            ssm.close_window()
        elif "open" in request.form.keys():
            cid = int(request.form["open"])
            new_seid = ssm.open_session(cid)
            ssm.open_window(new_seid)
            course = courses_model.Courses()
            students = course.get_students_sids(cid)
            for student in students:
                sm = students_model.Students(student['sid'])
                sm.insert_attendance_record(new_seid)
    courses = tm.get_courses_with_session()
    empty = True if len(courses) == 0 else False
    context = dict(data=courses)
    return render_template('main_teacher.html', empty=empty, **context)
コード例 #2
0
 def test_sessions_model_constructor(self):
     ssm = sessions_model.Sessions()
     assert ssm.seid == -1
     assert ssm.window_open == False
     assert ssm.cid == -1
     assert ssm.date == 'blank'
     assert ssm.secret == -1
コード例 #3
0
ファイル: imhere.py プロジェクト: jeb2239/flask_test_heroku
def update_session(seid):
    sm = sessions_model.Sessions(g.conn, seid)
    tm = teachers_model.Teachers(g.conn, flask.session['id'])

    action = request.form['action']
    sid = request.form['sid'] if 'sid' in request.form.keys() else None

    stm = students_model.Students(g.conn, sid)

    if action == 'mark_present':
        stm.insert_attendance_record(seid)

    elif action == 'mark_absent':
        sm.remove_attendance_record(sid)

    elif action == 'approve':
        status = 1
        tm.update_change_request(int(status), int(seid), int(sid))
        stm.insert_attendance_record(seid)

    elif action == 'deny':
        status = 0
        tm.update_change_request(int(status), int(seid), int(sid))

    elif action == 'delete_session':
        sm.delete_session()
        return flask.redirect('/teacher/')

    session = sm.get_session()[0]
    attendance = sm.get_attendance_record()

    return render_template('session.html',
                           session=session,
                           attendance=attendance)
コード例 #4
0
ファイル: imhere.py プロジェクト: jeb2239/flask_test_heroku
def view_session(seid):
    sm = sessions_model.Sessions(g.conn, seid)
    session = sm.get_session()[0]
    attendance = sm.get_attendance_record()

    return render_template('session.html',
                           session=session,
                           attendance=attendance)
コード例 #5
0
 def test_open_session_with_cid_arg(self):
     self.ds = self.get_client()
     ssm = sessions_model.Sessions()
     ssm.date = str(date.today())
     cid = self.upper_partition_course_entity()['cid']
     seid = ssm.open_session(cid)
     assert ssm.cid == cid
     self.delete_session(seid)
コード例 #6
0
 def test_close_window2(self):
     session = self.upper_partition_session_entity()
     ssm = sessions_model.Sessions()
     ssm.open_session(session['cid'])
     ssm.open_window()
     assert ssm.window_open == True
     assert ssm.close_window() == False
     assert ssm.window_open == False
     self.delete_session(session['seid'])
コード例 #7
0
 def test_get_current_roster_size(self):
     ssm = sessions_model.Sessions()
     cid = self.upper_partition_course_entity()['cid']
     seid = ssm.open_session(cid)
     assert ssm.get_current_roster_size() == 0
     ds = model.Model().get_client()
     key = ds.key('enrolled_in')
     entity = datastore.Entity(key=key)
     entity.update({'sid': 653, 'cid': cid})
     ds.put(entity)
     assert ssm.get_current_roster_size() == 1
     self.delete_session(seid)
コード例 #8
0
 def test_open_window(self):
     ssm = sessions_model.Sessions()
     cid = self.upper_partition_course_entity()['cid']
     seid = ssm.open_session(cid)
     assert ssm.seid <> -1
     assert ssm.window_open == False
     ssm.open_window()
     assert ssm.open_window() == True
     assert ssm.window_open == True
     self.ds = self.get_client()
     query = self.ds.query(kind='sessions')
     query.add_filter('cid', '=', cid)
     result = list(query.fetch())
     assert result[0]['secret'] <> -1  #opening window changes the secret
     self.delete_session(seid)
コード例 #9
0
def view_class():
    if request.method == 'GET':
        flask.redirect(flask.url_for('main_teacher'))

    elif request.method == 'POST':
        cm = courses_model.Courses()
        ssm = sessions_model.Sessions()

        if 'close' in request.form.keys():
            cid = request.form['close']
            cm.cid = cid
            ssm.open_session(cid)
            ssm.close_window()
        elif 'open' in request.form.keys():
            cid = request.form['open']
            cm.cid = cid
            new_seid = ssm.open_session(cid)
            ssm.open_window(new_seid)
        else:
            cid = request.form['cid']
            cm.cid = cid

        res = 0
        uni = None
        if 'add_student' in request.form.keys():
            for uni in request.form['add_student'].split('\n'):
                uni = uni.strip('\r')
                res = cm.add_student(uni)
        elif 'remove_student' in request.form.keys():
            for uni in request.form['remove_student'].split('\n'):
                uni = uni.strip('\r')
                res = cm.remove_student(uni)
        course_name = cm.get_course_name()

        secret = ssm.get_secret_code()
        num_sessions = cm.get_num_sessions()
        sess = cm.get_sessions()
        ssm2 = sessions_model.Sessions()
        labels = []
        values = []
        for ses in sess:
            denom = float(ssm2.get_current_roster_size(ses['seid']))
            numerator = float(ssm2.get_attendance_count(ses['seid']))
            if(denom == 0):
                values.append(0)
            else:
                values.append((float(numerator/denom))*100)
            labels.append(str(ses['date']))
        students = cm.get_students()
        students_with_ar = []
        for student in students:
            sm = students_model.Students(student['id'])
            student_uni = sm.get_uni()
            num_ar = sm.get_num_attendance_records(cid)
            students_with_ar.append([student, student_uni, num_ar])

        context = dict(students=students_with_ar)
        return render_template(
                'view_class.html',
                cid=cid,
                secret=secret,
                course_name=course_name,
                num_sessions=num_sessions,
                uni=uni,
                res=res,
                labels=labels,
                values=values,
                **context)