Beispiel #1
0
def set_attendance(course_id, excel_file):
    book = None
    try:
        book = openpyxl.load_workbook(excel_file)
    except:
        raise ExtensionException(excel_file)
    sheet = book.active

    p_file = get_attendance(course_id)
    p_book = openpyxl.load_workbook(p_file)
    h_p_sheet = p_book['Hidden']
    p_sheet = p_book.active

    course = CourseDB.get_course(course_id)
    cw_count = len(course['cw_numbers'])
    u_count = len(course['participants'])

    for i in range(4, 4 + u_count):
        for j in range(2, 2 + cw_count):
            if str(sheet.cell(i, j).value) != '0' or str(
                    sheet.cell(i, j).value) != '1':
                p_book.close()
                book.close()
                raise CellValueException(
                    i, j, '{0} must be replaced with 0 or 1.'.format(
                        sheet.cell(i, j).value))
            if str(sheet.cell(i, j).value) != str(p_sheet.cell(i, j).value):
                u_id = h_p_sheet.cell(i, 1).value
                cw_id = h_p_sheet.cell(3, j).value
                CourseDB.set_attendance(course_id, cw_id, u_id, 'value',
                                        str(sheet.cell(i, j).value))
    p_book.close()
    book.close()
Beispiel #2
0
 def value(self, value):
     CourseDB.set_attendance(self.__course_id, self.__cw_number,
                             self.__user_id, 'value', value)