示例#1
0
def build_student_submission(student_id, task_id):
    res = db.select_columns(
        'submissions', ['name', 'path', 'text', 'date_modified', 'status'],
        ['student', 'task'], [student_id, task_id])
    # Account for no submission and a text based submission (no path)
    if not res:
        return {}
    submission = {
        'name': res[0][0],
        'date_modified': timestamp_to_string(res[0][3], True),
        'status': {
            'id': res[0][4]
        },
        'file': None,
        'text': None
    }

    task = build_task(task_id)
    if 'file' in task['sub_method']['name']:
        submission['file'] = FileUpload(filename=res[0][1])
    else:
        submission['text'] = res[0][2]

    res = db.select_columns('request_statuses', ['name'], ['id'],
                            [submission['status']['id']])
    submission['status']['name'] = res[0][0]
    if 'approval' in task['mark_method']['name']:
        submission['mark_method'] = 'approval'
    else:
        submission['mark_method'] = 'mark'
    return submission
示例#2
0
def view_submission():
    student_id = request.args.get('submissions', None, type=int)
    if student_id is None:
        abort(400)
    db.connect()
    student_info = db.select_columns('users', ['name', 'email'], ['id'],
                                     [student_id])
    if not len(student_info):
        db.close()
        abort(404)

    # get tasks for this student
    tasks = []
    student_tasks = queries.get_student_submissions(student_id)
    for task in student_tasks:

        submit_date_text = timestamp_to_string(task[4], True)

        file_url = None
        if task[3]:
            file_url = FileUpload(filename=task[3]).get_url()

        status = get_sub_status(student_id, task[0])
        if 'approval' in task[2]:
            tasks.append((task[1], submit_date_text, status, file_url, task[0],
                          student_id))

        else:
            criteria = db.select_columns('task_criteria', ['id', 'max_mark'],
                                         ['task'], [task[0]])

            staff_mark = 0
            total_max_mark = 0
            for c in criteria:
                total_max_mark += c[1]
                mark = db.select_columns('marks', ['mark'],
                                         ['criteria', 'student', 'marker'],
                                         [c[0], student_id, session['id']])
                if len(mark) != 0:
                    staff_mark += mark[0][0]
                else:
                    staff_mark = -1
            if staff_mark <= 0:
                staff_mark = '- '
            tasks.append((task[1], submit_date_text,
                          str(staff_mark) + '/' + str(total_max_mark),
                          file_url, task[0], student_id))

    db.close()
    zid = student_info[0][1].split('@')[0]
    heading = f'Submissions - {student_info[0][0]} ({zid})'
    return render_template('submission_staff.html',
                           heading=heading,
                           title=heading,
                           submissions=tasks)
示例#3
0
def build_task(task_id):
    'Assumes you already have a database connection open'
    res = db.select_columns('tasks', [
        'deadline', 'marking_method', 'visible', 'course_offering',
        'word_limit', 'name', 'description', 'submission_method', 'word_limit',
        'size_limit'
    ], ['id'], [task_id])
    if not res:
        return None

    task = {
        'id': task_id,
        'deadline': res[0][0],
        'pretty_deadline': timestamp_to_string(res[0][0], True),
        'mark_method': {
            'id': res[0][1]
        },
        'sub_method': {
            'id': res[0][7]
        },
        'visible': res[0][2],
        'offering': res[0][3],
        'word_limit': res[0][4],
        'name': res[0][5],
        'description': res[0][6],
        'text_limit': res[0][8],
        'file_limit': res[0][9],
        'attachment': None,
        'accepted_files': queries.get_tasks_accepted_files(task_id)
    }
    res = queries.get_general_task_info(task_id)
    task['course_name'] = res[0][0]

    res = db.select_columns('marking_methods', ['name'], ['id'],
                            [task['mark_method']['id']])
    task['mark_method']['name'] = res[0][0]

    res = db.select_columns('submission_methods', ['name'], ['id'],
                            [task['sub_method']['id']])
    task['sub_method']['name'] = res[0][0]

    res = db.select_columns('task_attachments', ['path'], ['task'], [task_id])
    if res:
        task['attachment'] = FileUpload(filename=res[0][0])
    return task
