summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorankitjavalkar2020-10-08 16:12:01 +0530
committerGitHub2020-10-08 16:12:01 +0530
commitaaf8f36bce5fff6c36bcbac3fa038ae99304b73f (patch)
treeb00c763f1ef38a3abf43f4f337d97f67ae04337a /yaksh/models.py
parentf61351f6a4e7a6150e66ca39f23ac14f9a60de96 (diff)
parent78eb6dc42e73551c2bb9972e53a2d7dd3b81e7d7 (diff)
downloadonline_test-aaf8f36bce5fff6c36bcbac3fa038ae99304b73f.tar.gz
online_test-aaf8f36bce5fff6c36bcbac3fa038ae99304b73f.tar.bz2
online_test-aaf8f36bce5fff6c36bcbac3fa038ae99304b73f.zip
Merge pull request #778 from ankitjavalkar/cruise-comments-under-video
[Rebased] Comments under video lesson
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index b172e79..da2327c 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -42,6 +42,7 @@ from django.template import Context, Template
from django.conf import settings
from django.forms.models import model_to_dict
from django.db.models import Count
+
# Local Imports
from yaksh.code_server import (
submit, get_result as get_result_from_code_server
@@ -1101,6 +1102,25 @@ class Course(models.Model):
learning_units.extend(module.get_learning_units())
return learning_units
+ def get_lesson_posts(self):
+ learning_units = self.get_learning_units()
+ comments = []
+ for unit in learning_units:
+ if unit.lesson is not None:
+ lesson_ct = ContentType.objects.get_for_model(unit.lesson)
+ title = unit.lesson.name
+ try:
+ post = Post.objects.get(
+ target_ct=lesson_ct,
+ target_id=unit.lesson.id,
+ active=True, title=title
+ )
+ except Post.DoesNotExist:
+ post = None
+ if post is not None:
+ comments.append(post)
+ return comments
+
def remove_trial_modules(self):
learning_modules = self.learning_module.all()
for module in learning_modules:
@@ -2749,12 +2769,20 @@ class ForumBase(models.Model):
image = models.ImageField(upload_to=get_image_dir, blank=True,
null=True, validators=[validate_image])
active = models.BooleanField(default=True)
+ anonymous = models.BooleanField(default=False)
class Post(ForumBase):
title = models.CharField(max_length=200)
- course = models.ForeignKey(Course,
- on_delete=models.CASCADE, related_name='post')
+ target_ct = models.ForeignKey(ContentType,
+ blank=True,
+ null=True,
+ related_name='target_obj',
+ on_delete=models.CASCADE)
+ target_id = models.PositiveIntegerField(null=True,
+ blank=True,
+ db_index=True)
+ target = GenericForeignKey('target_ct', 'target_id')
def __str__(self):
return self.title