diff --git a/app/main/checks/report_checks/main_character_check.py b/app/main/checks/report_checks/main_character_check.py
index ea34361f..69f3b745 100644
--- a/app/main/checks/report_checks/main_character_check.py
+++ b/app/main/checks/report_checks/main_character_check.py
@@ -1,6 +1,8 @@
from ..base_check import BaseReportCriterion, answer
from .main_page_settings import ReportMainPageSetting
import re
+import copy
+
class ReportMainCharacterCheck(BaseReportCriterion):
label = "Проверка составляющих титульного листа, задания и календарного плана"
@@ -11,19 +13,18 @@ class ReportMainCharacterCheck(BaseReportCriterion):
def __init__(self, file_info):
super().__init__(file_info)
self.headers = []
- self.first_check_list = ReportMainPageSetting.FIRST_TABLE
- self.second_check_list = ReportMainPageSetting.SECOND_TABLE
+ self.first_check_list = None
+ self.second_check_list = None
self.tables_count_to_verify = 8
-
def late_init(self):
self.headers = self.file.make_headers(self.file_type['report_type'])
def check(self):
+ self.first_check_list = copy.deepcopy(ReportMainPageSetting.FIRST_TABLE)
+ self.second_check_list = copy.deepcopy(ReportMainPageSetting.SECOND_TABLE)
if self.file.page_counter() < 4:
return answer(False, "В отчете недостаточно страниц. Нечего проверять.")
- if len(self.file.styled_paragraphs) == 0:
- self.file.parse()
if self.tables_count_to_verify > len(self.file.tables):
return answer(False, f"Количество таблиц на страницах титульного листа, задания и календарного плана должно быть не меньше {self.tables_count_to_verify}")
self.late_init()
@@ -34,9 +35,6 @@ def check(self):
pages.append(header["page"])
for i in range(self.tables_count_to_verify):
table = self.file.tables[i]
- print("table",table)
- print(type(table))
- print(table.__dict__)
extract_table = self.extract_table_contents(table)
self.check_table(self.first_check_list, extract_table)
self.check_table(self.second_check_list, extract_table)
@@ -45,7 +43,7 @@ def check(self):
if res["found_key"] > 1 and res["key"] == "Консультант":
links = self.format_page_link(pages[1:])
result_str += f"На страницах {links} не нужно указывать консультантов.
"
- elif res["found_key"] < res["find"]:
+ elif res["found_key"] < res["find"] and res["key"] != "Консультант":
result_str += f"Поле '{res['key']}' не найдено на страницах {links}. Его удалось обнаружить {res['found_key']} из {res['find']} раз. Проверьте корректность всех вхождений.
"
elif res["found_value"] < res["find"]:
links = self.format_page_link(pages)
@@ -59,15 +57,16 @@ def check(self):
return answer(False, result_str)
def extract_table_contents(self, table):
- collected_table = []
- for cell in table.table_cells:
- collected_line = []
- for item in cell:
- if item.cell_text not in collected_line:
- collected_line.append(item.cell_text)
- collected_table.append(' '.join(collected_line))
- print("УСпех"*10)
- return collected_table
+ contents = []
+ processed_cells = set()
+ for row in table.rows:
+ row_text = []
+ for cell in row.cells:
+ if cell not in processed_cells:
+ row_text.append(cell.text.strip())
+ processed_cells.add(cell)
+ contents.append(' '.join(row_text))
+ return contents
def calculate_find_value(self, table, index):
count = int((len(table) - index - 2) / 2)
@@ -81,7 +80,7 @@ def check_table(self, check_list, table):
for i, line in enumerate(table):
if item["key"] in line:
flag = True
- item["found_key"]+=1
+ item["found_key"] += 1
if item["key"] == "Консультант":
if item["found_key"] == 1:
item["find"] += self.calculate_find_value(table, i)
@@ -91,6 +90,6 @@ def check_table(self, check_list, table):
for value in item["value"]:
if re.search(value, line):
item["found_value"] += 1
- if item["key"] != "Консультант":
- flag = False
- break
\ No newline at end of file
+ break
+ if item["key"] != "Зав. кафедрой" and item["key"] != "Консультант":
+ flag = False
\ No newline at end of file