Skip to content

Commit

Permalink
Implement code autocompletion (from #20) for quizzes
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnans2006 committed May 27, 2024
1 parent 5c10d9d commit 617ebd1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tin/apps/assignments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Meta:
"submission_limit_cooldown",
"is_quiz",
"quiz_action",
"quiz_autocomplete_enabled",
]
labels = {
"markdown": "Use markdown?",
Expand All @@ -82,6 +83,7 @@ class Meta:
"submission_limit_interval": "Rate limit interval (minutes)",
"submission_limit_cooldown": "Rate limit cooldown period (minutes)",
"is_quiz": "Is this a quiz?",
"quiz_autocomplete_enabled": "Enable code autocompletion?",
}
sections = (
{
Expand Down Expand Up @@ -112,6 +114,7 @@ class Meta:
"fields": (
"is_quiz",
"quiz_action",
"quiz_autocomplete_enabled",
),
"collapsed": False,
},
Expand Down Expand Up @@ -149,9 +152,13 @@ class Meta:
"submission_limit_cooldown": 'This sets the length of the "cooldown" period after a '
"student exceeds the rate limit for submissions.",
"folder": "If blank, assignment will show on the main classroom page.",
"is_quiz": "This forces students to submit through a page that monitors their actions.",
"is_quiz": "This forces students to submit through a page that monitors their actions. The below options "
"have no effect if this is unset.",
"quiz_action": "Tin will take the selected action if a student clicks off of the "
"quiz page.",
"quiz_autocomplete_enabled": "This gives students basic code completion in the quiz editor, including "
"variable names, built-in functions, and keywords. It's recommended for quizzes that focus on code logic "
"and not syntax.",
}
widgets = {"description": forms.Textarea(attrs={"cols": 30, "rows": 4})}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.13 on 2024-05-27 21:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("assignments", "0030_quizlogmessage_assignment_is_quiz_and_more"),
]

operations = [
migrations.AddField(
model_name="assignment",
name="quiz_autocomplete_enabled",
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions tin/apps/assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Assignment(models.Model):
is_quiz = models.BooleanField(default=False)
QUIZ_ACTIONS = (("0", "Log only"), ("1", "Color Change"), ("2", "Lock"))
quiz_action = models.CharField(max_length=1, choices=QUIZ_ACTIONS, default="2")
quiz_autocomplete_enabled = models.BooleanField(default=False)

objects = AssignmentQuerySet.as_manager()

Expand Down
9 changes: 9 additions & 0 deletions tin/templates/assignments/quiz.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.33.2/ext-modelist.min.js"
integrity="sha512-bxvuZHJlay2Y4HHIPrEhyE9YRfKoyqI/JoRPyeu5YwLLfvecSUupKJluhXOvDNTfVZXQnXOxd7Fo3vJxij3GSQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.33.2/ext-language_tools.min.js"
integrity="sha512-4l33zsqrqf1PBA3iEZ399Jl9on7It0HngOkI3TG2c6W0wUyTiXRxd9Eh8zFBXNy8fMlgda/u4u1metnbEf5Hzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
{% if latest_submission %}
<script src="{% static 'js/incomplete.js' %}"></script>
{% endif %}
Expand All @@ -32,6 +35,12 @@
var mode = modelist.getModeForPath(filename).mode;
editor.session.setMode(mode);

{% if assignment.quiz_autocomplete_enabled %}
editor.setOptions({
enableLiveAutocompletion: true
});
{% endif %}

editor.getSession().setValue(textarea.val());
editor.getSession().on("change", function () {
textarea.val(editor.getSession().getValue());
Expand Down

0 comments on commit 617ebd1

Please sign in to comment.