Exemplo n.º 1
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())
Exemplo n.º 2
0
Arquivo: comment.py Projeto: 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())
Exemplo n.º 3
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})
Exemplo n.º 4
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())
Exemplo n.º 5
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})