diff --git a/backend/app/coordinator/routes/students.py b/backend/app/coordinator/routes/students.py index be392a4..92f0e23 100644 --- a/backend/app/coordinator/routes/students.py +++ b/backend/app/coordinator/routes/students.py @@ -102,11 +102,9 @@ def create_student(data: dict) -> dict: @bp.output(MessageSchema) def upload_students(file: dict) -> dict: uploaded_file = file.get('file') - mode = file.get('mode') == '0' - if uploaded_file and is_allowed_extensions(uploaded_file.filename): try: - students = parse_csv(uploaded_file, mode) + students = parse_csv(uploaded_file, mode=True) while True: sliced_students = islice(students, 5) list_of_students = list(sliced_students) @@ -120,6 +118,7 @@ def upload_students(file: dict) -> dict: except IntegrityError as e: # in the future create sql query checks index and add only these students, which didn't exist in db abort(400, "These students have already exist!") + else: abort(400, "Invalid extension of file") diff --git a/backend/app/coordinator/utils.py b/backend/app/coordinator/utils.py index e3abe2f..ab53f18 100644 --- a/backend/app/coordinator/utils.py +++ b/backend/app/coordinator/utils.py @@ -9,12 +9,13 @@ from ..students.models import Student def check_columns(df: pd.DataFrame) -> bool: headers = set(df.keys().values) - columns = ['first_name', 'last_name', 'index', 'mode'] + columns = ['NAZWISKO','IMIE','INDEKS','PESEL','EMAIL'] + if len(headers - set(columns)) != 0: return False flag = True - col_types = ['object', 'object', 'int', 'int'] + col_types = ['object', 'object', 'int', 'float64', 'object'] for name, col_type in zip(columns, col_types): if not str(df.dtypes[name]).startswith(col_type): @@ -25,11 +26,17 @@ def check_columns(df: pd.DataFrame) -> bool: def parse_csv(file, mode) -> Generator[Student, Any, None]: - df = pd.read_csv(file) + df = pd.read_csv(file, mode) - if not check_columns(df): - raise InvalidNameOrTypeHeaderException + # if not check_columns(df): + # raise InvalidNameOrTypeHeaderException - students = (Student(**dict(item.items(), mode=mode)) + students = (Student(last_name = dict(item.items())['NAZWISKO'], + first_name = dict(item.items())['NAZWISKO'], + index = dict(item.items())['INDEKS'], + pesel = str(int(dict(item.items())['PESEL'])) if not pd.isna(dict(item.items())['PESEL']) else '', + email = dict(item.items())['EMAIL'], + mode=mode) for _, item in df.iterrows()) + return students diff --git a/frontend/src/views/coordinator/Students.tsx b/frontend/src/views/coordinator/Students.tsx index 273e327..851f9ca 100644 --- a/frontend/src/views/coordinator/Students.tsx +++ b/frontend/src/views/coordinator/Students.tsx @@ -50,7 +50,6 @@ const Students = () => { const file = event.target.files[0] const payload = new FormData() payload.append('file', file, file.name) - payload.append('mode', mode ? '0' : '1') mutateUpload(payload) }