Beispiel #1
0
def register(request):
    # if a user is attempting to submit new acct info
    if request.method == 'POST':
        #get the information they have entered about themselves and their city
        uf = UserCreationForm(request.POST, prefix='user')
        cf = CityForm(request.POST, prefix='city')
        #check that the information is valid
        if uf.is_valid() * cf.is_valid():
            #save the new information to the db
            user = uf.save()
            city = cf.save(commit=False)
            city.user = user
            city.save()
            #direct the user to the login page
            response = HttpResponseRedirect('/login/')
            response.user = user
            return response
        else:
            #if they entered invalid credentials, reload the page.
            return render(request, 'cityscore/register.html', {
                'userform': uf,
                'cityform': cf,
                'error': " :( "
            })
    else:
        #if the user is trying to open the page, give them a blank form
        uf = UserCreationForm(prefix='user')
        cf = CityForm(prefix='city')
    #open the page
    return render(request, 'cityscore/register.html', {
        'userform': uf,
        'cityform': cf
    })
Beispiel #2
0
def register(request):
    # if a user is attempting to submit new acct info
    if request.method == 'POST':
        #get the information they have entered about themselves and their city
        uf = UserCreationForm(request.POST, prefix='user')
        cf = CityForm(request.POST, prefix='city')
        #check that the information is valid
        if uf.is_valid() * cf.is_valid():
            #save the new information to the db
            user = uf.save()
            city = cf.save(commit=False)
            city.user = user
            city.save()
            #direct the user to the login page
            response = HttpResponseRedirect('/login/')
            response.user = user
            return response
        else:
            #if they entered invalid credentials, reload the page.
            return render(request, 'cityscore/register.html', {'userform':uf, 'cityform':cf, 'error': " :( "})
    else:
        #if the user is trying to open the page, give them a blank form
        uf = UserCreationForm(prefix='user')
        cf = CityForm(prefix='city')
    #open the page
    return render(request, 'cityscore/register.html', {'userform':uf, 'cityform':cf})