diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 23 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_forum.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/lessons_forum.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/post_comments.html | 4 | ||||
-rw-r--r-- | yaksh/test_models.py | 14 |
5 files changed, 21 insertions, 24 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index da2327c..cca2a2c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2378,15 +2378,24 @@ class AnswerPaper(models.Model): 'error_list': [e for e in json.loads(answer.error)] }] + q_a.update( + { q: [] for q in self.questions_unanswered.all() } + ) + for question, answers in q_a.items(): answers = q_a[question] - q_a[question].append({ - 'marks': max([ - answer['answer'].marks - for answer in answers - if question == answer['answer'].question - ]) - }) + if answers: + q_a[question].append({ + 'marks': max([ + answer['answer'].marks + for answer in answers + if question == answer['answer'].question + ]), + }) + else: + q_a[question].append({ + 'marks': 0.0, + }) return q_a diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html index acd6861..b98688b 100644 --- a/yaksh/templates/yaksh/course_forum.html +++ b/yaksh/templates/yaksh/course_forum.html @@ -129,7 +129,7 @@ {% endwith %} </td> <td> - {% if user == course.creator %} + {% if user == course.creator or user in course.get_teachers %} <small><a href="{% url 'yaksh:hide_post' course.id post.uid %}" class="pull-right fa fa-trash"></i></a></small> {% endif %} </td> diff --git a/yaksh/templates/yaksh/lessons_forum.html b/yaksh/templates/yaksh/lessons_forum.html index 250536d..58fb360 100644 --- a/yaksh/templates/yaksh/lessons_forum.html +++ b/yaksh/templates/yaksh/lessons_forum.html @@ -61,7 +61,7 @@ {% endwith %} </td> <td> - {% if user == course.creator %} + {% if user == course.creator or user in course.get_teachers %} <small><a href="{% url 'yaksh:hide_post' course.id post.uid %}" class="pull-right fa fa-trash"></i></a></small> {% endif %} </td> diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html index bc452e0..70aac47 100644 --- a/yaksh/templates/yaksh/post_comments.html +++ b/yaksh/templates/yaksh/post_comments.html @@ -38,7 +38,7 @@ {% endif %} </strong> {{post.created_at}} - {% if user == course.creator %}<a href="{% url 'yaksh:hide_post' post.target.id post.uid %}" class="pull-right fa fa-trash"></a>{% endif %} + {% if user == course.creator or user in course.get_teachers %}<a href="{% url 'yaksh:hide_post' post.target.id post.uid %}" class="pull-right fa fa-trash"></a>{% endif %} </small> </div> @@ -77,7 +77,7 @@ </strong> </div> <div class="col-6 text-right"> - <small class="text-muted">{{comment.created_at}} {% if user == course.creator %} <a href="{% url 'yaksh:hide_comment' post.target.id comment.uid %}" class="fa fa-trash"></a>{% endif %}</small> + <small class="text-muted">{{comment.created_at}} {% if user == course.creator or user in course.get_teachers %} <a href="{% url 'yaksh:hide_comment' post.target.id comment.uid %}" class="fa fa-trash"></a>{% endif %}</small> </div> </div> <p class="card-text description">{{comment.description|safe}}</p> diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 36320a1..fe0d3b5 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1788,19 +1788,7 @@ class AnswerPaperTestCases(unittest.TestCase): """ Test get_question_answer() method of Answer Paper""" questions = self.answerpaper.questions.all() answered = self.answerpaper.get_question_answers() - for question in questions: - answers_saved = Answer.objects.filter(question=question) - error_list = [json.loads(ans.error) for ans in answers_saved] - if answers_saved: - ans = [] - err = [] - for val in answered[question]: - if val.get('answer') is not None: - ans.append(val.get('answer')) - if val.get('error_list') is not None: - err.append(val.get('error_list')) - self.assertEqual(set(ans), set(answers_saved)) - self.assertEqual(error_list, err) + self.assertEqual(list(questions), list(answered.keys())) def test_is_answer_correct(self): self.assertTrue(self.answerpaper.is_answer_correct(self.questions[0])) |