|
|
|
|
@ -1,10 +1,10 @@ |
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.template import loader |
|
|
|
|
from django.views.generic import View, DetailView, ListView |
|
|
|
|
from django.template import loader, Context, Template |
|
|
|
|
from django.views.generic import View, CreateView, DetailView, ListView |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
from django.views.decorators.http import require_http_methods |
|
|
|
|
from .models import Course, Like, Lesson |
|
|
|
|
from .models import Course, Like, Lesson, CourseComment, LessonComment |
|
|
|
|
from .filters import CourseFilter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ def likes(request, course_id): |
|
|
|
|
return JsonResponse({ |
|
|
|
|
'success': False, |
|
|
|
|
'errors': ['Course with id f{cource_id} not found'] |
|
|
|
|
}) |
|
|
|
|
}, status=400) |
|
|
|
|
else: |
|
|
|
|
course_user_likes = course.likes.filter(user=request.user) |
|
|
|
|
if course_user_likes.exists(): |
|
|
|
|
@ -37,6 +37,55 @@ def likes(request, course_id): |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@csrf_exempt |
|
|
|
|
@require_http_methods(['POST']) |
|
|
|
|
def coursecomment(request, course_id): |
|
|
|
|
try: |
|
|
|
|
course = Course.objects.get(id=course_id) |
|
|
|
|
except Course.DoesNotExist: |
|
|
|
|
return JsonResponse({ |
|
|
|
|
'success': False, |
|
|
|
|
'errors': ['Course with id f{cource_id} not found'] |
|
|
|
|
}, status=400) |
|
|
|
|
else: |
|
|
|
|
reply_to = request.POST.get('reply_id', None) |
|
|
|
|
comment = request.POST.get('comment', '') |
|
|
|
|
if not comment: |
|
|
|
|
return JsonResponse({ |
|
|
|
|
'success': False, |
|
|
|
|
'errors': ['Comment can not be empty'] |
|
|
|
|
}, status=400) |
|
|
|
|
|
|
|
|
|
if not reply_to: |
|
|
|
|
coursecomment = CourseComment.objects.create( |
|
|
|
|
author=request.user, |
|
|
|
|
content=comment, |
|
|
|
|
course=course, |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
try: |
|
|
|
|
_coursecomment = CourseComment.objects.get(id=reply_to) |
|
|
|
|
except CourseComment.DoesNotExist: |
|
|
|
|
return JsonResponse({ |
|
|
|
|
'success': False, |
|
|
|
|
'errors': ['CourseComment with id f{reply_to} not found'] |
|
|
|
|
}, status=400) |
|
|
|
|
else: |
|
|
|
|
coursecomment = CourseComment.objects.create( |
|
|
|
|
author=request.user, |
|
|
|
|
content=comment, |
|
|
|
|
course=course, |
|
|
|
|
parrent=_coursecomment, |
|
|
|
|
) |
|
|
|
|
ctx = {'node': coursecomment} |
|
|
|
|
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' |
|
|
|
|
|