Esempio n. 1
0
def update_profrating(request):
    prof_id = int(request.POST['prof_id'])
    #get prof ratings
    prof = Professor()
    prof_rating = prof.calculate_ratings(prof_id)

    return render_to_response('content/done_profrating.html', {"prof_rating":prof_rating}, RequestContext(request))
Esempio n. 2
0
def professor(request, prof_id=None):
    if not prof_id:
        prof_id = 0
    else:
        prof_id = int(prof_id)

    prof_info = Professor.objects.get(id=prof_id)
    comment_info = Comment.objects.filter(professor_id=prof_id)

    #get prof ratings
    prof = Professor()
    prof_rating = prof.calculate_ratings(prof_id)
    
    return render_to_response('content/professor.html', {
            "prof_info":prof_info,
            "prof_rating":prof_rating,
            "comment_info":comment_info,
            "prof_id":prof_id}, context_instance=RequestContext(request))
Esempio n. 3
0
def professor(request, prof_id=None):
    if not prof_id:
        prof_id = 0
    else:
        prof_id = int(prof_id)

    prof_info = Professor.objects.get(id=prof_id)
    comment_info = Comment.objects.filter(professor_id=prof_id)
    button_activation = []
    comment_button_activation = []
    #check if this user has already recommmended prof
    if Recommendation.objects.filter(user=request.user, professor=prof_info).exists():
        button_activation.append('true;')
        button_activation.append('Empfohlen')
    else:
        button_activation.append('false;')
        button_activation.append('Empfehlen')

    #check if already voted
    if Comment.objects.filter(user_info=request.user, professor=prof_info).exists():
        comment_button_activation.append('javascript: void(0);')
        comment_button_activation.append('Gerated')
    else:
        comment_button_activation = '#rateButton';
        comment_button_activation.append('Raten')


    #check if there are facebook friends comments (only if logged in)
    friend_comment_list = []
    try:
        #loop through friends_list and check
        
        friends_list = request.session['friends_list']
        for uid in friends_list:
            # uncomment following to test condition with Can Olcer FB profile
            # uid = 1057698187
            if comment_info.filter(user_info__userfacebook__uid=uid).exists(): #if there are fb friends who commented, get their fb info and add to friends_comment_list
                #initialize
                current_user_info = {}
                current_comment = comment_info.get(user_info__userfacebook__uid=uid)
                #get the fb profile
                current_fb_profile = UserFacebook.objects.get(uid=uid)
                #get auth_user
                user = User.objects.get(id=current_fb_profile.user_id)
                #get the user profile
                current_user_profile = UserProfile.objects.get(user=user)

                #save the data needed
                #first name
                current_user_info['first_name'] = user.first_name
                #last name
                current_user_info['last_name'] = user.last_name
                #fb profile pic
                current_user_info['profile_pic'] = current_fb_profile.fb_pic_square
                #fb profile link
                current_user_info['profile_link'] = current_fb_profile.fb_profile_link
                #overall rating
                current_user_info['rating_overall'] = current_comment.rating_overall
                #clarity rating
                current_user_info['rating_clarity'] = current_comment.rating_clarity
                #interesting rating
                current_user_info['rating_interesting'] = current_comment.rating_interesting
                #easiness rating
                current_user_info['rating_easiness'] = current_comment.rating_easiness
                #niceness rating
                current_user_info['rating_niceness'] = current_comment.rating_niceness
                #review
                current_user_info['rating_review'] = current_comment.review
                #course
                current_user_info['rating_course'] = current_comment.course
                #created
                current_user_info['rating_created'] = current_comment.created

                friend_comment_list.append(current_user_info)
    except:
        pass

    
    #paginator
    paginator = Paginator(comment_info, 8)
    page = request.GET.get('page')
    try:
        comments = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        comments = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        comments = paginator.page(paginator.num_pages)

    #calculate prof ratings
    prof = Professor()
    prof_rating = prof.calculate_ratings(prof_id)
    
    return render_to_response('content/professor.html', {
            "prof_info":prof_info,
            "prof_rating":prof_rating,
            "comments":comments,
            "prof_id":prof_id,
            "friend_comment_list":friend_comment_list,
            "button_activation":button_activation,
            "comment_button_activation":comment_button_activation}, context_instance=RequestContext(request))