Ejemplo n.º 1
0
 def create(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         obj_content_type = ContentType.objects.get_for_model(BillSegment)
         obj = Comment()
         obj.content_type = obj_content_type
         obj.user = request.user
         obj.comment = request.data['comment']
         obj.object_pk = request.data['object_pk']
         obj.site_id = settings.SITE_ID
         obj.save()
         return Response(status=201)
     elif request.data['token']:
         token = Token.objects.get(key=request.data['token'])
         obj_content_type = ContentType.objects.get_for_model(BillSegment)
         obj = Comment()
         obj.content_type = obj_content_type
         obj.user = token.user
         obj.comment = request.data['comment']
         obj.object_pk = request.data['object_id']
         obj.site_id = settings.SITE_ID
         obj.save()
         serializer = CommentsSerializer(obj)
         return JSONResponse(serializer.data, status=201)
     else:
         return Response(serializer._errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
 def create(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         obj_content_type = ContentType.objects.get_for_model(BillSegment)
         obj = Comment()
         obj.content_type = obj_content_type
         obj.user = request.user
         obj.comment = request.data['comment']
         obj.object_pk = request.data['object_pk']
         obj.site_id = settings.SITE_ID
         obj.save()
         return Response(status=201)
     elif request.data['token']:
         token = Token.objects.get(key=request.data['token'])
         obj_content_type = ContentType.objects.get_for_model(BillSegment)
         obj = Comment()
         obj.content_type = obj_content_type
         obj.user = token.user
         obj.comment = request.data['comment']
         obj.object_pk = request.data['object_id']
         obj.site_id = settings.SITE_ID
         obj.save()
         serializer = CommentsSerializer(obj)
         return JSONResponse(serializer.data, status=201)
     else:
         return Response(serializer._errors,
                         status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 3
0
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())
Ejemplo n.º 4
0
Archivo: comment.py Proyecto: ptrr/frog
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())
Ejemplo n.º 5
0
def object_detail(request, object_slug):
    
    trans_obj = TransientCandidate.objects.get(slug = object_slug)
    trans_candidate_id = trans_obj.pk
    ranked_interesting = Ranking.objects.filter(trans_candidate = trans_obj).filter(isInteresting = True)
    int_users_list = UserProfile.objects.filter(ranking = ranked_interesting)
    int_counts = len(int_users_list)
    
    if request.method == "POST":
        if request.user.is_authenticated():  
            #Save the comment if there is one.
            comment_text = request.POST.get('comment')
            if len(comment_text) > 0:
                #save the comment
                newComment = Comment()
                newComment.user = request.user
                newComment.user_name = request.user.username
                newComment.user_email = request.user.email
                newComment.user_url = UserProfile.objects.get(user=request.user).website
                newComment.comment = comment_text
                newComment.site = get_current_site(request)
                newComment.content_object = trans_obj
                newComment.save()
                    
    return render(request, 'winnow/trans_detail.html', {'object' : trans_obj,
                                                        'interesting_count': str(int_counts), 
                                                        'interesting_user_list': int_users_list})
Ejemplo n.º 6
0
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())
Ejemplo n.º 7
0
def rank(request):
    if request.method == "POST":
        form = RankingForm(request.POST)
        if form.is_valid():
            if request.user.is_authenticated():
                r = form.save(commit=False)
                r.ranker = UserProfile.objects.get(user=request.user)
                tc_id = int(request.POST.get("tc_id"))
                tc = TransientCandidate.objects.get(pk=tc_id)
                r.trans_candidate = tc
                r.save()

                # Now save the comment if there is one.
                comment_text = request.POST.get("comment")
                if len(comment_text) > 0:
                    # save the comment
                    newComment = Comment()
                    newComment.user = request.user
                    newComment.user_name = request.user.username
                    newComment.user_email = request.user.email
                    newComment.user_url = UserProfile.objects.get(user=request.user).website
                    newComment.comment = comment_text
                    newComment.site = get_current_site(request)
                    newComment.content_object = tc
                    newComment.save()

            return HttpResponseRedirect(reverse("rank"))
        else:
            print form.errors
            tc_id = int(request.POST.get("tc_id"))
            tc = TransientCandidate.objects.get(pk=tc_id)
    else:
        try:
            # Fetch any tc not ranked yet
            tc = TransientCandidate.objects.filter(dataset_id="cstar_june02_predictedreals").exclude(
                ranking=Ranking.objects.all()
            )[0]
        except IndexError:
            # Fetch any tc not ranked by the current user
            try:
                currentUser = UserProfile.objects.get(user=request.user)
                tc = TransientCandidate.objects.filter(dataset_id="cstar_june02_predictedreals").exclude(
                    ranking=Ranking.objects.filter(ranker=currentUser)
                )[0]
            except IndexError:
                tc = None

        if tc is None:
            tc_id = -1
        else:
            tc_id = tc.id

        form = RankingForm()

    return render(request, "winnow/rank.html", {"form": form, "page_rank": "selected", "tc_id": tc_id, "object": tc})
Ejemplo n.º 8
0
 def create(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         obj_content_type = ContentType.objects.get_for_model(BillSegment)
         obj = Comment()
         obj.content_type = obj_content_type
         obj.user = request.user
         obj.comment = request.data['comment']
         obj.object_pk = request.data['object_pk']
         obj.site_id = settings.SITE_ID
         obj.save()
         return Response(status=201)
     else:
         return Response(status=403)
Ejemplo n.º 9
0
def comment(request, segment_id):
    if request.user.is_authenticated() and request.method == 'POST':
        ctype = ContentType.objects.get_for_model(BillSegment)
        segment = BillSegment.objects.get(pk=segment_id)
        obj = Comment()
        obj.content_type = ctype
        obj.user = request.user
        obj.comment = request.POST.get('comment')
        obj.object_pk = segment_id
        obj.site_id = settings.SITE_ID
        obj.save()
        html = render_to_string('widget/_segment_comments.html',
                                {'segment': segment})
        return JsonResponse({'html': html,
                             'count': segment.comments.all().count()})
    else:
        msg = _("You must be logged to comment.")
        return HttpResponseForbidden(reason=msg)