def fill_table_7(template: DocxTemplate, context: Dict[str, Any]) -> None: """ Заполняем таблицу со ссылками на литературу в разделе 7 """ if context['lit_images']: return # вместо таблицы будет скан страницы с печатью def append_table_7_section(caption, books): rows_count = len(table.rows) core.add_table_rows(table, len(books) + 1) # доп. строка для заголовка table.cell(rows_count, 0).merge(table.cell(rows_count, 4)) core.set_cell_text(table, rows_count, 0, core.CENTER, caption) for i, book in enumerate(books): core.set_cell_text(table, rows_count + i + 1, 0, core.CENTER, str(i + 1)) core.set_cell_text(table, rows_count + i + 1, 1, core.CENTER, book['гост']) core.set_cell_text(table, rows_count + i + 1, 2, core.CENTER, book['гриф']) core.set_cell_text(table, rows_count + i + 1, 3, core.CENTER, book['экз']) core.set_cell_text(table, rows_count + i + 1, 4, core.CENTER, book['эбс']) table = template.get_docx().tables[9] append_table_7_section('Основная литература', context['course'].primary_books) append_table_7_section('Дополнительная литература', context['course'].secondary_books) core.fix_table_borders(table)
def fill_table_4(template: DocxTemplate, context: Dict[str, any]) -> None: """ Заполнение бланка "Лист сформированности компетенций" """ plan: EducationPlan = context['plan'] table: Table = template.get_docx().tables[-1] row_number = 0 for competence in sorted(plan.competence_codes.values(), key=Competence.repr): core.add_table_rows(table, 1) row_index = len(table.rows) - 1 row_number += 1 core.set_cell_text(table, row_index, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row_index, 1, core.JUSTIFY, competence.code + ' ' + competence.description) subjects = [plan.subject_codes[s] for s in competence.subjects] for subject in sorted(subjects, key=Subject.repr): core.add_table_rows(table, 1) row_index = len(table.rows) - 1 core.set_cell_text(table, row_index, 1, core.JUSTIFY, subject.code + ' ' + subject.name) core.add_table_rows(table, 1) row_number += 1 row_index = len(table.rows) - 1 core.set_cell_text(table, row_index, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row_index, 1, core.JUSTIFY, 'Практики') core.add_table_rows(table, 1) row_number += 1 row_index = len(table.rows) - 1 core.set_cell_text(table, row_index, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row_index, 1, core.JUSTIFY, 'НИР') core.fix_table_borders(table)
def fill_table_4(template: DocxTemplate, context: Dict[str, Any]) -> None: """ Заполняем таблицу с содержанием СРС в разделе 4 """ themes = context['course'].themes themes_count = len(themes) subject = context['subject'] homeworks = distribute(subject.get_hours('homeworks'), themes_count) table = template.get_docx().tables[5] core.add_table_rows(table, themes_count + 1) # последняя строка - для итога hw_text = "Проработка теоретического материала, подготовка к выполнению лабораторной работы" hw_control = "Вопросы к итоговому тесту" i = 0 for theme in themes: i += 1 core.set_cell_text(table, i, 0, core.CENTER, str(i)) core.set_cell_text(table, i, 1, core.CENTER, theme['тема']) core.set_cell_text(table, i, 2, core.CENTER, hw_text) core.set_cell_text(table, i, 3, core.CENTER, str_or_dash(homeworks[i - 1])) core.set_cell_text(table, i, 4, core.CENTER, hw_control) i += 1 core.set_cell_text(table, i, 1, core.JUSTIFY, 'Всего часов') core.set_cell_text(table, i, 3, core.CENTER, str_or_dash(sum(homeworks))) core.fix_table_borders(table)
def fill_table_3_1(template: DocxTemplate, context: Dict[str, Any]) -> None: """ Заполняем таблицу с содержанием курса в разделе 3.1 """ # Извлекаем названия тем и форматируем для заполнения таблицы course, subject = context['course'], context['subject'] themes = [ 'Тема %d. %s' % (i + 1, t['тема']) for i, t in enumerate(course.themes) ] # Равномерно размазываем часы по темам themes_count = len(themes) lectures = distribute(subject.get_hours('lectures'), themes_count) practices = distribute(subject.get_hours('practices'), themes_count) labworks = distribute(subject.get_hours('labworks'), themes_count) controls = distribute(subject.get_hours('controls'), themes_count) homeworks = distribute(subject.get_hours('homeworks'), themes_count) totals = [ sum(t) for t in zip(lectures, practices, labworks, controls, homeworks) ] # Заполняем таблицу table = template.get_docx().tables[4] core.add_table_rows(table, themes_count + 1) # последняя строка - для итога fill_table_column(table, 2, [0], themes + ['Всего часов']) fill_table_column(table, 2, [1], totals + [subject.get_total_hours()]) fill_table_column(table, 2, [2], lectures + [sum(lectures)]) fill_table_column(table, 2, [4], practices + [sum(practices)]) fill_table_column(table, 2, [6], labworks + [sum(labworks)]) fill_table_column(table, 2, [10], controls + [sum(controls)]) fill_table_column(table, 2, [11], homeworks + [sum(homeworks)]) fill_table_column(table, 2, [3, 5, 7, 8, 9], [0] * (themes_count + 1)) # пустые значения core.fix_table_borders(table)
def fill_table_2_1(template: DocxTemplate, context: Dict[str, any]) -> None: """ Заполнение таблицы в разделе 2.1 """ plan: EducationPlan = context['plan'] table: Table = template.get_docx().tables[3] for subject in sorted(plan.subject_codes.values(), key=Subject.repr): core.add_table_rows(table, 1) row_index = len(table.rows) - 1 core.set_cell_text(table, row_index, 0, core.CENTER, subject.code) core.set_cell_text(table, row_index, 1, core.JUSTIFY, subject.name) core.fix_table_borders(table)
def fill_table_1(template: DocxTemplate, context: Dict[str, any]) -> None: """ Заполнение таблиц с формами контроля """ control_fancy_name = { CT_EXAM: 'Экзамен', CT_CREDIT_GRADE: 'Зачет с оценкой', CT_CREDIT: 'Зачет', CT_COURSEWORK: 'Курсовой проект', } plan: EducationPlan = context['plan'] if plan.degree == core.BACHELOR: core.remove_table(template, 1) elif plan.degree == core.MASTER: core.remove_table(template, 2) table: Table = template.get_docx().tables[1] row_number = 0 for competence in sorted(plan.competence_codes.values(), key=Competence.repr): core.add_table_rows(table, 1) row = len(table.rows) - 1 row_number += 1 core.set_cell_text(table, row, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row, 1, core.JUSTIFY, competence.code + ' ' + competence.description) table.cell(row, 1).merge(table.cell(row, len(table.columns) - 1)) subjects = [plan.subject_codes[s] for s in competence.subjects] for subject in sorted(subjects, key=Subject.repr): core.add_table_rows(table, 1) row = len(table.rows) - 1 row_number += 1 core.set_cell_text(table, row, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row, 1, core.JUSTIFY, subject.code + ' ' + subject.name) for number, semester in subject.semesters.items(): controls = [control_fancy_name[c] for c in semester.control] core.set_cell_text(table, row, number + 1, core.CENTER, ', '.join(controls)) core.fix_table_borders(table)
def fill_table_1_2(template: DocxTemplate, context: Dict[str, Any]) -> None: """ Заполняем таблицу с компетенциями в разделе 1.2 """ table = template.get_docx().tables[1] core.add_table_rows(table, len(context['subject'].competencies)) row = 0 competencies = [ context['plan'].competence_codes[c] for c in context['subject'].competencies ] for competence in sorted(competencies, key=Competence.repr): row += 1 core.set_cell_text(table, row, 0, core.CENTER, competence.category) core.set_cell_text(table, row, 1, core.JUSTIFY, competence.code + ' ' + competence.description) core.set_cell_text(table, row, 4, core.CENTER, context['course'].assessment) for ind_code in sorted(competence.indicator_codes): indicator = competence.indicator_codes[ind_code] core.set_cell_text(table, row, 2, core.JUSTIFY, ind_code + ' ' + indicator.description) def add_study_results(attr: str, caption: str) -> None: """ Добавить в ячейку таблицы результаты обучения """ results = context['course'].__getattribute__(attr) if results: core.set_cell_text(table, 1, 3, core.JUSTIFY, caption) for elem in results: core.set_cell_text(table, 1, 3, 'Table List', '•\t' + elem) table.cell(1, 3).merge(table.cell(row, 3)) add_study_results('knowledge', 'Знать:') add_study_results('abilities', 'Уметь:') add_study_results('skills', 'Владеть:') core.fix_table_borders(table)
def fill_table_1(template: DocxTemplate, context: Dict[str, any]) -> None: """ Заполнение таблиц с формами контроля """ # control_fancy_name = { # core.CT_EXAM: 'Экзамен', # core.CT_CREDIT_GRADE: 'Зачет с оценкой', # core.CT_CREDIT: 'Зачет', # core.CT_COURSEWORK: 'Курсовой проект', # } plan: EducationPlan = context['plan'] if plan.degree == core.BACHELOR: core.remove_table(template, 1) elif plan.degree == core.MASTER: core.remove_table(template, 2) table: Table = template.get_docx().tables[1] row_number = 0 for competence in sorted(plan.competence_codes.values(), key=Competence.repr): core.add_table_rows(table, 1) row = len(table.rows) - 1 row_number += 1 core.set_cell_text(table, row, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row, 1, core.JUSTIFY, competence.code + ' ' + competence.description) for number in range(1, 9 if plan.degree == core.BACHELOR else 5): cell_components = [] subjects = [plan.subject_codes[s] for s in competence.subjects] subjects.sort(key=lambda s: s.code) for subject in subjects: for sem_num, sem_work in subject.semesters.items(): if sem_num == number: if sem_work.control: values = subject.code, subject.name, ', '.join(sem_work.control) cell_components.append('%s %s (%s)' % values) else: values = subject.code, subject.name cell_components.append('%s %s' % values) core.set_cell_text(table, row, number + 1, core.CENTER, '\n'.join(cell_components)) core.fix_table_borders(table) rpd_dict = context['rpd_dict'] table: Table = template.get_docx().tables[2] row_number1 = 0 for competence in sorted(plan.competence_codes.values(), key=Competence.repr): core.add_table_rows(table, 1) row = len(table.rows) - 1 row_number1 += 1 core.set_cell_text(table, row, 0, core.CENTER, str(row_number1)) core.set_cell_text(table, row, 1, core.JUSTIFY, competence.code + ' ' + competence.description) values = ['%s %s' % (k, v.description) for k, v in competence.indicator_codes.items()] core.set_cell_text(table, row, 2, core.JUSTIFY, '\n'.join(values)) row_number2 = 0 subjects = [plan.subject_codes[s] for s in competence.subjects] for subject in subjects: if not subject.code.startswith('Б1'): continue zuv_raw = '' rpd = rpd_dict.get(subject.code) if rpd: zuv = rpd.competences.get(competence.code) if zuv: zuv_raw = zuv.raw core.add_table_rows(table, 1) row = len(table.rows) - 1 row_number2 += 1 core.set_cell_text(table, row, 0, core.CENTER, '%d.%d' % (row_number1, row_number2)) core.set_cell_text(table, row, 1, core.JUSTIFY, subject.code + ' ' + subject.name) core.set_cell_text(table, row, 3, core.JUSTIFY, zuv_raw) core.set_cell_text(table, row, 4, core.JUSTIFY, zuv_raw) core.set_cell_text(table, row, 5, core.JUSTIFY, zuv_raw) core.set_cell_text(table, row, 6, core.JUSTIFY, zuv_raw) core.fix_table_borders(table)
def fill_table_6_1(template: DocxTemplate, context: Dict[str, Any]): """ Заполняем таблицу в разделе 6.1 """ def add_study_results(attr: str, caption: str, row: int, col: int) -> None: """ Добавить в ячейку таблицы результаты обучения """ results = course.__getattribute__(attr) if results: core.set_cell_text(table, row, col, core.JUSTIFY, caption) for elem in results: core.set_cell_text(table, row, col, 'Table List', '•\t' + elem) course, subject = context['course'], context['subject'] # Уровни освоения control = [s.control for s in subject.semesters.values()] control = functools.reduce( lambda x, y: x + y if isinstance(x, list) else set.union(x, y), control) if CT_EXAM in control: levels = [ ('Высокий', 'Отлично'), ('Базовый', 'Хорошо'), ('Минимальный', 'Удовлетворительно'), ('Не освоены', 'Неудовлетворительно'), ] elif CT_CREDIT_GRADE in control: levels = [ ('Высокий', 'Зачтено (отлично)'), ('Базовый', 'Не зачтено (хорошо)'), ('Минимальный', 'Зачтено (удовлетворительно)'), ('Не освоены', 'Не зачтено'), ] else: levels = [('Освоено', 'Зачтено'), ('Не освоено', 'Не зачтено')] # Строки таблицы table = template.get_docx().tables[8] rows_count = len(subject.competencies) * len(levels) core.add_table_rows(table, rows_count) # Компетенции и индикаторы start_row = 2 for code in subject.competencies: competence = context['plan'].competence_codes[code] table.cell(start_row, 0).merge(table.cell(start_row + len(levels) - 1, 0)) core.set_cell_text(table, start_row, 0, core.JUSTIFY, competence.code + ' ' + competence.description) table.cell(start_row, 1).merge(table.cell(start_row + len(levels) - 1, 1)) for ind_code in sorted(competence.indicator_codes): indicator = competence.indicator_codes[ind_code] core.set_cell_text(table, start_row, 1, core.JUSTIFY, ind_code + ' ' + indicator.description) start_row += len(levels) # Знать, уметь, владеть start_row = 2 table.cell(start_row, 2).merge(table.cell(start_row + rows_count - 1, 2)) add_study_results('knowledge', 'Знать:', 2, 2) add_study_results('abilities', 'Уметь:', 2, 2) add_study_results('skills', 'Владеть:', 2, 2) # Уровни освоения start_row = 2 for level, grade in levels: table.cell(start_row, 3).merge( table.cell(start_row + len(subject.competencies) - 1, 3)) core.set_cell_text(table, start_row, 3, core.CENTER, level) table.cell(start_row, 4).merge( table.cell(start_row + len(subject.competencies) - 1, 4)) if CT_CREDIT in control: if level == 'Освоено': add_study_results('knowledge', 'Обучаемый знает:', start_row, 4) add_study_results('abilities', 'Обучаемый умеет:', start_row, 4) add_study_results('skills', 'Обучаемый владеет:', start_row, 4) else: add_study_results('knowledge', 'Обучаемый не знает:', start_row, 4) add_study_results('abilities', 'Обучаемый не умеет:', start_row, 4) add_study_results('skills', 'Обучаемый не владеет:', start_row, 4) else: if level == 'Высокий': add_study_results('knowledge', 'Обучаемый знает:', start_row, 4) add_study_results('abilities', 'Обучаемый умеет:', start_row, 4) add_study_results('skills', 'Обучаемый владеет:', start_row, 4) elif level == 'Базовый': add_study_results('knowledge', 'Обучаемый знает:', start_row, 4) add_study_results('abilities', 'Обучаемый не умеет:', start_row, 4) add_study_results('skills', 'Обучаемый владеет:', start_row, 4) elif level == 'Минимальный': add_study_results('knowledge', 'Обучаемый не знает:', start_row, 4) add_study_results('abilities', 'Обучаемый не умеет:', start_row, 4) add_study_results('skills', 'Обучаемый владеет:', start_row, 4) else: add_study_results('knowledge', 'Обучаемый не знает:', start_row, 4) add_study_results('abilities', 'Обучаемый не умеет:', start_row, 4) add_study_results('skills', 'Обучаемый не владеет:', start_row, 4) table.cell(start_row, 5).merge( table.cell(start_row + len(subject.competencies) - 1, 5)) core.set_cell_text(table, start_row, 5, core.CENTER, grade) start_row += len(subject.competencies) core.fix_table_borders(table)
def fill_table_2(template: DocxTemplate, context: Dict[str, any]) -> None: """ Заполнение таблиц с формами контроля """ global fileslist control_fancy_name = { CT_EXAM: 'Экзамен', CT_CREDIT_GRADE: 'Зачет с оценкой', CT_CREDIT: 'Зачет', CT_COURSEWORK: 'Курсовой проект', } plan: EducationPlan = context['plan'] table: Table = template.get_docx().tables[2] fileslist = [ filename[:-5] for filename in os.listdir('./rpds') if filename.endswith('.docx') ] row_number = 0 for competence in sorted(plan.competence_codes.values(), key=Competence.repr): core.add_table_rows(table, 1) row = len(table.rows) - 1 row_number += 1 core.set_cell_text(table, row, 0, core.CENTER, str(row_number)) core.set_cell_text(table, row, 1, core.JUSTIFY, competence.code + ' ' + competence.description) for runover in range(2, 8): core.set_cell_text(table, row, runover, core.JUSTIFY, ' ') # table.cell(row, 1).merge(table.cell(row, len(table.columns) - 1)) subjects = [plan.subject_codes[s] for s in competence.subjects] for subject in sorted(subjects, key=Subject.repr): # core.add_table_rows(table, 1) # row = len(table.rows) - 1 # len(table.rows) - 1 # row_number += 1 controls = [] for number, semester in subject.semesters.items(): controls += [control_fancy_name[c] for c in semester.control] sem = 0 for control in controls: core.add_table_rows(table, 1) row = len(table.rows) - 1 zuv_criteria = find_rpd(subject.code, subject.name, control, controls, sem) sem += 1 if len(zuv_criteria) == 6: core.set_cell_text(table, row, 0, core.CENTER, ' ') core.set_cell_text(table, row, 1, core.JUSTIFY, subject.code + ' ' + subject.name) core.set_cell_text(table, row, 2, core.JUSTIFY, zuv_criteria[0]) if control == 'Зачет': core.set_cell_text(table, row, 3, core.JUSTIFY, zuv_criteria[1]) core.set_cell_text(table, row, 4, core.JUSTIFY, ' ') core.set_cell_text(table, row, 5, core.JUSTIFY, ' ') core.set_cell_text(table, row, 6, core.JUSTIFY, zuv_criteria[4]) table.cell(row, 3).merge(table.cell(row, 5)) else: core.set_cell_text(table, row, 3, core.JUSTIFY, zuv_criteria[1]) core.set_cell_text(table, row, 4, core.JUSTIFY, zuv_criteria[2]) core.set_cell_text(table, row, 5, core.JUSTIFY, zuv_criteria[3]) core.set_cell_text(table, row, 6, core.JUSTIFY, zuv_criteria[4]) core.set_cell_text(table, row, 7, core.JUSTIFY, zuv_criteria[5]) core.fix_table_borders(table)