예제 #1
0
            def get_request_information():
                """
                Grab a request record for this ticket/user combo if one exists
                First we need to determine who the requester would have been.
                Our inbox viewer might be a seller or a buyer, but the request can only be made by a buyer.
                """
                user_request, request_status, request_expiration = None, None, None
                if ticket.poster == user:
                    user_request = Request.get_last_request(other_user, ticket)
                     # The user viewing the inbox did not request this ticket. He is the seller.
                    is_requester = False if user_request else None
                elif ticket.poster == other_user:
                    user_request = Request.get_last_request(user, ticket)
                    # The user viewing the inbox did request this ticket. He is the buyer.
                    is_requester = True if user_request else None
                if user_request:
                    request_status = user_request.status
                    request_expiration = user_request.calculate_expiration_datetime()

                return request_status, is_requester, request_expiration
예제 #2
0
def view_ticket(request, username, ticket_id):
    """
    View the details for a particular ticket. This view allows us to message the user or buy the ticket from him.
    """
    user = request.user

     # Look up the user record who corresponds to this profile
    profile = UserProfile.get_user_profile_from_username(username)
    if profile:
        profile_user = profile.user
    else:
        raise Http404('The username {} does not exist.'.format(username))

    # Make sure that ticket exists
    try:
        ticket = Ticket.objects.get(pk=ticket_id)
    except Ticket.DoesNotExist:
        raise Http404()

    # Make sure that the username entered is the actual poster of this ticket
    if ticket.poster != profile_user:
        raise Http404('{} did not post that ticket.'.format(profile_user.user_profile.username))

    if not ticket.can_view():
        raise Http404('It looks like this page no longer exists. The user probably cancelled their ticket.')

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

    user_location = profile_user.location

    most_recent_review = profile_user.most_recent_review()

    user_info = {'name': profile_user,
                 'age': profile_user.age(),
                 'city': user_location.city,
                 'state': user_location.state,
                 'rating': profile_user.rating,
                 'username': username,
                 'user_id': profile_user.id,
                 'email': profile_user.email
                 }

    try:
        user_info['profile_picture'] = profile_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

    return render(request,
                  'user_profile/view_ticket.html',
                  {'user_info': user_info,
                   'is_owner': is_owner,
                   'ticket': ticket,
                   'most_recent_review_info': most_recent_review_info,
                   'stripe_public_api_key': settings.STRIPE_PUBLIC_API_KEY,
                   'has_request': Request.has_requested(ticket, user.id), # We pass in user.id because otherwise the
                                                                          # if the user is anonymous, it would be a
                                                                          # SimpleLazyObject, and Django would error out
                   'ticket_status': ticket.status,
                   },
                  content_type='text/html',
                  )
예제 #3
0
def view_ticket(request, username, ticket_id):
    """
    View the details for a particular ticket. This view allows us to message the user or buy the ticket from him.
    """
    user = request.user

    # Look up the user record who corresponds to this profile
    profile = UserProfile.get_user_profile_from_username(username)
    if profile:
        profile_user = profile.user
    else:
        raise Http404('The username {} does not exist.'.format(username))

    # Make sure that ticket exists
    try:
        ticket = Ticket.objects.get(pk=ticket_id)
    except Ticket.DoesNotExist:
        raise Http404()

    # Make sure that the username entered is the actual poster of this ticket
    if ticket.poster != profile_user:
        raise Http404('{} did not post that ticket.'.format(
            profile_user.user_profile.username))

    if not ticket.can_view():
        raise Http404(
            'It looks like this page no longer exists. The user probably cancelled their ticket.'
        )

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

    user_location = profile_user.location

    most_recent_review = profile_user.most_recent_review()

    user_info = {
        'name': profile_user,
        'age': profile_user.age(),
        'city': user_location.city,
        'state': user_location.state,
        'rating': profile_user.rating,
        'username': username,
        'user_id': profile_user.id,
        'email': profile_user.email
    }

    try:
        user_info['profile_picture'] = profile_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

    return render(
        request,
        'user_profile/view_ticket.html',
        {
            'user_info': user_info,
            'is_owner': is_owner,
            'ticket': ticket,
            'most_recent_review_info': most_recent_review_info,
            'stripe_public_api_key': settings.STRIPE_PUBLIC_API_KEY,
            'has_request': Request.has_requested(
                ticket, user.id),  # We pass in user.id because otherwise the
            # if the user is anonymous, it would be a
            # SimpleLazyObject, and Django would error out
            'ticket_status': ticket.status,
        },
        content_type='text/html',
    )