summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorCruiseDevice2020-09-08 15:02:22 +0530
committerankitjavalkar2020-10-08 10:40:08 +0530
commit25cb22481469f738d6aa9ed440474f34e22600aa (patch)
tree9cafb303cfc4ba8c3fb59afdd8ecbd9269d85135 /yaksh
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')
-rw-r--r--yaksh/templates/yaksh/show_video.html36
-rw-r--r--yaksh/views.py43
2 files changed, 74 insertions, 5 deletions
diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html
index 9e9d0b4..76a48d4 100644
--- a/yaksh/templates/yaksh/show_video.html
+++ b/yaksh/templates/yaksh/show_video.html
@@ -227,6 +227,42 @@
</div>
</div>
{% endif %}
+ {% if comments %}
+ {% for comment in comments %}
+ <div class="card mb-2">
+ <div class="card-body p-3">
+ <div class="row mb-3">
+ <div class="col-6">
+ <strong class="text-muted">{{comment.creator.username}}</strong>
+ </div>
+ <div class="col-6 text-right">
+ <small class="text-muted">{{comment.created_at}} {% if user.profile.is_moderator %} <a href="{% url 'yaksh:hide_comment' course.id comment.uid %}" class="btn btn-danger">Delete</a>{% endif %}</small>
+ </div>
+ </div>
+ <p class="card-text description">{{comment.description}}</p>
+ <div>
+ {% if comment.image %}
+ <a href="{{comment.image.url}}" target="_blank">
+ <center><img src="{{comment.image.url}}" class="comment_image thumbnail" alt=""></center>
+ </a>
+ {% endif %}
+ </div>
+ </div>
+ </div>
+ {% endfor %}
+ {% endif %}
+ {% if state == 'lesson' %}
+ <div>
+ <b><u>Add comment:</u></b>
+ <form action="" method="POST" enctype='multipart/form-data'>
+ <div class="form-group">
+ {% csrf_token %}
+ {{form}}
+ </div>
+ <input type="submit" value="Submit" class="btn btn-success">
+ </form>
+ </div>
+ {% endif %}
</div>
</div>
<div id="dialog"></div>
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