Skip to content

Commit

Permalink
add: text field for further explanation if unsure in macula task
Browse files Browse the repository at this point in the history
  • Loading branch information
huangziwei committed Jun 4, 2024
1 parent 826069a commit 8e266b8
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 5 deletions.
17 changes: 17 additions & 0 deletions accounts/migrations/0022_alter_invitationcode_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1.7 on 2024-06-04 10:55

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0021_alter_invitationcode_code"),
]

operations = [
migrations.AlterField(
model_name="invitationcode",
name="code",
field=models.CharField(default="vbyxxrqk", max_length=100, unique=True),
),
]
4 changes: 2 additions & 2 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
DEBUG = env.bool("DEBUG", default=False)

# ALLOWED_HOSTS = ["*"]
ALLOWED_HOSTS = ["r.etr.ist", "retimgtools.fly.dev"]
ALLOWED_HOSTS = ["r.etr.ist", "retimgtools.fly.dev", "*"]


# Application definition
Expand Down Expand Up @@ -160,4 +160,4 @@
]
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
DATA_UPLOAD_MAX_NUMBER_FIELDS = 1000
SECURE_SSL_REDIRECT = True
SECURE_SSL_REDIRECT = False
Binary file added db.sqlite3.save
Binary file not shown.
1 change: 1 addition & 0 deletions retimgeval/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ChoiceAdmin(admin.ModelAdmin):
class AnswerAdmin(admin.ModelAdmin):
list_display = (
"choice",
"notes",
"user",
"task",
"question",
Expand Down
2 changes: 1 addition & 1 deletion retimgeval/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, *args, **kwargs):
class AnswerForm(forms.ModelForm):
class Meta:
model = Answer
fields = ["choice"]
fields = ["choice", "notes"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
20 changes: 20 additions & 0 deletions retimgeval/migrations/0013_answer_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.7 on 2024-06-04 10:55

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"retimgeval",
"0012_remove_question_image4_remove_question_image4_height_and_more",
),
]

operations = [
migrations.AddField(
model_name="answer",
name="notes",
field=models.TextField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions retimgeval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Answer(models.Model):
answered_at = models.DateTimeField(auto_now=True, blank=True, null=True)
reaction_time = models.FloatField(blank=True, null=True)
delay_time = models.FloatField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)

def __str__(self):
return self.choice.choice_text
Expand Down
17 changes: 16 additions & 1 deletion retimgeval/templates/retimgeval/question_detail_macula.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,27 @@ <h5>Options for magnifiers</h5>
<div class="sub-question-form choices-vertical mt-2">
{% for choice in form.fields.choice.queryset %}
<div class="choice-item">
<input type="radio" id="choice_{{ choice.id }}" name="{{ sub_question.id }}" value="{{ choice.id }}">
<input type="radio" id="choice_{{ choice.id }}" name="{{ sub_question.id }}" value="{{ choice.id }}"
onclick="toggleNotes('{{ choice.choice_text }}', '{{ sub_question.id }}')">
<label for="choice_{{ choice.id }}">
{{ choice.choice_text }}
</label>
</div>
{% endfor %}
<!-- Add notes field here -->
<div class="form-group mt-3">
<textarea id="notes_{{ sub_question.id }}" name="notes_{{ sub_question.id }}" class="form-control" rows="3" style="display:none;" placeholder="why?"></textarea>
</div>
<script>
function toggleNotes(choiceText, subQuestionId) {
var notesTextarea = document.getElementById('notes_' + subQuestionId);
if (choiceText.toLowerCase() === 'unsure') {
notesTextarea.style.display = 'block';
} else {
notesTextarea.style.display = 'none';
}
}
</script>
</div>
{% if sub_question in unanswered_sub_questions %}
<div class="alert alert-danger">
Expand Down
3 changes: 2 additions & 1 deletion retimgeval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def question_detail(request, slug):

for sub_question in sub_questions:
choice_id = request.POST.get(str(sub_question.id), None)
form_data = {"choice": choice_id}
notes = request.POST.get(f"notes_{sub_question.id}", "")
form_data = {"choice": choice_id, "notes": notes}
form = AnswerForm(form_data)
form.fields["choice"].queryset = sub_question.choice_set.all()

Expand Down

0 comments on commit 8e266b8

Please sign in to comment.