示例#4
0
def task_info():
    db.connect()
    task_id = request.args.get('task_id', None, type=int)
    if not task_id:
        db.close()
        return abort(400)
    task = build_task(task_id)
    if not task:
        db.close()
        return abort(404)

    students = get_student_statuses(task)
    for s in students:
        if s['submission_date']:
            s['submission_date'] = timestamp_to_string(s['submission_date'])
    db.close()
    students.sort(key=lambda x: zid_sort(x['email']))
    return render_template('task_stats.html',
                           task=task,
                           students=students,
                           heading=f"{task['name']} - Statistics",
                           title=f"{task['name']} - Statistics")
示例#5
0
def manage_course_offerings():

    data = {}
    if request.method == 'POST':
        data = json.loads(request.data)
        if 'table' in data:
            if data['table'] == 'update_account_types':
                db.connect()
                if not re.match(config.EMAIL_FORMAT, data['email']):
                    db.close()
                    return error(f"""Invalid email address<br>
                        {config.EMAIL_FORMAT_ERROR}""")
                update_account_type(data['email'], data['name'],
                                    data['account_type'],
                                    session['current_co'])
                db.close()

            if data['table'] == 'materials':
                db.connect()
                db.update_rows('materials', [data['type']], ['visible'],
                               ['id'], [data['id']])
                db.close()

            if data['table'] == 'tasks':
                db.connect()
                db.update_rows('tasks', [data['type']], ['visible'], ['id'],
                               [data['id']])
                db.close()
        return jsonify({'status': 'ok'})

    co = 1
    if 'current_co' in session:
        co = session['current_co']
    else:
        session['current_co'] = co
        # maybe default to whatever course is in the current session
    db.connect()
    course_offerings = queries.get_course_offering_details()
    co_map, courses, sessions = split_co(course_offerings)
    materials_query = db.select_columns('materials', ['id', 'name', 'visible'],
                                        ['course_offering'], [co])
    materials = []
    for material in materials_query:
        attachments = []
        attachments_query = db.select_columns('material_attachments', ['path'],
                                              ['material'], [material[0]])
        for x in attachments_query:
            attachments.append(FileUpload(filename=x[0]))
        materials.append((material[0], material[1], attachments, material[2]))
    tasks = []
    task_query = db.select_columns('tasks',
                                   ['id', 'name', 'deadline', 'visible'],
                                   ['course_offering'], [co])
    task_ids = []
    task_query.sort(key=lambda x: x[2])
    for task in task_query:
        attachments = []
        attachments_query = db.select_columns('task_attachments', ['path'],
                                              ['task'], [task[0]])
        for x in attachments_query:
            attachments.append(FileUpload(filename=x[0]))

        print_date = timestamp_to_string(task[2])
        tasks.append((task[0], task[1], print_date, attachments, task[3]))
        task_ids.append(task[0])
    enrollments = []
    enrollments_query = queries.get_student_enrollments(co)
    for student in enrollments_query:
        zid = student[2].split('@')[0]
        if student[3] is not None:
            enrollments.append(
                (student[1], zid, student[2], student[3], student[0]))
        else:
            enrollments.append(
                (student[1], zid, student[2], 'No topic', student[0]))

    # for material file upload
    file_types = db.select_columns('file_types', ['name'])
    file_types = list(map(lambda x: x[0], file_types))
    allowed_file_types = ','.join(file_types)
    account_types = get_all_account_types()
    accepted_account_types = [('student', account_types['student']),
                              ('admin', account_types['course_admin'])]
    sessions_list = sessions[co_map[co]['course']]
    enrollments.sort(key=lambda x: zid_sort(x[1]))
    db.close()
    return render_template('manage_courses.html',
                           title='Manage Courses',
                           heading='Manage Courses',
                           materials=materials,
                           tasks=tasks,
                           enrollments=enrollments,
                           courses=courses,
                           sessions=sessions_list,
                           co_map=co_map,
                           default_co=co,
                           max_file_size=config.MAX_FILE_SIZE,
                           accepted_files=allowed_file_types,
                           task_ids=task_ids)