def post(request): """Returns a serialized object""" data = json.loads(request.body)["body"] guid = data.get("guid", None) res = Result() if guid: obj = getObjectsFromGuids([guid])[0] comment = Comment() comment.comment = data.get("comment", "No comment") comment.user = request.user comment.user_name = request.user.get_full_name() comment.user_email = request.user.email comment.content_object = obj # For our purposes, we never have more than one site comment.site_id = 1 comment.save() obj.comment_count += 1 obj.save() emailComment(comment, obj, request) res.append(commentToJson(comment)) return JsonResponse(res.asDict())
def post(request): """Returns a serialized object""" data = request.POST or json.loads(request.body)['body'] guid = data.get('guid', None) res = Result() if guid: obj = getObjectsFromGuids([guid,])[0] comment = Comment() comment.comment = data.get('comment', 'No comment') comment.user = request.user comment.user_name = request.user.get_full_name() comment.user_email = request.user.email comment.content_object = obj comment.site_id = get_current_site(request).id comment.save() obj.comment_count += 1 obj.save() emailComment(comment, obj, request) res.append(commentToJson(comment)) else: res.isError = True res.message = "No guid provided" return JsonResponse(res.asDict())
def commentList(request): """Returns a rendered list of comments :returns: html """ if request.method == 'POST': return post(request) comments = [] guid = request.GET.get('guid', None) id = request.GET.get('id', 0) if guid: obj = getObjectsFromGuids([guid])[0] if obj.AssetType == 1: model = 'image' else: model = 'video' contentType = ContentType.objects.get(app_label="frog", model=model) comments = Comment.objects.filter(object_pk=obj.id, content_type=contentType) if request.GET.get('json'): res = Result() for comment in comments: res.append(commentToJson(comment)) return JsonResponse(res.asDict()) return render(request, 'frog/comment_list.html', {'comments': comments, 'guid': guid, 'id': id})
def post(request): """Returns a serialized object""" data = request.POST or json.loads(request.body)['body'] guid = data.get('guid', None) res = Result() if guid: obj = getObjectsFromGuids([guid,])[0] comment = Comment() comment.comment = data.get('comment', 'No comment') comment.user = request.user comment.user_name = request.user.get_full_name() comment.user_email = request.user.email comment.content_object = obj comment.site_id = get_current_site(request).id comment.save() obj.comment_count += 1 obj.save() emailComment(comment, obj, request) res.append(commentToJson(comment)) return JsonResponse(res.asDict())
def get(request, obj_id): """Returns a serialized object :param obj_id: ID of comment object :type obj_id: int :returns: json """ res = Result() c = Comment.objects.get(pk=obj_id) res.append(commentToJson(c)) return JsonResponse(res.asDict())
def put(request, obj_id): """Updates the content of a comment :param obj_id: ID of comment object :type obj_id: int :returns: json """ res = Result() c = Comment.objects.get(pk=obj_id) data = json.loads(request.body)["body"] content = data.get("comment", None) if content: c.comment = content c.save() res.append(commentToJson(c)) return JsonResponse(res.asDict())
def put(request, obj_id): """Updates the content of a comment :param obj_id: ID of comment object :type obj_id: int :returns: json """ res = Result() c = Comment.objects.get(pk=obj_id) content = request.PUT.get('comment', None) if content: c.comment = content c.save() res.append(commentToJson(c)) res.isSuccess = True else: res.isError = True res.message = "No comment provided" return JsonResponse(res)
def put(request, obj_id): """Updates the content of a comment :param obj_id: ID of comment object :type obj_id: int :returns: json """ res = Result() c = Comment.objects.get(pk=obj_id) data = request.PUT or json.loads(request.body)['body'] content = data.get('comment', None) if content: c.comment = content c.save() res.append(commentToJson(c)) else: res.isError = True res.message = "No comment provided" return JsonResponse(res.asDict())
def commentList(request): """Returns a rendered list of comments :returns: html """ if request.method == "POST": return post(request) res = Result() comments = [] guid = request.GET.get("guid", None) if guid: obj = getObjectsFromGuids([guid]) if obj: obj = obj[0] if obj.AssetType == Image.AssetType: model = "image" elif obj.AssetType == Video.AssetType: model = "video" elif obj.AssetType == Group.AssetType: model = "group" elif obj.AssetType == Marmoset.AssetType: model = "marmoset" else: model = None if model: contenttype = ContentType.objects.get(app_label="frog", model=model) comments = Comment.objects.filter(object_pk=obj.id, content_type=contenttype) else: res.isError = True res.message = "Invalid object, could not lookup comments for {}".format( guid) for comment in comments: res.append(commentToJson(comment)) return JsonResponse(res.asDict())
def commentList(request): """Returns a rendered list of comments :returns: html """ if request.method == 'POST': return post(request) comments = [] guid = request.GET.get('guid', None) if guid: obj = getObjectsFromGuids([guid])[0] if obj.AssetType == 1: model = 'image' else: model = 'video' contenttype = ContentType.objects.get(app_label="frog", model=model) comments = Comment.objects.filter(object_pk=obj.id, content_type=contenttype) res = Result() for comment in comments: res.append(commentToJson(comment)) return JsonResponse(res.asDict())