Skip to content

How to add a new subproblem for a task

Cristian Gonzalez edited this page Oct 22, 2020 · 4 revisions

How to add a new subproblem for a task

Adding a new subproblem to UNCode is quite easy using plugins, a subproblem can be seen as a additional configuration for the task, on UNCode we used to add the option to submit multiple language submissions either in code or file, and notebook submissions. For this, please do the changes inside the multilang plugin, as this plugin is in charge to add this new subproblems.

Tutorial

See the INGInious documentation to understand how you can do this. Also see the multilang plugin where the subproblems are added.

Add the subproblem type

In the common package (inginious.common) is located the tasks_problems Which contains the classes for every kind of subproblem that is possible to add in a specific task, the you will find the next classes you can use to inherit from:

  • Problem
  • CodeProblem
  • CodeSingleLineProblem
  • FileProblem
  • MultipleChoiceProblem
  • MatchProblem

For the case of multilang plugin, we have added the CodeMultipleLanguagesProblem class that inherits from CodeProblem, this class will handle the objects of our desired new subproblem. This is show in the next image:

Define a new type of subproblem overriding the method get_type, where for this example the type is called code_multiple_languages. Thus, submissions will have this new label and we can identify a submission to this type.

Display subproblem in the frontend

If you need to add some feature in the frontend that a student should see, as well as the professor, it’s necessary to continue and add some more things to the code. As there is a set of classes to control the type of subproblems objects, there are some classes that control the functioning of the interface of those type of subproblems. Those classes are allocated in the file inginious/frontend/common/task_problems.py.

Actually, these classes render the html file that will be showed to the user. It must extend from the class previously created class (CodeMultipleLanguagesProblem) and from some of the Displayable classes defined in this file, for this case, DisplayableCodeProblem for the case of multilang plugin.

Some methods most be override to add the new functionality: get_renderer, get_type_name, show_editbox, show_input. In this methods you have to use the TemplateHelper to add the corresponding templates that will be shown to either the student or the instructor. For that, add two templates, on corresponding to the edit and other the one students see.

Control templates

The frontend and control of the actions in the frontend are mostly done in inginious/frontend/static/js/studio.js. Thus, a static js file must be added in the plugin to do something similar, to control the added templates.

  • studio_init_template_<subproblem_type>, this function must start with the prefix studio_init_template_ followed by the subproblem type, which in this example is code_multiple_languages. Thus the name of the function will be studio_init_template_code_multiple_languages. Inside this function, the type of the correct subproblem type is updated in frontend. This function is automatically called by the function studio_init_template in the file studio.js.
  • (optional) load_input_<subproblem_type>: this function must start with the prefix load_input_ followed by the subproblem type, which in this example is code_multiple_languages. Thus, the name of the function will be load_input_template_code_multiple_languages. This function is in charge of loading previous submissions selected in the submission history of the task. This function is automatically called by the function load_input in the file inginious/frontend/static/js/task.js.

After adding these functions, your subproblem type should be now working and you should be able to submit new type of tasks.

Clone this wiki locally