def authentication_info(request):
    '''
    This context processor adds all the user info into the page that is needed for the
    login form and signup form that appear in the header of every page, as well as other
    basic information about the state of the current user.

    This way the code is DRY-er: we don't need to copy these fields into every page handler.
    '''
    profile = Profile.get(request.user)
    return {
        'login_form': AuthenticationForm(),
        'signup_form': CreateAccountForm(),
        'username': request.user.username,
        'is_authenticated': request.user.is_active and request.user.is_authenticated(),
        'is_admin': profile.user.is_superuser if profile is not None else None
    }
Exemple #2
0
def edit_review(request, review_id):
    if request.method == 'POST':
        new_title = request.POST['new_review_title']
        new_body = request.POST['new_review_body']
        current_user = Profile.get(request.user)
        current_movie = Movie.objects.filter(m_id=review_id)[0]
        review = Review.objects.filter(user=current_user, movie=current_movie)[0]

        review.approved = False
        review.review_title = new_title
        review.review_body = new_body
        review.date_edited = datetime.today()
        review.save()

        return HttpResponseRedirect(request.META['HTTP_REFERER'])   
    else:
        return HttpResponse("Unknown edit review request")
Exemple #3
0
def edit_review(request, review_id):
    if request.method == 'POST':
        new_title = request.POST['new_review_title']
        new_body = request.POST['new_review_body']
        current_user = Profile.get(request.user)
        current_movie = Movie.objects.filter(m_id=review_id)[0]
        review = Review.objects.filter(user=current_user,
                                       movie=current_movie)[0]

        review.approved = False
        review.review_title = new_title
        review.review_body = new_body
        review.date_edited = datetime.today()
        review.save()

        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    else:
        return HttpResponse("Unknown edit review request")
Exemple #4
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 #5
0
def authentication_info(request):
    '''
    This context processor adds all the user info into the page that is needed for the
    login form and signup form that appear in the header of every page, as well as other
    basic information about the state of the current user.

    This way the code is DRY-er: we don't need to copy these fields into every page handler.
    '''
    profile = Profile.get(request.user)
    return {
        'login_form':
        AuthenticationForm(),
        'signup_form':
        CreateAccountForm(),
        'username':
        request.user.username,
        'is_authenticated':
        request.user.is_active and request.user.is_authenticated(),
        'is_admin':
        profile.user.is_superuser if profile is not None else None
    }
Exemple #6
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'])