cms icon indicating copy to clipboard operation
cms copied to clipboard

Display Task Statement in the Page

Open raylin01 opened this issue 7 years ago • 16 comments

Is it possible to modify the CMS so that instead of the pdf being downloaded it is displayed inside the task page itself? Also, is there a way to modify CMS so that there are different time limits for different languages? Thanks!

raylin01 avatar Feb 23 '18 04:02 raylin01

Displaying task statements in the page is a really good idea and I think the best way to do it is to support optional markdown format statements (MD file extension) and render those with a Javascript library. We do something like this in @algorithm-ninja/territoriali-frontend

As for different time limits for different languages, I think it's not such a good idea because it can be abused easily. Someone could compile a C++ program and hen embed the binary file inside a Python source code, for example.

Il 23 feb 2018 1:14 PM, "Ray Lin" [email protected] ha scritto:

Is it possible to modify the CMS so that instead of the pdf being downloaded it is displayed inside the task page itself? Also, is there a way to modify CMS so that there are different time limits for different languages? Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cms-dev/cms/issues/859, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOc8ZAGgMPyRUMopaw7sLBQGSMnS4Qdks5tXjsdgaJpZM4SQXMd .

wil93 avatar Feb 24 '18 00:02 wil93

Does anyone know which code is being called when the pdf is being downloaded? I think that can be modified to display html/pdf embeded

raylin01 avatar Feb 24 '18 01:02 raylin01

I agree with @wil93, requiring a pdf for the statement is quite limiting. Regarding showing the pdf (or any format) inline: I can see us doing that, but requires a bit of front-end work to handle the case of multiple statements.

Time limits: again plussing @wil93, we don't support different time limits per language, and I don't think we will because of possible circumventions like the one he mentions.

stefano-maggiolo avatar Feb 24 '18 06:02 stefano-maggiolo

Forgot: the template for the statement page is https://github.com/cms-dev/cms/blob/master/cms/server/contest/templates/task_description.html

stefano-maggiolo avatar Feb 24 '18 07:02 stefano-maggiolo

the best way to do it is to support optional markdown format statements (MD file extension) and render those with a Javascript library

Since this is relevant for translations, may I suggest still allowing a PDF to be displayed as-is? This would be a more global approach, since not all languages can be reasonably converted to MD.

I have tried various translation and text systems over the years for writing Hebrew statements. Markdown is not right-to-left friendly, and I personally advise against trying to make it so. To be clear, I'm sure there are libraries that display MD aligned to the right, but there is more to RTL than that: formulas are often still written LTR, and the combination of both directions, especially in the same line, does not play well in any plain text editor. Such text is frustrating and time consuming to edit. There are non-plain editors that solve this problem correctly, but I think it's out of scope for CMS to try and support such tools for all languages. PDF is already the solution IMHO.

nir-lavee avatar Feb 24 '18 08:02 nir-lavee

