コード例 #1
0
def add_comment(request, course_name):
    form = None
    if request.method == "POST":
        form = CommentForm(data=request.POST)
        if form.is_valid() and request.POST.get('bulletin_id'):
            comment = form.save(commit=False)
            comment.bulletin = Bulletin.objects.get(
                id=request.POST.get('bulletin_id'))
            comment.user = request.user
            comment.date = datetime.datetime.now()
            comment.save()

            #add notification
            Notification.create_added_comment_notification(
                request.course, comment.bulletin, comment)

            return JsonResponse({
                'success': True,
                'comment': comment.get_data()
            })
        else:
            return JsonResponse({
                'success': False,
                'error': "* This field is required."
            })
    else:
        form = CommentForm()

    return render_to_response("courses/bulletins/add_comment_form.html",
                              {'form': form})
コード例 #2
0
ファイル: views.py プロジェクト: momenezes/Atlas-LMS
def add_comment(request, course_name):
    form = None
    if request.method == "POST":
        form = CommentForm(data=request.POST)
        if form.is_valid() and request.POST.get("bulletin_id"):
            comment = form.save(commit=False)
            comment.bulletin = Bulletin.objects.get(id=request.POST.get("bulletin_id"))
            comment.user = request.user
            comment.date = datetime.datetime.now()
            comment.save()

            # add notification
            Notification.create_added_comment_notification(request.course, comment.bulletin, comment)

            return JsonResponse({"success": True, "comment": comment.get_data()})
        else:
            return JsonResponse({"success": False, "error": "* This field is required."})
    else:
        form = CommentForm()

    return render_to_response("courses/bulletins/add_comment_form.html", {"form": form})
コード例 #3
0
ファイル: tests.py プロジェクト: momenezes/Atlas-LMS
 def testCreateAddedCommentNotification(self):
     notification = Notification.create_added_comment_notification(self.course, self.bulletin, self.comment)
     self.assertTrue(self.student1.notifications.filter(pk=notification.pk).exists())
コード例 #4
0
 def testCreateAddedCommentNotification(self):
     notification = Notification.create_added_comment_notification(
         self.course, self.bulletin, self.comment)
     self.assertTrue(
         self.student1.notifications.filter(pk=notification.pk).exists())