LIL-120. Add lesson comments view

remotes/origin/hasaccess
Ivlev Denis 8 years ago
parent 4bba7763f3
commit f0be7241b5
  1. 49
      apps/course/views.py
  2. 2
      project/urls.py

@ -87,6 +87,55 @@ def coursecomment(request, course_id):
})
@login_required
@csrf_exempt
@require_http_methods(['POST'])
def lessoncomment(request, Lesson):
try:
lesson = Lesson.objects.get(id=lesson_id)
except Lesson.DoesNotExist:
return JsonResponse({
'success': False,
'errors': ['Lesson with id f{lesson_id} not found']
}, status=400)
else:
reply_to = request.POST.get('reply_id', 0)
comment = request.POST.get('comment', '')
if not comment:
return JsonResponse({
'success': False,
'errors': ['Comment can not be empty']
}, status=400)
if not int(reply_to):
lessoncomment = LessonComment.objects.create(
author=request.user,
content=comment,
course=course,
)
else:
try:
_lessoncomment = LessonComment.objects.get(id=reply_to)
except LessonComment.DoesNotExist:
return JsonResponse({
'success': False,
'errors': ['CourseComment with id f{reply_to} not found']
}, status=400)
else:
lessoncomment = LessonComment.objects.create(
author=request.user,
content=comment,
course=course,
parent=_lessoncomment,
)
ctx = {'node': lessoncomment, 'user': request.user}
html = loader.render_to_string('course/blocks/comment.html', ctx)
return JsonResponse({
'success': True,
'comment': html,
})
class CourseView(DetailView):
model = Course
context_object_name = 'course'

@ -21,6 +21,7 @@ from django.conf import settings
from apps.course.views import (
CoursesView, likes, coursecomment,
CourseView, LessonView, SearchView,
lessoncomment,
)
from apps.user.views import UserView
@ -32,6 +33,7 @@ urlpatterns = [
path('course/<int:course_id>/like', likes, name='likes'),
path('course/<int:course_id>/comment', coursecomment, name='coursecomment'),
path('lesson/<int:pk>/', LessonView.as_view(), name='lesson'),
path('lesson/<int:lesson_id>/comment', lessoncomment, name='lessoncomment'),
path('search/', SearchView.as_view(), name='search'),
path('user/<int:pk>/', UserView.as_view(), name='user'),
path('', TemplateView.as_view(template_name="templates/lilcity/main.html"), name='index'),

Loading…
Cancel
Save