add mode info to upload and update test data

This commit is contained in:
Patryk Drzewiński 2022-06-12 19:01:16 +02:00
parent 52ba3313fb
commit d6c0bd189b
6 changed files with 17 additions and 15 deletions

View File

@ -100,12 +100,12 @@ def create_student(data: dict) -> dict:
@bp.route("/upload/", methods=["POST"])
@bp.input(FileSchema, location='form_and_files')
@bp.output(MessageSchema)
def upload_students(file: dict) -> dict:
def upload_students(file: dict, mode: bool) -> dict:
uploaded_file = file.get('file')
if uploaded_file and is_allowed_extensions(uploaded_file.filename):
try:
students = parse_csv(uploaded_file)
students = parse_csv(uploaded_file, mode)
while True:
sliced_students = islice(students, 5)
list_of_students = list(sliced_students)

View File

@ -51,6 +51,7 @@ class MessageSchema(ma.Schema):
class FileSchema(ma.Schema):
file = fields.Raw(type='file', required=True)
mode = fields.Bool(required=True)
class StudentQuerySchema(ma.Schema):

View File

@ -24,12 +24,12 @@ def check_columns(df: pd.DataFrame) -> bool:
return flag
def parse_csv(file) -> Generator[Student, Any, None]:
def parse_csv(file, mode) -> Generator[Student, Any, None]:
df = pd.read_csv(file)
if not check_columns(df):
raise InvalidNameOrTypeHeaderException
students = (Student(**dict(item.items(), email=f'student{randint(1, 300_000)}@gmail.com'))
students = (Student(**dict(item.items(), mode=mode))
for _, item in df.iterrows())
return students

View File

@ -1,9 +1,9 @@
first_name,last_name,index,mode
Patryk,Drzewiński,452790,1
Adam,Skowronek,452791,1
Mariia,Kuzmenko,452792,1
Dominik,Cupał,452793,1
Natalia,Wasik,452794,0
Michalina,Gaj,452795,0
Jan,Kowalski,452796,0
Adrian,Kowalski,452797,1
NAZWISKO,IMIE,INDEKS,PESEL,EMAIL
Drzewiński,Patryk,452790,11111111111,patdrz1@st.amu.edu.pl
Skowronek,Adam,452791,22222222222,adasko8@st.amu.edu.pl
Kuzmenko,Mariia,452792,33333333333,markuz5@st.amu.edu.pl
Cupał,Dominik,452793,44444444444,domcup@st.amu.edu.pl
Wasik,Natalia,452794,,wasna@st.amu.edu.pl
Gaj,Michalina,452795,,gajm@st.amu.edu.pl
Kowalski,Jan,452796,55555555555,kowj@st.amu.edu.pl
Kowalski,Adrian,452797,66666666666,kowa@st.amu.edu.pl
1 last_name NAZWISKO first_name IMIE index INDEKS mode PESEL EMAIL
2 Drzewiński Patryk 452790 1 11111111111 patdrz1@st.amu.edu.pl
3 Skowronek Adam 452791 1 22222222222 adasko8@st.amu.edu.pl
4 Kuzmenko Mariia 452792 1 33333333333 markuz5@st.amu.edu.pl
5 Cupał Dominik 452793 1 44444444444 domcup@st.amu.edu.pl
6 Wasik Natalia 452794 0 wasna@st.amu.edu.pl
7 Gaj Michalina 452795 0 gajm@st.amu.edu.pl
8 Kowalski Jan 452796 0 55555555555 kowj@st.amu.edu.pl
9 Kowalski Adrian 452797 1 66666666666 kowa@st.amu.edu.pl

View File

@ -34,8 +34,9 @@ export const getStudents = (
export const createStudent = (payload: Student) =>
axiosInstance.post('http://127.0.0.1:5000/api/coordinator/students/', payload)
export const uploadStudents = (payload: FormData) =>
export const uploadStudents = (payload: FormData, mode: Boolean) =>
axiosInstance.post(
'http://127.0.0.1:5000/api/coordinator/students/upload/',
payload,
mode,
)

View File

@ -40,7 +40,7 @@ const Students = () => {
const { mutate: mutateUpload } = useMutation(
'uploadStudents',
(payload: FormData) => uploadStudents(payload),
(payload: FormData) => uploadStudents(payload, mode),
{
onSuccess: () => refetchStudents(),
},