-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download alle indieningen (files) + csv (met indieningen info) in 1 k…
…eer als zip (#228) * backend: implement project zip * backend: implement csv * frontend: download all submissions
- Loading branch information
Showing
7 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from src.docker_tests.utils import submission_path | ||
import pathlib | ||
import zipfile | ||
import csv | ||
import io | ||
|
||
from src.submission.models import Status | ||
from src.submission.schemas import Submission | ||
from typing import Sequence | ||
|
||
from src.group.service import get_group_by_id | ||
from src.group.exceptions import GroupNotFound | ||
|
||
|
||
async def project_zip_stream(db: AsyncSession, submissions: Sequence[Submission], project_id): | ||
data = io.BytesIO() | ||
csvdata = io.StringIO() | ||
writer = csv.DictWriter(csvdata, fieldnames=[ | ||
"project", "group", "date", "status", "remarks", "stdout", "stderr"]) | ||
writer.writeheader() | ||
|
||
with zipfile.ZipFile(data, mode='w') as z: | ||
|
||
for submission in submissions: | ||
path = pathlib.Path(submission_path(submission.files_uuid, "")) | ||
|
||
group = await get_group_by_id(db, submission.group_id) | ||
|
||
if not group: | ||
raise GroupNotFound() | ||
|
||
writer.writerow({'project': submission.project_id, 'group': group.num, 'date': submission.date, 'status': Status( | ||
submission.status).name, 'remarks': submission.remarks, 'stdout': submission.stdout, 'stderr': submission.stderr}) | ||
|
||
for f_name in path.iterdir(): | ||
name = f"project_{ | ||
project_id}/group_{group.num}/{str(f_name).replace(str(path), "")}" | ||
z.write(f_name, arcname=name) | ||
|
||
z.writestr(f"project_{project_id}/submissions.csv", csvdata.getvalue()) | ||
|
||
data.seek(0) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters