This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added functionlity for downloading files
- Loading branch information
Showing
5 changed files
with
42 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
backend/project/endpoints/projects/project_assignment_file.py
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,32 @@ | ||
""" | ||
Module for getting the assignment files | ||
of a project | ||
""" | ||
import os | ||
from urllib.parse import urljoin | ||
|
||
from flask import jsonify, send_from_directory, send_file | ||
from werkzeug.utils import safe_join | ||
|
||
from flask_restful import Resource | ||
|
||
from project.models.project import Project | ||
from project.utils.query_agent import query_by_id_from_model | ||
|
||
API_URL = os.getenv('API_HOST') | ||
RESPONSE_URL = urljoin(API_URL, "projects") | ||
UPLOAD_FOLDER = os.getenv('UPLOAD_URL') | ||
|
||
class ProjectAssignmentFiles(Resource): | ||
""" | ||
Class for getting the assignment files of a project | ||
""" | ||
def get(self, project_id): | ||
|
||
project = Project.query.filter(getattr(Project, "project_id") == project_id).first() | ||
|
||
file_url = urljoin(f"{UPLOAD_FOLDER}", f"{project_id}") + "/" | ||
|
||
directory = safe_join(os.getcwd(), file_url) | ||
|
||
return send_from_directory(directory, project.assignment_file, as_attachment=True) |
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