Exemplo n.º 1
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.º 2
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})