Refactor user collections view to categorize collections into available, in-progress, and finished; update templates for improved display of collection statuses and question rendering.
This commit is contained in:
+29
-6
@@ -1391,18 +1391,25 @@ class BaseReportAnswer(models.Model):
|
||||
raise ValueError("No cid or user specified")
|
||||
|
||||
def get_correct_json_answers(self):
|
||||
logger.debug(f"Getting correct json answers for question {self.question.pk}")
|
||||
if self.question.question_schema is None or not "properties" in self.question.question_schema:
|
||||
return []
|
||||
answers = []
|
||||
for name, value in self.question.question_schema["properties"].items():
|
||||
logger.debug(f"Processing question property '{name}' with schema {value}")
|
||||
|
||||
try:
|
||||
user_answer = self.json_answer[name]
|
||||
except KeyError: # If the schema has changed?
|
||||
# Safely retrieve the user's answer and the stored correct answer.
|
||||
# json_answer or question_answers may be None (or not a dict) if not set,
|
||||
# so check before subscripting to avoid TypeError.
|
||||
if isinstance(self.json_answer, dict):
|
||||
user_answer = self.json_answer.get(name, "")
|
||||
else:
|
||||
user_answer = ""
|
||||
try:
|
||||
correct_answer = self.question.question_answers[name]
|
||||
except KeyError: # If the schema has changed?
|
||||
|
||||
qa = getattr(self.question, "question_answers", None)
|
||||
if isinstance(qa, dict):
|
||||
correct_answer = qa.get(name, "")
|
||||
else:
|
||||
correct_answer = ""
|
||||
|
||||
match value:
|
||||
@@ -1423,6 +1430,22 @@ class BaseReportAnswer(models.Model):
|
||||
|
||||
return answers
|
||||
|
||||
#def get_marked_answers_html(self):
|
||||
# """Returns an HTML representation of the users answers with correct answers highlighted"""
|
||||
# html = "<div class='json-answers'>"
|
||||
# for value, user_answer, correct_answer, answer_is_correct, automark in self.get_correct_json_answers():
|
||||
# if automark:
|
||||
# if answer_is_correct:
|
||||
# html += f"<div class='answer correct'>{user_answer}</div>"
|
||||
# else:
|
||||
# html += f"<div class='answer incorrect'>Your answer: {user_answer}<br/>Correct answer: {correct_answer}</div>"
|
||||
# else:
|
||||
# html += f"<div class='answer unmarked'>Your answer: {user_answer} (Not auto-marked)</div>"
|
||||
|
||||
# html += "</div>"
|
||||
|
||||
# return format_html(html)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user