def learning_lesson(request,lesson_id): if not request.user.is_staff: lesson = get_object_or_404(Lesson,pk=lesson_id,subject__course__status__name__in=["published","evaluation period","building"]) else: lesson = get_object_or_404(Lesson,pk=lesson_id) enrrollment = lesson.subject.course.enrollments.filter(user_id=request.user.id,active=True) if not enrrollment and lesson.subject.course.get_owner_id() != request.user.id and not request.user.is_staff: messages.warning(request,_('You are not enrroled in that course: ')+lesson.subject.course.title) return HttpResponseRedirect(reverse('elearning.views.view_course', args=(lesson.subject.course.slug,))) else: comments = Comment.objects.filter(lesson_id=lesson.id,parent_comment=None).order_by('-created_at') if request.POST: comment_form = CommentForm(request.POST) if comment_form.is_valid(): comment = comment_form.save(commit=False) comment.user_id = request.user.id comment.created_at = datetime.now() comment.lesson_id = lesson_id comment.save() messages.success(request,_('Comment send sucesfully')) return HttpResponseRedirect(reverse('elearning.views.learning_lesson', args=(lesson_id,))) else: comment_form = CommentForm() context = {'lesson':lesson,'comments':comments,'comment_form':comment_form,'enrrolled':True} if lesson.subject.course.get_owner_id() == request.user.id: context = {'lesson':lesson,'comments':comments,'comment_form':comment_form,'enrrolled':False,'is_teacher':True} return render_to_response('elearning/course/learning_lesson.html',context,context_instance = RequestContext(request))
def reply_comment(request,lesson_id,parent_comment_id): lesson = get_object_or_404(Lesson,pk=lesson_id,subject__course__status__name__in=["published","evaluation period","building"]) enrrollment = lesson.subject.course.enrollments.filter(user_id=request.user.id,active=True) if not enrrollment and lesson.subject.course.get_owner_id() != request.user.id: messages.warning(request,_('You are not enrroled in that course: ')+lesson.subject.course.title) return HttpResponseRedirect(reverse('elearning.views.view_course', args=(lesson.subject.course.slug,))) else: if request.POST: comment_form = CommentForm(request.POST) if comment_form.is_valid(): comment = comment_form.save(commit=False) comment.user_id = request.user.id comment.created_at = datetime.now() comment.parent_comment_id = parent_comment_id comment.lesson_id = lesson_id comment.save() messages.success(request,_('Reply sucesfully')) return HttpResponseRedirect(reverse('elearning.views.learning_lesson', args=(lesson_id,))) else: reply_form = CommentForm() context = {'reply_form':reply_form,'lesson_id':lesson_id,'parent_comment_id':parent_comment_id} return render_to_response('elearning/course/comments/reply_form.html',context,context_instance = RequestContext(request))