.
This commit is contained in:
+11
-11
@@ -187,18 +187,18 @@ class AnatomyQuestion(models.Model):
|
||||
if i.status != i.MarkOptions.UNMARKED
|
||||
]
|
||||
)
|
||||
correct_answers = set(
|
||||
[i.answer.get_compare_string() for i in self.answers.all()]
|
||||
)
|
||||
half_mark_answers = set(
|
||||
[i.answer.get_compare_string() for i in self.half_mark_answers.all()]
|
||||
)
|
||||
incorrect_answers = set(
|
||||
[i.answer.get_compare_string() for i in self.incorrect_answers.all()]
|
||||
)
|
||||
#correct_answers = set(
|
||||
# [i.answer.get_compare_string() for i in self.answers.all()]
|
||||
#)
|
||||
#half_mark_answers = set(
|
||||
# [i.answer.get_compare_string() for i in self.half_mark_answers.all()]
|
||||
#)
|
||||
#incorrect_answers = set(
|
||||
# [i.answer.get_compare_string() for i in self.incorrect_answers.all()]
|
||||
#)
|
||||
|
||||
marked_answers = correct_answers | half_mark_answers | incorrect_answers
|
||||
return marked_answers
|
||||
#marked_answers = correct_answers | half_mark_answers | incorrect_answers
|
||||
#return marked_answers
|
||||
|
||||
def get_annotations(self):
|
||||
return self.image_annotations
|
||||
|
||||
@@ -478,3 +478,7 @@ td.user-answer-score-2::after {
|
||||
font-style: italic;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.proposed-answer {
|
||||
color: darkblue
|
||||
}
|
||||
@@ -57,6 +57,7 @@ urlpatterns = [
|
||||
#path('', include('generic.urls')),
|
||||
path("feedback/<str:question_type>/<int:pk>", views.AddQuestionNote.as_view(), name="feedback_create"),
|
||||
#path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
|
||||
path("feedback/answer", views.answer_suggestion_submit, name="answer_suggestion_submit"),
|
||||
|
||||
|
||||
path('api/', include(router.urls)),
|
||||
|
||||
@@ -29,10 +29,12 @@ from physics.models import Exam as PhysicsExam
|
||||
from anatomy.models import CidUserAnswer as AnatomyCidUserAnswer
|
||||
from anatomy.models import Exam as AnatomyExam
|
||||
from anatomy.models import AnatomyQuestion
|
||||
from anatomy.models import Answer as AnatomyAnswer
|
||||
|
||||
from rapids.models import CidUserAnswer as RapidsCidUserAnswer
|
||||
from rapids.models import Exam as RapidsExam
|
||||
from rapids.models import Rapid
|
||||
from rapids.models import Answer as RapidAnswer
|
||||
|
||||
from longs.models import CidUserAnswer as LongsCidUserAnswer
|
||||
from longs.models import Exam as LongsExam
|
||||
@@ -44,6 +46,8 @@ from longs.views import LongExamViews
|
||||
from generic.forms import QuestionNoteForm
|
||||
from generic.models import QuestionNote
|
||||
|
||||
import json
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request):
|
||||
@@ -189,3 +193,35 @@ class AddQuestionNote(CreateView):
|
||||
get_object_or_404(question, pk=pk)
|
||||
return { "content_type" : content_type,
|
||||
"object_id" : pk }
|
||||
|
||||
@csrf_exempt
|
||||
def answer_suggestion_submit(request):
|
||||
if request.is_ajax and request.method == "POST":
|
||||
j = json.loads(request.body.decode())
|
||||
question_type, qid = j["qid"].split("/")
|
||||
answer_string = j["answer"]
|
||||
status = j["status"]
|
||||
|
||||
if str(status) not in " 012":
|
||||
return JsonResponse({"success": False, "error": "Invalid status"})
|
||||
|
||||
if question_type == "anatomy":
|
||||
AnswerModel = AnatomyAnswer
|
||||
question = AnatomyQuestion
|
||||
elif question_type == "rapid":
|
||||
AnswerModel = RapidAnswer
|
||||
question = Rapid
|
||||
else:
|
||||
return JsonResponse({"success": False, "error": "Invalid question type"})
|
||||
|
||||
if AnswerModel.objects.filter(answer=answer_string):
|
||||
return JsonResponse({"success": False, "error": "Answer already exists"})
|
||||
|
||||
q = get_object_or_404(question, pk=qid)
|
||||
|
||||
a = AnswerModel(question=q, answer=answer_string, status=status, proposed=True)
|
||||
a.save()
|
||||
return JsonResponse({"success": True, "error": "Answer submited"})
|
||||
|
||||
# postExamAnswers
|
||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
@@ -30,7 +30,9 @@
|
||||
<p><b>Scrapped:</b> {{ question.scrapped }} <a href="{% url 'rapids:rapid_scrap' pk=question.pk %}">(toggle)</a>
|
||||
<p class="pre-whitespace">
|
||||
Answers (score): {% for answer in question.answers.all %}
|
||||
<span {% if answer.proposed}class="proposed-answer"{% endif %}>
|
||||
{{ answer }} ({{answer.status}}),
|
||||
</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user