def vote_down_on(comment, voter): try: vote = comment.votes.get(voter=voter) if vote.direction == Vote.UP: vote.delete() CommentList.get_by_comment(comment).increment() return except Vote.DoesNotExist: Vote.objects.create(direction=Vote.DOWN, voter=voter, comment=comment) CommentList.get_by_comment(comment).increment()
def vote_down_on(comment, voter): try: vote = comment.votes.get(voter=voter) if vote.direction == Vote.UP: vote.delete() CommentList.get_by_comment(comment).increment() return except Vote.DoesNotExist: Vote.objects.create(direction=Vote.DOWN, voter=voter, comment=comment) CommentList.get_by_comment(comment).increment()
def delete_comment(request): comment_id = request.POST['comment_id'] deleter = RequestContext(request)['user'] comment = Comment.objects.filter(id=comment_id).select_related('parent__children')[0] if comment.author != deleter and not deleter.is_staff: return HttpResponseForbidden('You shall not delete!') comment.deleter = deleter comment.delete_date = timezone.now() comment.promoted = False comment.seen = True comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def promote_comment(request): data = request.POST requester = RequestContext(request)['user'] if not requester.is_staff: return HttpResponseForbidden('You shall not promote!') try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') comment.promoted = True if data['value'] == 'true' else False comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def promote_comment(request): data = request.POST requester = AuroraAuthenticationBackend.get_user(AuroraAuthenticationBackend(), request.user.id) if not requester.is_staff: return HttpResponseForbidden('You shall not promote!') try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') comment.promoted = True if data['value'] == 'true' else False comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def promote_comment(request): data = request.POST requester = RequestContext(request)['user'] if not requester.is_staff: return HttpResponseForbidden('You shall not promote!') try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') comment.promoted = True if data['value'] == 'true' else False comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def delete_comment(request): comment_id = request.POST['comment_id'] deleter = RequestContext(request)['user'] comment = Comment.objects.filter( id=comment_id).select_related('parent__children')[0] if comment.author != deleter and not deleter.is_staff: return HttpResponseForbidden('You shall not delete!') comment.deleter = deleter comment.delete_date = timezone.now() comment.promoted = False comment.seen = True comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def promote_comment(request): data = request.POST requester = AuroraAuthenticationBackend.get_user( AuroraAuthenticationBackend(), request.user.id) if not requester.is_staff: return HttpResponseForbidden('You shall not promote!') try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') comment.promoted = True if data['value'] == 'true' else False comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def bookmark_comment(request): data = request.POST requester = RequestContext(request)['user'] try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') if data['bookmark'] == 'true': comment.bookmarked_by.add(requester) else: comment.bookmarked_by.remove(requester) comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def bookmark_comment(request): data = request.POST requester = AuroraAuthenticationBackend.get_user(AuroraAuthenticationBackend(), request.user.id) try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') if data['bookmark'] == 'true': comment.bookmarked_by.add(requester) else: comment.bookmarked_by.remove(requester) comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def bookmark_comment(request): data = request.POST requester = RequestContext(request)['user'] try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') if data['bookmark'] == 'true': comment.bookmarked_by.add(requester) else: comment.bookmarked_by.remove(requester) comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def bookmark_comment(request): data = request.POST requester = AuroraAuthenticationBackend.get_user( AuroraAuthenticationBackend(), request.user.id) try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') if data['bookmark'] == 'true': comment.bookmarked_by.add(requester) else: comment.bookmarked_by.remove(requester) comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def edit_comment(request): data = request.POST context = RequestContext(request) requester = context['user'] try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') if comment.author != requester: return HttpResponseForbidden('You shall not edit!') text = data['text'] if text == '': return HttpResponse('') comment.text = data['text'] comment.edited_date = timezone.now() comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def edit_comment(request): data = request.POST context = RequestContext(request) requester = context['user'] try: comment = Comment.objects.get(id=data['comment_id']) except Comment.DoesNotExist: return HttpResponse('') if comment.author != requester: return HttpResponseForbidden('You shall not edit!') text = data['text'] if text == '': return HttpResponse('') comment.text = data['text'] comment.edited_date = timezone.now() comment.save() CommentList.get_by_comment(comment).increment() return HttpResponse('')
def create_comment(form, request): if not form.is_valid(): raise ValidationError('The submitted form was not valid') homeURL = form.cleaned_data['uri'] context = RequestContext(request) user = context['user'] ref_type_id = form.cleaned_data['reference_type_id'] ref_obj_id = form.cleaned_data['reference_id'] ref_obj_model = ContentType.objects.get_for_id(ref_type_id).model_class() ref_obj = ref_obj_model.objects.get(id=ref_obj_id) visibility = form.cleaned_data['visibility'] parent_comment_id = form.cleaned_data.get('parent_comment', None) if parent_comment_id is not None: try: parent_comment = Comment.objects.get(id=parent_comment_id) except ObjectDoesNotExist: parent_comment = None else: parent_comment = None comment = Comment.objects.create(text=form.cleaned_data['text'], author=user, content_object=ref_obj, parent=parent_comment, post_date=timezone.now(), visibility=visibility) if comment.author.is_staff or comment.visibility == Comment.PRIVATE: comment.seen = True comment.save() comment_list = CommentList.get_by_comment(comment) if comment_list.uri is None or 'evaluation' in comment_list.uri: comment_list.uri = form.cleaned_data['uri'] comment_list.save() comment_list.increment() if comment.visibility == Comment.PRIVATE: return if parent_comment is None: return if parent_comment.author == comment.author: return if comment.visibility == Comment.STAFF and not parent_comment.author.is_staff: return course_short_title = form.cleaned_data['course_short_title'] if course_short_title != "": course = Course.get_or_raise_404(course_short_title) link = comment_list.uri + '#comment_' + str(parent_comment.id) else: course = None link = "" text = comment.author.nickname[:15] + ': ' if len(comment.text) > 50: text += comment.text[:47] + "..." else: text += comment.text[:50] obj, created = Notification.objects.get_or_create( user=parent_comment.author, course=course, text=text, image_url=comment.author.avatar.url, link=link ) if not created: obj.creation_time = timezone.now() obj.read = False obj.save()
def create_comment(form, request): if not form.is_valid(): raise ValidationError('The submitted form was not valid') context = RequestContext(request) user = context['user'] ref_type_id = form.cleaned_data['reference_type_id'] ref_obj_id = form.cleaned_data['reference_id'] ref_obj_model = ContentType.objects.get_for_id(ref_type_id).model_class() ref_obj = ref_obj_model.objects.get(id=ref_obj_id) visibility = form.cleaned_data['visibility'] parent_comment_id = form.cleaned_data.get('parent_comment', None) if parent_comment_id is not None: try: parent_comment = Comment.objects.get(id=parent_comment_id) except ObjectDoesNotExist: parent_comment = None else: parent_comment = None comment = Comment.objects.create(text=form.cleaned_data['text'], author=user, content_object=ref_obj, parent=parent_comment, post_date=timezone.now(), visibility=visibility) if comment.author.is_staff or comment.visibility == Comment.PRIVATE: comment.seen = True comment.save() comment_list = CommentList.get_by_comment(comment) if comment_list.uri is None or 'evaluation' in comment_list.uri: comment_list.uri = form.cleaned_data['uri'] comment_list.save() comment_list.increment() if comment.visibility == Comment.PRIVATE: return if parent_comment is None: return if parent_comment.author == comment.author: return if comment.visibility == Comment.STAFF and not parent_comment.author.is_staff: return course_short_title = form.cleaned_data['course_short_title'] if course_short_title != "": course = Course.get_or_raise_404(course_short_title) link = comment_list.uri + '#comment_' + str(parent_comment.id) else: course = None link = "" text = comment.author.nickname[:15] + ': ' if len(comment.text) > 50: text += comment.text[:47] + "..." else: text += comment.text[:50] obj, created = Notification.objects.get_or_create( user=parent_comment.author, course=course, text=text, image_url=comment.author.avatar.url, link=link) if not created: obj.creation_time = timezone.now() obj.read = False obj.save()