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})
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})
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())
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())