diff --git a/core/report.py b/core/report.py index 0bb133c..e32a7e3 100644 --- a/core/report.py +++ b/core/report.py @@ -9,6 +9,12 @@ class Report: def __init__(self, nested_list: list): + """Report class handles all PDF generation methods and fits the translated list (nested_list) + into line by line inputs. Student name and app types are also captured for later storing methods. + + :param nested_list: translated nested list of inputs such as: strings and lists + :type nested_list: list + """ self.nested_list = nested_list self.student_name = [] @@ -24,6 +30,10 @@ def __init__(self, nested_list: list): self.font_size = 7 def capture_student_name(self) -> None: + """Method for capturing the student names from the given nested list. Locates the start of student information + ['Student Contact:'] and captures the next several lines in the list until it reaches an indicator to stop + ['Nickname', 'Place of Birth', ...] + """ name = '' @@ -36,15 +46,21 @@ def capture_student_name(self) -> None: if student_check == 1 and str(item).startswith(tuple(['First', 'Middle', 'Last', 'Initial','Suffix'])): colon_idx = item.find(':') # Find the position of the colon input = item[colon_idx + 2:] # Extract the part after the colon, +2 to skip the colon and the space after it - name += f'{input}_' # Add an underscore before each new item + if str(item).startswith('Last'): + name += f'{input}, ' # Add a comma after the last name for each new item + else: + name += f'{input} ' elif student_check == 1 and str(item).startswith(tuple(['Nickname', 'Place of Birth', 'Date of Birth'])): - name += str(idx) + # name += str(idx) self.student_name.append(name) name = '' student_check = 0 def capture_app_type(self) -> None: + """Method for capturing the app types from the given nested list. Locates the start of app information + ['App ID'] and captures the portion of the list after a certain indicator '|' + """ for idx, app in enumerate(self.nested_list): for item in app: @@ -53,6 +69,14 @@ def capture_app_type(self) -> None: self.app_type.append(app_type[-1]) def fit_student_data(self, app_data: list) -> list: + """Method for fitting the nested lists data of list and strings into a coherent list of strings. + Ex: list = ['input1', 'input2', ['input3', 'input4', ''], 'input5'] -> list = ['input1', 'input2','input3', 'input4', '', 'input5'] + + :param app_data: selected nested list + :type app_data: list + :return: decoupled nested list + :rtype: list + """ _list = [] @@ -68,6 +92,14 @@ def fit_student_data(self, app_data: list) -> list: return _list def find_total_pages(self, _list: list) -> int: + """Method to find the total number of pages needed to be used to display all of the student's app data. Divides by + 65 lines to determine when to cutoff each list of data. + + :param _list: selected list + :type _list: list + :return: number of pages + :rtype: int + """ if len(_list)/65 > round(len(_list)/65): return round(len(_list)/65)+1 @@ -75,6 +107,18 @@ def find_total_pages(self, _list: list) -> int: return round(len(_list)/65) def create_page_structure(self, folder: str, file_name: str, _list: list, idx: int) -> None: + """Method that handles the creation of pdf pages and storage. Creates pdf objects based on the number of pages + needed and feeds the current list of data through the generate_pdf_page method to write each input line by line. + + :param folder: current folder path + :type folder: str + :param file_name: name of selected spe file + :type file_name: str + :param _list: selected list of data + :type _list: list + :param idx: current nested list idx + :type idx: int + """ current_dir = os.getcwd() pdf_pages = self.find_total_pages(_list) @@ -100,6 +144,16 @@ def create_page_structure(self, folder: str, file_name: str, _list: list, idx: canvas.save() def generate_pdf_page(self, canvas: object, _list: list, page_num: int) -> None: + """Nethod for handling all page writing in any given pdf generation. Write line by line and + slices the list of data based on the number of lines able to fit on the self.page_size parameters. + + :param canvas: PDF canvas object + :type canvas: object + :param _list: selected list of data + :type _list: list + :param page_num: current page number + :type page_num: int + """ canvas.setFont(self.font_type, self.font_size) canvas.setPageSize(self.page_size) diff --git a/core/structure.py b/core/structure.py index 327c7bc..5045e1b 100644 --- a/core/structure.py +++ b/core/structure.py @@ -385,8 +385,9 @@ def translate_IN2(self) -> str: self.error_handler('IN2', sep) if len(self.target) != 2: - return f'{sep}: {self.target[-1].upper()}' - + if sep == 'Suffix': + return f'{sep}: {self.target[-1].upper()}' + return f'{sep}: {self.target[-1]}' return def translate_IND(self) -> str: