add mode info to upload and update test data
This commit is contained in:
parent
52ba3313fb
commit
d6c0bd189b
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
|
@ -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,
|
||||
)
|
||||
|
@ -40,7 +40,7 @@ const Students = () => {
|
||||
|
||||
const { mutate: mutateUpload } = useMutation(
|
||||
'uploadStudents',
|
||||
(payload: FormData) => uploadStudents(payload),
|
||||
(payload: FormData) => uploadStudents(payload, mode),
|
||||
{
|
||||
onSuccess: () => refetchStudents(),
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user