-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add file submission to problem page #1933
base: master
Are you sure you want to change the base?
Add file submission to problem page #1933
Conversation
Perhaps it would be be much less code if this was just implemented client side with JS so there would be no need for any kind of server code changes. |
I added 16 lines of server side code. It's possible that using client side JS would take less but it won't be a huge difference. Unless there is a better reason to switch I think we can leave things as they are. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a general comment: I think we should move this to the Submit Solution
page rather than at the bottom of the problem statement page. This centralizes the location where a user can submit a solution.
As a consequence of this, we can revert all the changes in judge/views/problem.py
and revert Go to editor
to Submit solution
.
Also, could you run flake8
locally to fix all the linting issues?
templates/problem/problem.html
Outdated
</a> | ||
{% endif %} | ||
{% if request.user.is_authenticated and (not request.in_contest or submission_limit) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: please use spaces instead of tabs.
judge/forms.py
Outdated
class Meta: | ||
model = Submission | ||
fields = ['language'] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't delete newline.
The main issue is that handling file uploads on the server side is much more prone to issues than simply using a text field. For example, your code is vulnerable to memory DoS attacks if the user uploads a very large file composed of only 0s since it decodes line-by-line. In addition, it would cause a 500 if you were to upload a file that included invalid UTF-8 because it tries to decode without a try-except. Typically, Django does most of the validation work for you if you use a normal text field, but it provides much less built in protection against these bugs if you want to handle file uploads. Moving the processing to the client side significantly reduces the bug surface simply because handling file uploads on the server side is nontrivial. |
I removed all modifications to server side code. Thanks for looking at this.
In my opinion the main benefit of this feature is that it creates a shortcut for submitting from the problem page. I'm open to moving it around though. Here are some screenshots of the "Submit solution"/"Go to editor" button in case anyone wants to look at the changes without setting them up: |
Notes:
/problem/<problem-code>/submit
, which means that error messages, for example when submitting a file with length greater than 65535, show up in the editor. This isn't amazing UX but it might be acceptable.