コード例 #1
0
ファイル: views.py プロジェクト: nadrane/sparestub-public
def update_question(request, username, question_id):
    """
    Update a single answer for a particular profile question of a particular user
    """
    profile = UserProfile.get_user_profile_from_username(username)
    # Make sure that the profile exists
    if profile:
        user = profile.user
    else:
        return form_failure_notification('User does not exist')

    # Make sure that a user is only able to update his profile and nobody else's.
    if request.user != user:
        return form_failure_notification('Uh oh! Something went wrong!')

    if request.method == 'POST':
        profile_answer_form = ProfileAnswerForm(request.POST)
        if profile_answer_form.is_valid():
            new_answer = request.POST.get('answer', '')

            profile_answer = ProfileAnswer.get_answer(user, ProfileQuestion.objects.get(id=question_id))
            profile_answer.answer = new_answer
            profile_answer.save()
            return ajax_http(form_success_notification('Question successfully updated'))
        else:
            return ajax_http(form_failure_notification('Answer too long'))
コード例 #2
0
def update_question(request, username, question_id):
    """
    Update a single answer for a particular profile question of a particular user
    """
    profile = UserProfile.get_user_profile_from_username(username)
    # Make sure that the profile exists
    if profile:
        user = profile.user
    else:
        return form_failure_notification('User does not exist')

    # Make sure that a user is only able to update his profile and nobody else's.
    if request.user != user:
        return form_failure_notification('Uh oh! Something went wrong!')

    if request.method == 'POST':
        profile_answer_form = ProfileAnswerForm(request.POST)
        if profile_answer_form.is_valid():
            new_answer = request.POST.get('answer', '')

            profile_answer = ProfileAnswer.get_answer(
                user, ProfileQuestion.objects.get(id=question_id))
            profile_answer.answer = new_answer
            profile_answer.save()
            return ajax_http(
                form_success_notification('Question successfully updated'))
        else:
            return ajax_http(form_failure_notification('Answer too long'))
コード例 #3
0
ファイル: views.py プロジェクト: nadrane/sparestub-public
def view_profile(request, username):
    # Look up the user record who corresponds to this profile
    profile = UserProfile.get_user_profile_from_username(username)
    if profile:
        user = profile.user
    else:
        raise Http404('The username {} does not exist'.format(username))

    # If the user looking at this profile is its owner, then we want to render a couple edit buttons
    if request.user == user:
        is_owner = True
    else:
        is_owner = False

    user_location = user.location

    most_recent_review = user.most_recent_review()

    user_info = {'name': user,
                 'age': user.age(),
                 'city': user_location.city,
                 'state': user_location.state,
                 'rating': user.rating,
                 'username': username,
                 }

    try:
        user_info['profile_picture'] = user.profile_picture
    except ObjectDoesNotExist:
        pass

    if most_recent_review:
        reviewer_location = most_recent_review.reviewer.location
        reviewer_city, reviewer_state = reviewer_location.city, reviewer_location.state
        most_recent_review_info = {'name': most_recent_review.reviewer.get_short_name(),
                                   'age': most_recent_review.reviewer.age(),
                                   'city': reviewer_city,
                                   'state': reviewer_state,
                                   'contents': most_recent_review.contents,
                                   'rating': most_recent_review.rating
                                   }
    else:
        most_recent_review_info = None

    # Get the profile questions and the user's answers, if they exist.
    profile_questions = ProfileQuestion.objects.all()
    question_answer_pairs = ((ProfileAnswer.get_answer(user, profile_question), profile_question)
                             for profile_question in profile_questions)

    return render(request,
                  'user_profile/view_profile.html',
                  {'user_info': user_info,
                   'is_owner': is_owner,
                   'question_answer_pairs': question_answer_pairs,
                   'most_recent_review_info': most_recent_review_info,
                   'form_settings': profile_answer_form_settings,
                   },
                  content_type='text/html',
                  )
コード例 #4
0
def view_profile(request, username):
    # Look up the user record who corresponds to this profile
    profile = UserProfile.get_user_profile_from_username(username)
    if profile:
        user = profile.user
    else:
        raise Http404('The username {} does not exist'.format(username))

    # If the user looking at this profile is its owner, then we want to render a couple edit buttons
    if request.user == user:
        is_owner = True
    else:
        is_owner = False

    user_location = user.location

    most_recent_review = user.most_recent_review()

    user_info = {
        'name': user,
        'age': user.age(),
        'city': user_location.city,
        'state': user_location.state,
        'rating': user.rating,
        'username': username,
    }

    try:
        user_info['profile_picture'] = user.profile_picture
    except ObjectDoesNotExist:
        pass

    if most_recent_review:
        reviewer_location = most_recent_review.reviewer.location
        reviewer_city, reviewer_state = reviewer_location.city, reviewer_location.state
        most_recent_review_info = {
            'name': most_recent_review.reviewer.get_short_name(),
            'age': most_recent_review.reviewer.age(),
            'city': reviewer_city,
            'state': reviewer_state,
            'contents': most_recent_review.contents,
            'rating': most_recent_review.rating
        }
    else:
        most_recent_review_info = None

    # Get the profile questions and the user's answers, if they exist.
    profile_questions = ProfileQuestion.objects.all()
    question_answer_pairs = ((ProfileAnswer.get_answer(user, profile_question),
                              profile_question)
                             for profile_question in profile_questions)

    return render(
        request,
        'user_profile/view_profile.html',
        {
            'user_info': user_info,
            'is_owner': is_owner,
            'question_answer_pairs': question_answer_pairs,
            'most_recent_review_info': most_recent_review_info,
            'form_settings': profile_answer_form_settings,
        },
        content_type='text/html',
    )