def newComment(request): nickname=request.COOKIES['nickname'] accessToken=request.COOKIES['accessToken'] if authenticate(nickname, accessToken): comment=Comment() commenter=CubeUser.objects.get(nickname=nickname) comment.commenter=commenter comment.comment=request.POST['comment'] id=request.POST['viz'] viz=Viz.objects.get(pk=id) comment.viz=viz comment.save() response='{ "status":"ok", "nickname":"%s"}' % nickname else: response='{ "status":"error", "error":"user is not authenticated"}' return HttpResponse(response, content_type="application/json")
def newComment(request): nickname = request.COOKIES['nickname'] accessToken = request.COOKIES['accessToken'] if authenticate(nickname, accessToken): comment = Comment() commenter = CubeUser.objects.get(nickname=nickname) comment.commenter = commenter comment.comment = request.POST['comment'] id = request.POST['viz'] viz = Viz.objects.get(pk=id) comment.viz = viz comment.save() response = '{ "status":"ok", "nickname":"%s"}' % nickname else: response = '{ "status":"error", "error":"user is not authenticated"}' return HttpResponse(response, content_type="application/json")
def log_status_update(status_display_name, commenter): """ :param status_display_name: New status display name :param commenter: The commenter who updated the status :return: A new comment instance """ now = datetime.now() datetime_string = now.strftime("at %H:%M:%S hrs on %-d %b, %Y") full_name = commenter.full_name text = f'Status changed to {status_display_name} by {full_name} {datetime_string}' comment = Comment() comment.text = text comment.commenter = commenter comment.save() return comment