Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previous submission file #1016

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions inginious/frontend/pages/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def GET(self, courseid, taskid, is_LTI):

self.user_manager.user_saw_task(username, courseid, taskid)


userinput = flask.request.args
if "submissionid" in userinput and "questionid" in userinput:

# Download a previously submitted file
submission = self.submission_manager.get_submission(userinput["submissionid"], user_check=not is_staff)
if submission is None:
Expand All @@ -98,14 +98,23 @@ def GET(self, courseid, taskid, is_LTI):
if userinput["questionid"] not in sinput:
raise NotFound()

if isinstance(sinput[userinput["questionid"]], dict):
# File uploaded previously
file_data = sinput[userinput["questionid"]]
if isinstance(file_data, dict):
filename = file_data['filename']
file_content = file_data['value']
mimetypes.init()
mime_type = mimetypes.guess_type(urllib.request.pathname2url(sinput[userinput["questionid"]]['filename']))
return Response(response=sinput[userinput["questionid"]]['value'], content_type=mime_type[0])
mime_type = mimetypes.guess_type(urllib.request.pathname2url(filename))

# Force download for non pdf files
if not filename.lower().endswith(".pdf"):
headers = {
'Content-Disposition': f'attachment; filename="{filename}"'
}
return Response(response=file_content, content_type=mime_type[0], headers=headers)
Comment on lines +109 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why having a difference in behavior if the file is a PDF ? I think the best is to download it as any other file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature has been asked by the professor using INGInious. When you need to review multiple pdf file it's easier to just display it in the browser than downloading all the pdf files on the professor personnal computer. Since the other type of files cannot be directly shown in the browser using a built in feature, we only display pdf files


return Response(response=file_content, content_type=mime_type[0])
else:
# Other file, download it as text
return Response(response=sinput[userinput["questionid"]], content_type='text/plain')
return Response(response=file_data, content_type='text/plain')
else:
# Generate random inputs and save it into db
random.seed(str(username if username is not None else "") + taskid + courseid + str(
Expand Down
2 changes: 1 addition & 1 deletion inginious/frontend/static/js/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ function load_input_file(submissionid, key, input)
var input_file = $('#download-input-file-' + key);
input_file.attr('href', url );
input_file.css('display', 'block');
if(allowed_exts.indexOf(".pdf") >= 0) {
if(input[key]["filename"].endsWith('.pdf')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the allowed_ext definition if it is not used anymore.

Apart from this, where is load_input_file() used ?

var input_file_pdf = $('#download-input-file-pdf-' + key);
input_file_pdf.attr('data', url);
input_file_pdf.find("embed").attr("src", url);
Expand Down
Loading