Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skil 580 #803

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions BackEndFlask/Functions/teamBulkUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,14 +36,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
Expand Down Expand Up @@ -71,7 +72,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
Expand Down Expand Up @@ -263,10 +273,12 @@ 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
})
# Prevents duplicaition in the team user table.
if not does_team_user_exist(user_id, team_id):
create_team_user({
"team_id": team_id,
"user_id": user_id
})

tainfo = __handle_ta()

Expand Down
28 changes: 27 additions & 1 deletion BackEndFlask/models/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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: <class 'int'> (User Id)
team_id: <class 'int'> (Team Id)

Returns:
<class 'bool'> (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
Loading