Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.
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
13 changes: 13 additions & 0 deletions inginious/frontend/webapp/pages/course_admin/task_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

from collections import OrderedDict

import re
import web
import yaml


from inginious.frontend.webapp.pages.course_admin.utils import make_csv, INGIniousAdminPage

Expand All @@ -23,6 +26,16 @@ def POST_AUTH(self, courseid): # pylint: disable=arguments-differ
course, _ = self.get_course_and_check_rights(courseid)
data = web.input(task=[])

if "new_task_id" in data:
# Create new task
valid_expression = re.compile("^[a-zA-Z0-9_\-]+$")
if valid_expression.match(data["new_task_id"]):
default_task_data = yaml.safe_load(open("task.yaml", "r"))
default_task_data["name"] = data["new_task_id"]
self.task_factory.update_task_descriptor_content(courseid, data["new_task_id"], default_task_data, "yaml")



if "task" in data:
# Change tasks order
for index, taskid in enumerate(data["task"]):
Expand Down
11 changes: 11 additions & 0 deletions inginious/frontend/webapp/static/js/studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
/**
* Redirect to the studio to create a new task
*/

function studio_validate_name_task(){
var task_id = $('#new_task_id');
if(!task_id.val().match(/^[a-zA-Z0-9_\-]+$/))
{
alert('Task id should only contain alphanumeric characters (in addition to "_" and "-").');
return;
}
}


function studio_create_new_task()
{
var task_id = $('#new_task_id');
Expand Down
11 changes: 7 additions & 4 deletions inginious/frontend/webapp/templates/course_admin/task_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ <h2>Tasks
</form>

<div class="row">
<div class="form-group">
<div class="col-sm-9"><input type="text" class="form-control" id="new_task_id" placeholder="New task id"/></div>
<div class="col-sm-3"><a href="javascript:studio_create_new_task();" class="btn btn-info btn-large btn-block">Create new task</a></div>
<form class="form-horizontal" method="post">
Copy link
Member

Choose a reason for hiding this comment

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

Why didn't you put action on this form?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because webpy assumes that the action goes to the same page. So I went to task_list.py and modify the POST method in there

<div class="form-group">
<div class="col-sm-9"><input type="text" class="form-control" name="new_task_id" id="new_task_id" placeholder="New task id"/></div>
<div class="col-sm-3"><button type="submit" class="form-control btn btn-primary" onclick="studio_validate_name_task();" value="Create new task"/>Create task</div>
</div>
</form>
</div>
</div>
$if len(errors) != 0:
Expand Down Expand Up @@ -117,4 +120,4 @@ <h3>Errors while loading tasks</h3>
}
$$('.sorted_table').sortable($$(this).hasClass("active") ? "enable" : "disable");
});
</script>
</script>
24 changes: 24 additions & 0 deletions task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
accessible: true
author: ''
context: ''
environment: mcq
evaluate: best
groups: false
limits:
output: '2'
memory: '100'
time: '30'
name: default
network_grading: false
problems:
default-task:
name: ''
type: code-multiple-languages
languages:
cpp11: true
header: ''
stored_submissions: 0
submission_limit:
amount: -1
period: -1
weight: 1.0