Esempio n. 1
0
def viewProfile( request, username = None ):
    """Handles requests for a user to view their profile

    Keyword arguments:
    request -- the request to view the profile
    username -- the username of the user's profile do display (String, default None)

    Contributors:
    Quinton Black
    Erin Cramer
    Matthew Hengeveld

    Output:
        HTTP response

    """
    if not request.user.is_authenticated():
        messages.add_message( request, messages.INFO, 'Please Login' )
        return redirect( settings.SITE_URL + 'login/' )

    if not request.user.getHasUpdatedProfile():
        messages.add_message( request, messages.INFO, 'Please edit your profile before continuing' )
        return redirect( settings.SITE_URL + 'profile/edit' )

    form = ProfileForm()

    if request.method == 'POST':
        form = ProfileForm( request.POST )

        if form.is_valid():

            username = form.cleaned_data['search']

            user = PongUser.objects.get( username = username )

            rank = getUserRank( user )
            instRank = getInstitutionRank( user )

            totalSunk = getTotalSunk( user.getLifeStats() )

            return render( request, 'user/profile.html', {'isMyself': False, 'user':user, 'rank':rank, 'instRank':instRank, 'totalSunk':totalSunk, 'form':form} )

    if username is None:
        username = request.session['username']

    gamesToConfirm = obtainGamesToBeConfirmed( username )[0]
    if gamesToConfirm != []:
        messages.add_message( request, messages.INFO, "You have games that need to be <a href = '{0}game/verify'>verified</a>".format( settings.SITE_URL ) )

    user = PongUser.objects.get( username = username )

    rank = getUserRank( user )
    instRank = getInstitutionRank( user )

    totalSunk = getTotalSunk( user.getLifeStats() )

    return render( request, 'user/profile.html', {'isMyself': True, 'user':user, 'rank':rank, 'instRank':instRank, 'totalSunk':totalSunk, 'form':form} )
Esempio n. 2
0
def verifyGameRequest(request):
    """
    Displays the verify game page where PongUsers can choose Games to confirm/deny.
    
    Keyword arguments:
    request -- the HTTP request sent by the PongUser when they go to game/verify
               on the PongTracker website
    
    Contributors: Richard Douglas
    
    Output: renders the webpage based on what Games the PongUser has to confirm.
        
    """
    #redirect to login if they haven't logged in
    if not request.user.is_authenticated():
        messages.add_message(request,messages.INFO,'Please Login')
        return redirect(settings.SITE_URL+'login/')
    
    #redirect to edit profile if they haven't filled in their profile details 
    if not request.user.getHasUpdatedProfile():
        messages.add_message(request,messages.INFO,'Please edit your profile before continuing')
        return redirect(settings.SITE_URL+'profile/edit')
    
    username = request.session['username']
    
    #obtain the Games and write them to the forms
    gamesToConfirm, gamesOthersConfirm = obtainGamesToBeConfirmed(username)
    confirmGameForms = []
    otherGameForms = []
    
    #store the Game data for Games the PongUser can verify (in forms)
    for game in gamesToConfirm:
        confirmForm = ConfirmGameForm()
        confirmForm.setGameData(game)
        confirmGameForms.append(confirmForm)
    
    #store the Game data for Games the PongUser's opponents can verify (in forms)
    for game in gamesOthersConfirm:
        otherForm = ConfirmGameForm()
        otherForm.setGameData(game)
        otherGameForms.append(otherForm)
    
    return render(request, 'game/confirm.html', { 'confirm_games': confirmGameForms, 'opponent_confirm_games': otherGameForms})