From bb6f6182d2be4e28f999afa6c9608f20c2b643ab Mon Sep 17 00:00:00 2001 From: aldo Date: Wed, 11 Dec 2024 12:54:32 -0600 Subject: [PATCH 1/3] bulk upload can now handle one observer --- BackEndFlask/Functions/teamBulkUpload.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/BackEndFlask/Functions/teamBulkUpload.py b/BackEndFlask/Functions/teamBulkUpload.py index cf93356c7..d09b8e127 100755 --- a/BackEndFlask/Functions/teamBulkUpload.py +++ b/BackEndFlask/Functions/teamBulkUpload.py @@ -35,14 +35,14 @@ def __expect(lst: list[list[str]], cols: int | None = None) -> list[str]: will modify the original list passed. """ hd: list[str] = lst.pop(0) - + # Clean the row - specifically handle 'Unnamed:' columns and empty strings cleaned = [] for x in hd: stripped = x.strip() if stripped and not stripped.startswith('Unnamed:'): cleaned.append(stripped) - + if cols is not None and len(cleaned) != cols: raise TooManyColumns(1, cols, len(cleaned)) return cleaned @@ -71,7 +71,16 @@ def __parse(lst: list[list[str]]) -> list[TBUTeam]: raise EmptyTeamName if team_name == "" else EmptyTAEmail teams.append(TBUTeam(team_name, ta, students)) students = [] - current_state = EXPECT_TA + + multiple_observers = True + if len(lst) > 2: + hd = __expect(lst) + lookAhead = __expect(lst) + lst.insert(0, lookAhead) + lst.insert(0, hd) + multiple_observers = len(hd) == len(lookAhead) == 1 + + current_state = EXPECT_TA if multiple_observers else EXPECT_TEAM continue # Process based on what type of row we're expecting From fab9319d1705b76bef515e0a2805821cddc9aa3b Mon Sep 17 00:00:00 2001 From: aldo Date: Wed, 11 Dec 2024 19:01:34 -0600 Subject: [PATCH 2/3] Fixed the TeamUser duplicaiton that team bulk upload was doing.Needs a bit of testing then should be good for a pr --- BackEndFlask/Functions/teamBulkUpload.py | 10 +++++---- BackEndFlask/models/queries.py | 28 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/BackEndFlask/Functions/teamBulkUpload.py b/BackEndFlask/Functions/teamBulkUpload.py index d09b8e127..8c4ac3b86 100755 --- a/BackEndFlask/Functions/teamBulkUpload.py +++ b/BackEndFlask/Functions/teamBulkUpload.py @@ -5,6 +5,7 @@ from models.team_user import * from models.user_course import * from models.course import * +from models.queries import does_team_user_exist from Functions.test_files.PopulationFunctions import xlsx_to_csv from datetime import date @@ -272,10 +273,11 @@ def __handle_student(student: TBUStudent, team_name: str, tainfo): else: set_inactive_status_of_user_to_active(user_course.user_course_id) - create_team_user({ - "team_id": team_id, - "user_id": user_id - }) + if not does_team_user_exist(user_id, team_id): + create_team_user({ + "team_id": team_id, + "user_id": user_id + }) tainfo = __handle_ta() diff --git a/BackEndFlask/models/queries.py b/BackEndFlask/models/queries.py index 0c1a20e9a..d82338284 100644 --- a/BackEndFlask/models/queries.py +++ b/BackEndFlask/models/queries.py @@ -1188,4 +1188,30 @@ def get_students_for_emailing(is_teams: bool, completed_at_id: int = None, at_id CompletedAssessment.completed_assessment_id == completed_at_id ) - return student_info.all() \ No newline at end of file + return student_info.all() + +def does_team_user_exist(user_id:int, team_id:int): + """ + Description: + Returns true or false if the (user_id,team_id) entry exists in TeamUser table. + + Paramaters: + user_id: (User Id) + team_id: (Team Id) + + Returns: + (If a (user_id, team_id) entry is present in TeamUser table) + + Exceptions: + None except what the db or oem may raise. + """ + is_entry = db.session.query( + TeamUser.team_user_id + ).filter( + TeamUser.user_id == user_id, + TeamUser.team_id == team_id + ).all() + + if len(is_entry) == 0: + return False + return True \ No newline at end of file From 6d75a6c09b80c05f8d773338b999fe93d6c17461 Mon Sep 17 00:00:00 2001 From: aldo Date: Thu, 12 Dec 2024 12:20:19 -0600 Subject: [PATCH 3/3] minor documentation but testing seems to be good --- BackEndFlask/Functions/teamBulkUpload.py | 1 + 1 file changed, 1 insertion(+) diff --git a/BackEndFlask/Functions/teamBulkUpload.py b/BackEndFlask/Functions/teamBulkUpload.py index 8c4ac3b86..812c9eabf 100755 --- a/BackEndFlask/Functions/teamBulkUpload.py +++ b/BackEndFlask/Functions/teamBulkUpload.py @@ -273,6 +273,7 @@ def __handle_student(student: TBUStudent, team_name: str, tainfo): else: set_inactive_status_of_user_to_active(user_course.user_course_id) + # Prevents duplicaition in the team user table. if not does_team_user_exist(user_id, team_id): create_team_user({ "team_id": team_id,