summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorCruiseDevice2020-09-08 15:02:22 +0530
committerankitjavalkar2020-10-08 10:40:08 +0530
commit25cb22481469f738d6aa9ed440474f34e22600aa (patch)
tree9cafb303cfc4ba8c3fb59afdd8ecbd9269d85135 /yaksh/views.py
parente4a9897685b4958efb0d5bd86f57dc1584449619 (diff)
downloadonline_test-25cb22481469f738d6aa9ed440474f34e22600aa.tar.gz
online_test-25cb22481469f738d6aa9ed440474f34e22600aa.tar.bz2
online_test-25cb22481469f738d6aa9ed440474f34e22600aa.zip
Comments feature for video lesson
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py43
1 files changed, 38 insertions, 5 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index e9730d9..803f1d6 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -2804,11 +2804,40 @@ def show_lesson(request, lesson_id, module_id, course_id):
if not learn_unit.is_prerequisite_complete(user, learn_module, course):
msg = "You have not completed previous Lesson/Quiz/Exercise"
return view_module(request, learn_module.id, course_id, msg=msg)
+
+ lesson_ct = ContentType.objects.get_for_model(learn_unit.lesson)
+ title = learn_unit.lesson.name
+ try:
+ post = Post.objects.get(
+ target_ct=lesson_ct, target_id=learn_unit.lesson.id,
+ active=True, title=title, creator=user,
+ description=f'Discussion on {title} lesson',
+ )
+ except Post.DoesNotExist:
+ post = Post.objects.create(
+ target_ct=lesson_ct, target_id=learn_unit.lesson.id,
+ active=True, title=title, creator=user,
+ description=f'Discussion on {title} lesson',
+ )
+ if request.method == "POST":
+ form = CommentForm(request.POST, request.FILES)
+ if form.is_valid():
+ new_comment = form.save(commit=False)
+ new_comment.creator = request.user
+ new_comment.post_field = post
+ new_comment.save()
+ return redirect(request.path_info)
+ else:
+ raise Http404(f'Post does not exist for lesson {title}')
+ else:
+ form = CommentForm()
+ comments = post.comment.filter(active=True)
context = {'lesson': learn_unit.lesson, 'user': user,
'course': course, 'state': "lesson", "all_modules": all_modules,
'learning_units': learning_units, "current_unit": learn_unit,
'learning_module': learn_module, 'toc': toc,
- 'contents_by_time': contents_by_time}
+ 'contents_by_time': contents_by_time,
+ 'comments': comments, 'form': form, 'post': post}
return my_render_to_response(request, 'yaksh/show_video.html', context)
@@ -3454,6 +3483,7 @@ def course_forum(request, course_id):
raise Http404('You are not enrolled in {0} course'.format(course.name))
search_term = request.GET.get('search_post')
if search_term:
+ # Fix this...
posts = course.post.get_queryset().filter(
active=True, title__icontains=search_term)
else:
@@ -3522,7 +3552,7 @@ def hide_post(request, course_id, uuid):
user = request.user
course = get_object_or_404(Course, id=course_id)
if (not course.is_creator(user) or not course.is_teacher(user)):
- raise Http404('You are not enrolled in {0} course'.format(course.name))
+ raise Http404(f'Only a course creator or a teacher can delete the post.')
post = get_object_or_404(Post, uid=uuid)
post.comment.active = False
post.active = False
@@ -3534,9 +3564,12 @@ def hide_post(request, course_id, uuid):
@email_verified
def hide_comment(request, course_id, uuid):
user = request.user
- course = get_object_or_404(Course, id=course_id)
- if (not course.is_creator(user) or not course.is_teacher(user)):
- raise Http404('You are not enrolled in {0} course'.format(course.name))
+ if course_id:
+ course = get_object_or_404(Course, id=course_id)
+ if (not course.is_creator(user) or not course.is_teacher(user)):
+ raise Http404(
+ f'Only a course creator or a teacher can delete the comments'
+ )
comment = get_object_or_404(Comment, uid=uuid)
post_uid = comment.post_field.uid
comment.active = False