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.route("/upload/", methods=["POST"])
|
||||||
@bp.input(FileSchema, location='form_and_files')
|
@bp.input(FileSchema, location='form_and_files')
|
||||||
@bp.output(MessageSchema)
|
@bp.output(MessageSchema)
|
||||||
def upload_students(file: dict) -> dict:
|
def upload_students(file: dict, mode: bool) -> dict:
|
||||||
uploaded_file = file.get('file')
|
uploaded_file = file.get('file')
|
||||||
|
|
||||||
if uploaded_file and is_allowed_extensions(uploaded_file.filename):
|
if uploaded_file and is_allowed_extensions(uploaded_file.filename):
|
||||||
try:
|
try:
|
||||||
students = parse_csv(uploaded_file)
|
students = parse_csv(uploaded_file, mode)
|
||||||
while True:
|
while True:
|
||||||
sliced_students = islice(students, 5)
|
sliced_students = islice(students, 5)
|
||||||
list_of_students = list(sliced_students)
|
list_of_students = list(sliced_students)
|
||||||
|
@ -51,6 +51,7 @@ class MessageSchema(ma.Schema):
|
|||||||
|
|
||||||
class FileSchema(ma.Schema):
|
class FileSchema(ma.Schema):
|
||||||
file = fields.Raw(type='file', required=True)
|
file = fields.Raw(type='file', required=True)
|
||||||
|
mode = fields.Bool(required=True)
|
||||||
|
|
||||||
|
|
||||||
class StudentQuerySchema(ma.Schema):
|
class StudentQuerySchema(ma.Schema):
|
||||||
|
@ -24,12 +24,12 @@ def check_columns(df: pd.DataFrame) -> bool:
|
|||||||
return flag
|
return flag
|
||||||
|
|
||||||
|
|
||||||
def parse_csv(file) -> Generator[Student, Any, None]:
|
def parse_csv(file, mode) -> Generator[Student, Any, None]:
|
||||||
df = pd.read_csv(file)
|
df = pd.read_csv(file)
|
||||||
|
|
||||||
if not check_columns(df):
|
if not check_columns(df):
|
||||||
raise InvalidNameOrTypeHeaderException
|
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())
|
for _, item in df.iterrows())
|
||||||
return students
|
return students
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
first_name,last_name,index,mode
|
NAZWISKO,IMIE,INDEKS,PESEL,EMAIL
|
||||||
Patryk,Drzewiński,452790,1
|
Drzewiński,Patryk,452790,11111111111,patdrz1@st.amu.edu.pl
|
||||||
Adam,Skowronek,452791,1
|
Skowronek,Adam,452791,22222222222,adasko8@st.amu.edu.pl
|
||||||
Mariia,Kuzmenko,452792,1
|
Kuzmenko,Mariia,452792,33333333333,markuz5@st.amu.edu.pl
|
||||||
Dominik,Cupał,452793,1
|
Cupał,Dominik,452793,44444444444,domcup@st.amu.edu.pl
|
||||||
Natalia,Wasik,452794,0
|
Wasik,Natalia,452794,,wasna@st.amu.edu.pl
|
||||||
Michalina,Gaj,452795,0
|
Gaj,Michalina,452795,,gajm@st.amu.edu.pl
|
||||||
Jan,Kowalski,452796,0
|
Kowalski,Jan,452796,55555555555,kowj@st.amu.edu.pl
|
||||||
Adrian,Kowalski,452797,1
|
Kowalski,Adrian,452797,66666666666,kowa@st.amu.edu.pl
|
|
@ -34,8 +34,9 @@ export const getStudents = (
|
|||||||
export const createStudent = (payload: Student) =>
|
export const createStudent = (payload: Student) =>
|
||||||
axiosInstance.post('http://127.0.0.1:5000/api/coordinator/students/', payload)
|
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(
|
axiosInstance.post(
|
||||||
'http://127.0.0.1:5000/api/coordinator/students/upload/',
|
'http://127.0.0.1:5000/api/coordinator/students/upload/',
|
||||||
payload,
|
payload,
|
||||||
|
mode,
|
||||||
)
|
)
|
||||||
|
@ -40,7 +40,7 @@ const Students = () => {
|
|||||||
|
|
||||||
const { mutate: mutateUpload } = useMutation(
|
const { mutate: mutateUpload } = useMutation(
|
||||||
'uploadStudents',
|
'uploadStudents',
|
||||||
(payload: FormData) => uploadStudents(payload),
|
(payload: FormData) => uploadStudents(payload, mode),
|
||||||
{
|
{
|
||||||
onSuccess: () => refetchStudents(),
|
onSuccess: () => refetchStudents(),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user