If we allowed Markdown statements we would still have to provide a way to export them to PDF, for contestants who like to read them out of the browser or to print them (or at least make sure that the browsers' "export to PDF" function works correctly on them).

For rendering PDFs directly in-browser we could have a look at https://mozilla.github.io/pdf.js/.

lw avatar Feb 24 '18 09:02 lw

Most browsers (read: at least Chrome) support pdf without js libraries. We used to use pdfjs for @algorithm-ninja/cmsocial but now we just embed the pdf and it works (unless it doesn't, then we fallback to pdfjs)

Il 24 feb 2018 6:13 PM, "Luca Wehrstedt" [email protected] ha scritto:

If we allowed Markdown statements we would still have to provide a way to export them to PDF, for contestants who like to read them out of the browser or to print them (or at least make sure that the browsers' "export to PDF" function works correctly on them).

For rendering PDFs directly in-browser we could have a look at https://mozilla.github.io/pdf.js/.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cms-dev/cms/issues/859#issuecomment-368213926, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOc8VCU4HGjgRQDaoswzI89KJrz0pA9ks5tX9KrgaJpZM4SQXMd .

wil93 avatar Feb 24 '18 10:02 wil93

I've made changed on my personal task_description.html but nothing is changing. Is there a cached version somewhere that the server is accessing?

raylin01 avatar Feb 24 '18 16:02 raylin01

You need to restart CWS at least, most probably to reinstall CMS. An alternative is to use setup.py develop instead of install - that install files by linking them to those in the original repo, so changes are reflected without the need to reinstall. Still, you have to restart CWS :)

stefano-maggiolo avatar Feb 24 '18 16:02 stefano-maggiolo

I tried adding the following code to task_description: `<object data="{{ contest_url("tasks", task.name, "statements", lang_code) }}" type="application/pdf" width="750px" height="750px"> <embed src="{{ contest_url("tasks", task.name, "statements", lang_code) }}" type="application/pdf">

This browser does not support PDFs. Please download the PDF to view it: <a href="{{ contest_url("tasks", task.name, "statements", lang_code) }}">Download PDF.

raylin01 avatar Feb 24 '18 17:02 raylin01

The handler that serves the statements is: https://github.com/cms-dev/cms/blob/2025d3d29fd228ddfeeb54e303eafc073fd2df62/cms/server/contest/handlers/task.py#L83 and they are served as attachments: https://github.com/cms-dev/cms/blob/2025d3d29fd228ddfeeb54e303eafc073fd2df62/cms/server/util.py#L326-L327 which causes the browser to download them rather than display them.

Changing this (without breaking all other file downloads) isn't a small fix.

lw avatar Feb 24 '18 17:02 lw

I was debugging the file handler in cms/server/util.py with @bblackham the other day, and we noticed that the file gets read from database into memory (even if it's huge) and then gets served by the web server. This is quite bad (the web server will have the whole file in memory, possibly taking up space for each file request but I didn't check). I should open a separate issue for this. However I mentioned this just because it might be a good time to completely refactor this part of cms, so the "embedding pdf" change could turn out to be not a big change

Il 25 feb 2018 2:28 AM, "Luca Wehrstedt" [email protected] ha scritto:

The handler that serves the statements is: https://github.com/cms-dev/cms/blob/2025d3d29fd228ddfeeb54e303eafc 073fd2df62/cms/server/contest/handlers/task.py#L83 and they are served as attachments: https://github.com/cms-dev/cms/blob/2025d3d29fd228ddfeeb54e303eafc 073fd2df62/cms/server/util.py#L326-L327 which causes the browser to download them rather than display them.

Changing this (without breaking all other file downloads) isn't a small fix.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/cms-dev/cms/issues/859#issuecomment-368244559, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOc8fr0Vpp6wquKMDljL1ys6BuoJITVks5tYEa9gaJpZM4SQXMd .

wil93 avatar Feb 25 '18 01:02 wil93

I think adding a flush after every write should fix this, right?

lw avatar Feb 25 '18 08:02 lw

We tried, but it didn't work. Bernard digged a bit more than me anyway

Il 25 feb 2018 9:44 AM, "Luca Wehrstedt" [email protected] ha scritto:

I think adding a flush after every write should fix this, right?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/cms-dev/cms/issues/859#issuecomment-368292931, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOc8YwFyLBny5zYegUuyeQHggoHuuBlks5tYR13gaJpZM4SQXMd .

wil93 avatar Feb 25 '18 17:02 wil93

Could @bblackham clarify? Because if flushing doesn't work as expected we should probably report it upstream to Tornado...

PS: if you think this is bigger than what I am imagining, please report it in a dedicated issue.

lw avatar Feb 25 '18 17:02 lw

PS: if you think this is bigger than what I am imagining, please report it in a dedicated issue.

Discussion moved to #870

wil93 avatar Feb 27 '18 11:02 wil93