Exemple #1
0
def rate(request, rating_id, approve):
    target_user = Profile.find(request.GET['review_of'])
    target_movie = Movie.objects.filter(m_id=int(rating_id))[0]
    review_of = Review.objects.filter(movie=target_movie, user=target_user)[0]
    user = Profile.get(request.user)

    already_exists = ReviewRating.objects.filter(review=review_of, user=user)
    """for entry in already_exists:
        entry.delete()"""

    if not len(already_exists):
        review_rating = ReviewRating(review=review_of, user=user, vote=approve)
        review_rating.save()
    else:
        if already_exists[0].vote == int(approve):
            already_exists[0].delete()
        else:
            already_exists[0].vote = approve
            already_exists[0].save()

    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Exemple #2
0
def rate(request, rating_id, approve):
    target_user = Profile.find(request.GET['review_of'])
    target_movie = Movie.objects.filter(m_id=int(rating_id))[0]
    review_of = Review.objects.filter(movie=target_movie, user=target_user)[0]
    user = Profile.get(request.user)

    already_exists = ReviewRating.objects.filter(review=review_of, user=user)

    """for entry in already_exists:
        entry.delete()"""
    
    if not len(already_exists):
        review_rating = ReviewRating(review=review_of, user=user, vote=approve)
        review_rating.save()
    else:
        if already_exists[0].vote == int(approve):
            already_exists[0].delete()
        else:
            already_exists[0].vote = approve
            already_exists[0].save()
    
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Exemple #3
0
 def test_find_user_when_does_not_exist(self):
     profile = Profile.create_new_user('testuser1', '*****@*****.**',
                                       'password1', date.today())
     profile_found = Profile.find('auserthatdoesntexist')
     self.assertTrue(profile_found is None)
Exemple #4
0
 def test_find_user_when_exists(self):
     profile = Profile.create_new_user('testuser1', '*****@*****.**',
                                       'password1', date.today())
     profile_found = Profile.find('testuser1')
     self.assertTrue(profile_found == profile)
Exemple #5
0
 def test_find_user_when_does_not_exist(self):
     profile = Profile.create_new_user('testuser1', '*****@*****.**', 'password1', date.today())
     profile_found = Profile.find('auserthatdoesntexist')
     self.assertTrue(profile_found is None)
Exemple #6
0
 def test_find_user_when_exists(self):
     profile = Profile.create_new_user('testuser1', '*****@*****.**', 'password1', date.today())
     profile_found = Profile.find('testuser1')
     self.assertTrue(profile_found == profile)