コード例 #1
0
ファイル: views.py プロジェクト: lorenmanu/DAI
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data = request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit = False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form=UserForm()
        profile_form = UserProfileForm()
    context_dict = {'user_form': user_form, 'profile_form':profile_form, 'registered':registered}
    bar_list =  Bar.objects.order_by('-numero_visitas')
    context_dict['bares'] = bar_list
    return render(request, 'rango/register.html', context_dict)
コード例 #2
0
ファイル: views.py プロジェクト: STAbraham/ProjectTango
def register_profile(request):
    registered = False

    if request.method == 'POST':
        form = UserProfileForm(data = request.POST)
        if form.is_valid():
            profile = form.save(commit=False)
            User = UserModel() # imported above
            current_user = User.objects.get(username = request.user.username)
            profile.user = current_user # form.user link comes from request object
            print profile.user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance to the DB
            profile.save()
            # Update our variable to tell the template registeration was succesful
            registered = True
            return index(request)
        else:
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details
        # (i.e. upon first load)
        form = UserProfileForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'registration/profile_registration.html', {'form': form})
コード例 #3
0
ファイル: views.py プロジェクト: hmishra2250/rango
def register(request):
	if request.session.test_cookie_worked():
		print ">>>>Test cookie worked !!!"
		request.session.delete_test_cookie()
	registered = False
	if request.method == "POST":
		user_form  = UserForm(data = request.POST)
		profile_form = UserProfileForm(data = request.POST)
		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			print "Part 1 done"
			
			profile = profile_form.save(commit = False)
			profile.user = user
			print "Part 1.5 done"
			if 'pic' in request.FILES:
				profile.pic = request.FILES['pic']
			profile.save()
			print "Part 2 done"
			registered = True
		else:
			print user_form.errors, profile_form.errors
	else:
		print "Part 3 executing"
		user_form = UserForm()
		profile_form = UserProfileForm()
	print "registered =  ",registered
	return render(request, 
		'rango/register.html',
		{'user_form': user_form, 'profile_form':profile_form, 'registered': registered })
コード例 #4
0
ファイル: views.py プロジェクト: Ramesh7128/tango-with-django
def register(request):

    context = RequestContext(request)
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response('rango/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered,}, context)
コード例 #5
0
ファイル: views.py プロジェクト: jonsuth/tangowithdjango
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)  # Hash the password
            user.save()  # Save the password

            profile = profile_form.save(commit=False)
            profile.user = user

            #  Check if user provides a profile picture
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print user_form.errors, profile_form.errors

    # If this is not a HTTP POST, then render the forms for input
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request, 'rango/register.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
コード例 #6
0
ファイル: views.py プロジェクト: jonathan-s/Rango
def register(request):
    context = RequestContext(request)

    registered = False

    # Post request
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save() # does this really save form data to the database?

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save() 
            registered = True
        else:
            print user_form.errors, profile_form.errors
    # not a HTTP POST
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # render template 
    return render_to_response('rango/register.html', {'user_form': user_form, 
        'profile_form': profile_form, 'registered': registered, 'cat_list': get_category_list()}, context)
コード例 #7
0
ファイル: views.py プロジェクト: simonmh2u/DjangoLearning
def register(request):
    context = RequestContext(request)
    registered = False
    if request.session.test_cookie_worked():
        print ">>>>>TEST COOKIE WORKED"
        request.session.delete_test_cookie()
    

    if request.POST:
        form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if form.is_valid() and profile_form.is_valid():
            user = form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.picture = request.FILES['picture']            
            profile.save()
            registered = True
        else:
            form.errors, profile_form.errors

    else:
        form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response('rango/register.html',{'form':form,'profile_form':profile_form,'registered':registered},context)
コード例 #8
0
def register(request):
	context=RequestContext(request)
	registered = False
	if(request.method=="POST"):
		#process the form
		user_form=UserForm(data=request.POST)
		profile_form=UserProfileForm(data=request.POST)
		if user_form.is_valid() and profile_form.is_valid():
			user=user_form.save()
			user.set_password(user.password)
			user.save()#hashing the pwd
			profile=profile_form.save(commit=False)	
			profile.user=user#This is where we populate the user attribute of the UserProfileForm form, which we hid from users
			if 'picture' in request.FILES:
				profile.picture=request.FILES['picture']
			profile.save()
			registered=True
		else:
			print user_form.errors, profile_form.errors
	else:
		user_form=UserForm()
		profile_form=UserProfileForm()
	return render_to_response(
            'rango/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
コード例 #9
0
ファイル: views.py プロジェクト: Time1ess/MyCodes
def register_profile(request):
	if request.method=='POST':
		user_id=request.POST['user_id'] 
		old_profile_form=None
		try:
			old_profile_form=UserProfile.objects.get(user_id=user_id)
		except:
			pass
		profile_form=UserProfileForm(data=request.POST) 
		user=None 
		try: 
			user=User.objects.get(pk=user_id) 
		except: 
			pass 
		if user and profile_form.is_valid():
			if not old_profile_form:
				profile=profile_form.save(commit=False)
				profile.user=user
				if 'picture' in request.FILES:
					profile.picture=request.FILES['picture'] 
				profile.save()
			else:
				old_profile_form.website=request.POST['website']
				if 'picture' in request.FILES: 
					old_profile_form.picture=request.FILES['picture'] 
				old_profile_form.save() 
				return redirect('/rango/') 
		else: 
			print profile_form.errors 
			return render(request,'rango/404.html',{}) 
	else: 
		profile_form=UserProfileForm() 
		return render(request,'registration/profile_registration.html',{ 'profile_form':profile_form, }) 
コード例 #10
0
ファイル: views.py プロジェクト: VijayAmbekar/tango_project
def register(request):
	context = RequestContext(request)
	context_dict = {'cat_list': get_category_list()}
	registered = False
	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		
		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			
			profile = profile_form.save(commit=False)
			profile.user = user
			if 'picture' in request.FILES:
				profile.picure = request.FILES['picture']
				profile.save()
				registered = True
		else:
			context_dict['errors'] = user_form.errors + profile_form.errors
	else:
		user_form = UserForm()
		profile_form = UserProfileForm()
		
	context_dict['user_form'] = user_form
	context_dict['profile_form'] = profile_form
	context_dict['registered'] = registered
	return render_to_response('rango/register.html', context_dict, context)
コード例 #11
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True
        else:
            print user_form.errors(), profile_form.errors()

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request, 'rango/register.html', {'user_form': user_form,
                                                   'profile_form': profile_form, 'registered': registered})
コード例 #12
0
def register(request):
    if request.session.test_cookie_worked():
        print ">>>Test cookie worked!"
        request.session.delete_test_cookie()

    context = RequestContext(request)
    categories = get_category_list()
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response('rango/register.html',
                              dict(user_form=user_form, profile_form=profile_form, registered=registered,
                              categories=categories),
                              context)
コード例 #13
0
def register(request):
    #if request.session.test_cookie_worked():
     #   print ">>>> TEST COOKIE WORKED!"
      #  request.session.delete_test_cookie()

    registered = False
    
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
		
        if user_form.is_valid() and profile_form.is_valid():
            user=user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            profile.save()
            registered = True
            #user1 = authenticate(username = user.username,password=user.password)
            #login(request,user1)
            #return HttpResponseRedirect('/rango/')
        else :
            print user_form.errors, profile_form.errors
    else :
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render(request,'rango/register.html',
	    {'user_form':user_form,'profile_form':profile_form,'registered':registered})
コード例 #14
0
def register(request):
	context = RequestContext(request)
	registered = False
	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		calc_form = CalcForm(data=request.POST)
		if user_form.is_valid() and profile_form.is_valid() and calc_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			profile.save()
			calc = calc_form.save(commit=False)
			calc.user = user
			calc.gender = profile.gender
			calc.height_for_calc = profile.height
			calc.weight_for_calc = profile.weight
			calc.save()
			registered = True
		else:
			print(user_form.errors, profile_form.errors)
	else:
		user_form = UserForm()
		profile_form = UserProfileForm()
		calc_form = CalcForm()
	return render_to_response('rango/register.html',{'user_form': user_form, 'profile_form': profile_form, 'calc_form': calc_form, 'registered' : registered}, context)
コード例 #15
0
ファイル: views.py プロジェクト: z23han/tango-django
def register(request):
	# boolean for telling the template whether registration is successful
	if request.session.test_cookie_worked():
		print ">>>> TEST COOKIE WORKED!"
		request.session.delete_test_cookie()
	register = False

	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)

		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()

			profile = profile_form.save(commit=False)
			profile.user = user

			if 'picture' in request.FILES:
				profile.picture = request.FILES['picture']

			profile.save()
			register = True

		else:
			print user_form.errors, profile_form.errors
	else:
		user_form = UserForm()
		profile_form = UserProfileForm()

	return render(request, 'rango/register.html', 
		{'user_form': user_form, 'profile_form': profile_form, 'register': register})
コード例 #16
0
ファイル: views.py プロジェクト: nishant57/rango
def register(request):
	registered = False

	## Testing cookies
	if request.session.test_cookie_worked():
		print ">>>>> Test cookie worked!"
	#	request.session.delete_test_cookie()
	## Testing cookies
	
	if request.method == 'POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		
		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()

			profile = profile_form.save(commit = False)
			profile.user = user

			if 'picture' in request.FILES:
				profile.picture = request.FILES['picture']

			profile.save()
			registered = True

		else:
			print user_form.errors, profile_form.errors

	else:
		user_form = UserForm()
		profile_form = UserProfileForm()

	return render(request, 'rango/register.html', {'user_form':user_form, 'profile_form':profile_form, 'registered': registered, 'cat_list':cat_list, })
コード例 #17
0
ファイル: views.py プロジェクト: kenju254/tangowithdjango
def register(request):
    context = RequestContext(request)

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)

            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True
        else:
            print user_form.errors , profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
コード例 #18
0
def register(request):
    registered = False
    print 'reg', request.method
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            
            profile = profile_form.save(commit=False)
            profile.user = user
            
            if 'picture' in request.FILES:
                profile.picture = request.FILES('picture')
            profile.save()
            registered = True
        
        else:
            print 'user profile form errors', user_form.errors, profile_form.errors
    else:
        user_form=UserForm()
        profile_form = UserProfileForm()
    context = {'user_form': user_form, 'profile_form': profile_form,'registered': registered}
    print 'context', context
    return render(request, 'rango/register.html', context)
コード例 #19
0
ファイル: views.py プロジェクト: scientist1642/cyrus
def register(request):
    if request.session.test_cookie_worked():
        print 'Test cookie worked'
        request.session.delete_test_cookie()
    context = RequestContext(request)

    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict = {'user_form' : user_form, 'profile_form': profile_form, 'registered':registered}

    return render_to_response('rango/register.html', context_dict, context)
コード例 #20
0
ファイル: views.py プロジェクト: astelmach/Rango
def register(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user

            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            profile.save()
            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render(
        request, "rango/register.html", {"user_form": user_form, "profile_form": profile_form, "registered": registered}
    )
コード例 #21
0
ファイル: views.py プロジェクト: pateto/hcltest
def add_profile(request):
	# A HTTP POST?
	if request.method == 'POST':
		form = UserProfileForm(request.POST)
	
		# Have we been provided with a valid form?
		if form.is_valid():
			userProfile = form.save(commit=False)
			userProfile.user_id = request.user.id
			
			if 'picture' in request.FILES:
				userProfile.picture = request.FILES['picture']
				
			# Save the new category to the database.
			form.save(commit=True)
		
		# Now call the index() viewed.
		# The user will be shown the homepage
		return index(request)
	else:
		# If the request was not a POST, display the form to enter details.
		form = UserProfileForm()
		
	# Bad form (or form details), no form supplied...
	# Render the form with error messages (if any).
	return render(request, 'rango/profile_registration.html',{'form':form})
コード例 #22
0
ファイル: views.py プロジェクト: erichideki/tango-with-django
def register(request):
    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request, 'rango/register.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
コード例 #23
0
def edit_profile(request):
   
    url = '/rango/'

    try:
        profile = request.user.userprofile
    except UserProfile.DoesNotExist:
        profile = UserProfile(user=request.user)

    if request.method == 'POST':
        profile_form = UserProfileForm(data=request.POST, instance=profile)
        if profile_form.is_valid():
            profile_form.save(commit=False)
            
            if 'picture' in request.FILES:
                print "picture"
                profile.picture = request.FILES['picture']
            
            profile.save()
            return redirect(url)

        else:
            print profile_form.errors

    else:
        profile_form = UserProfileForm(instance=profile)

    return render(request,
            'rango/edit_profile.html',
            {'profile_form': profile_form} )
コード例 #24
0
def registration_register(request):

    # if request.session.test_cookie_worked():
    #     print ">>>>> TEST COOKIE WORKED!"
    #     request.session.delete_test_cookie()

    registered = False

    if request.method=="POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
                  'rango/register.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
コード例 #25
0
ファイル: views.py プロジェクト: thinhdiep/rango
def register(request):
	registed = False
	if request.method == "POST":
		user_form = UserForm(request.POST)
		user_profile_form = UserProfileForm(request.POST)
		if user_form.is_valid() and user_profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()

			user_profile = user_profile_form.save(commit = False)
			user_profile.user = user
			if 'picture' in request.FILES:
				print "co picture"
				user_profile.picture = request.FILES['picture']
			user_profile.save()
			registed = True

	else:
		user_form = UserForm()
		user_profile_form = UserProfileForm()

	return render(request,'rango/register.html',{
		'user_form' : user_form,
		'user_profile_form' : user_profile_form,
		'registed' : registed,
		})
コード例 #26
0
ファイル: views.py プロジェクト: almok/tangowithdjango
def register(request):

    if request.session.test_cookie_worked():
        print ">>>> TEST COOKIE WORKED!"
        request.session.delete_test_cookie()

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == "POST":
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(
        request, "rango/register.html", {"user_form": user_form, "profile_form": profile_form, "registered": registered}
    )
コード例 #27
0
def register(request):
    # A boolean value for telling the template
    # whether the registration was successful
    # Set to False initially. Code changes value to
    # True when registration succeeds
    registered = False

    # If it's a HTTP POST, we're interested in processing form data
    if request.method == 'POST':
        # Attempt to grab information from the faw form information
        # Note that we make use of both UserForm and UserProfileForm
        user_form = UserForm(data=request.POST) 
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid..
        if user_form.is_valid() and profile_form.is_valid():
            #Save the user's form data to the database
            user = user_form.save()

            # Now we hash the password with the set_password method
            # Once hashed, we can update the user object.
            user.set_password(user.password) 
            user.save()

            # Now sort out the UserProfile instance
            # Since we need to set the user attribute ourselves,
            # we set commit=False. This delays saving the model
            # Until we're ready to avoid integrity problems

            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # if so we need to get it from the input form and
            # put it in the UserProfile model.
            if 'picture' in request.FILES: 
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instane
            profile.save()

            # Update our variable to indicate that the template
            # registartion was successful
            registered = True
        else:
            # Invalid form or forms - mistakes or something else
            # Print problems to the terminal.
            print(user_form.errors, profile_form.errors)
            
    else:
        # Not a HTTP POST, so we render our form using two ModelForm instances
        # These forms will be blank, ready for user input
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context
    return render(request,'rango/register.html',
                  {'user_form': user_form,
                   'profile_form': profile_form,
                   'registered': registered})
コード例 #28
0
ファイル: views.py プロジェクト: bugzPDX/rango
def register(request):
    #Like before, get the request's context
    context = RequestContext(request)
    cat_list = get_category_list()

    # A boolean value for telling the template whether the registration was successful
    # Set to False initiall. Code changes value to True when registration succeeds
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information
        # Note that we make use of both UserForm and UserProfileForm
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance
            # Since we need to set the user attribute ourselves, we set commit=False
            # This delays saving the model until we're ready to avoid integrity problems
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model
            if 'picture' in request.FILES:
                profile.picture - request.FILES['picture']

            # Now we save the UserProfile model instance
            profile.save()

            # Update our variable to tell the template registration was successful
            registered = True

        # Invalid form or forms - mistakes or somethign else?
        # Print problems to the terminal
        # They'll also be shown to the user
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using to ModelForm instances
    # These forms will be blank, ready for user input
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict = {'user_form': user_form, 'profile_form': profile_form,
                    'registered': registered, 'cat_list': cat_list}

    # Render the template depending on the context
    return render_to_response('rango/register.html', context_dict, context)
コード例 #29
0
ファイル: views.py プロジェクト: mhadam/django-practice
def register_profile(request):
    if request.user.is_authenticated():
        user = request.user
        registered = False
    
        if request.method == 'POST':
            profile_form = UserProfileForm(request.POST)

            if profile_form.is_valid():
                profile = profile_form.save(commit=False)
                profile.user = user

                if 'picture' in request.FILES:
                    profile.picture = request.FILES['picture']
                    profile.save()
                    registered = True
            else:
                print profile_form.errors

        else:
            profile_form = UserProfileForm()
    
    return render(request,
        'registration/profile_registration.html',
        {'profile_form': profile_form, 'registered': registered})
コード例 #30
0
def add_profile(request):
    username = ''
    #if method is post, we'll want to process this data
    if request.method == 'POST':
        profile_form = UserProfileForm(data=request.POST)

        if profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.user = request.user

            if request.user.is_authenticated():
                username = request.user.get_username()

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            #add a redirect to the view_profile page when you make one

        else:
            print profile_form.errors
    else:
        profile_form = UserProfileForm()

    return render(request,'registration/profile_registration.html', {'profile_form': profile_form,
                                                                     'username': username})
コード例 #31
0
ファイル: views.py プロジェクト: Sensweii/tango_with_django
def register_profile(request):
    form = UserProfileForm()

    if request.method == 'POST':
        form = UserProfileForm(request.POST, request.FILES)
        if form.is_valid():
            user_profile = form.save(commit=False)
            user_profile.user = request.user
            user_profile.save()

            return redirect('index')
        else:
            print(form.errors)

    context_dict = {'form':form}

    return render(request, 'rango/profile_registration.html', context_dict)
コード例 #32
0
ファイル: views.py プロジェクト: schouston/django_project
def register(request):
    if request.session.test_cookie_worked():
        print ">>>> Test cookie worked!"
        request.session.delete_test_cookie()
    context = RequestContext(request)

    #boolean to indicate whether registration successful
    registered = False

    #post request => process data
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        #forms valid
        if user_form.is_valid() and profile_form.is_valid():
            #save user's form to database
            user = user_form.save()

            #hash pw with set_pw, updatae user object
            user.set_password(user.password)
            user.save()

            #sort out userprofile insstance
            profile = profile_form.save(commit=False)
            profile.user = user

            #picture?
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            #save userprof model instance
            profile.save()
            registered = True

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response(
        'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)
コード例 #33
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and
            # put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            # Update our registration variable to indicate that the template
            # registration was successful.
            registered = True
        else:
            # Invalid form or forms - print problems to the terminal
            print(user_form.errors, profile_form.errors)
    else:
        # Not a HTTP POST, so we render our form using two ModelForm instances.
        # These forms will be blank, ready for user input.
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #34
0
def register(request):

    registered = False

    # if it's a HTTP POST, we're interested in processing a form
    if request.method == 'POST':
        #Grab info from the raw form
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            #save the user's form data to the database
            user = user_form.save()

            #Now let's hash the password
            user.set_password(user.password)
            user.save()

            #since we set the user attributes ourselves, commit=False
            profile = profile_form.save(commit=False)
            profile.user = user

            #did the user provide a profile image
            # if so, we need to get it from the input form and put it in the UserProfile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            #save the userprofile model instance
            profile.save()

            registered = True
        #invalid form
        else:
            print user_form.errors, profile_form.errors
    #not an HTTP POST, so we render our form using 2 ModelForm instances
    #these forms will be blank, ready for user input
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #35
0
ファイル: views.py プロジェクト: mikejguo290/Rango154
def register(request):
	# cookie testing
	if request.session.test_cookie_worked():
		print ">>> TEST COOKIE WORKED!"
		request.session.delete_test_cookie()

	context = RequestContext(request)
	
	registered = False
	# boolean variable to tell template about registration outcome. 
	# initially false
	if request.method =='POST':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		if user_form.is_valid() and profile_form.is_valid():
			
			# save the user's form data to db
			user = user_form.save()
			# hash the password with set_password
			user.set_password(user.password)
			user.save()
			
			# we save profile form, don't commit to db immediately, just get var name
			profile = profile_form.save(commit = False)
			# set profile's user association ourselves
			profile.user = user
			
			"""
			# need to install pillow module first 
			if 'picture ' in request.FILES:
				profile.picture = request.FILES['picture']
			"""	
			# now save UserProfile's model instance
			profile.save()
			
			#registration succesfull
			registered = True
			
		else:
			print user_form.errors, profile_form.errors
	else:
		user_form=UserForm()
		profile_form =UserProfileForm()
	
	return render_to_response('rango/register.html',{'user_form':user_form, 'profile_form': profile_form, 'registered': registered},context)
コード例 #36
0
def register(request):
    #Code changes value to
    # True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            # Update our variable. registration was successful.
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        # Not a HTTP POST, so we render our form using two ModelForm instances.
        # These forms will be blank, ready for user input.
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #37
0
def register(request):
    # Boolean value to store if the registration was successful.
    registered = False

    # If the form has been submitted(POST)
    if (request.method == 'POST'):
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # Check if both forms are filled out correctly:
        if user_form.is_valid() and profile_form.is_valid():
            # save the users registration data
            user = user_form.save()
            # now we hash the password and add it to the database
            user.set_password(user.password)
            user.save()

            # We can now deal with the user profile side of things
            profile = profile_form.save(commit=False)
            profile.user = user

            # Now to add the profile picture if provided!
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Save the new user and set flag to show it worked.
            profile.save()
            registered = True
        else:
            # Invalid form(s)
            print(user_form.errors, profile_form.errors)
    else:
        # have to display the forms for the user to fill in
        user_form = UserForm()
        profile_form = UserProfileForm()

    # render a display either a new registration form, errors in a submitted form
    # or a success message if succesfully registed user

    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
        })
コード例 #38
0
def register(request):
    registered = False

    # If it's a http POST, process form data
    if request.method == 'POST':
        # Retrieve data from the forms
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            # Save the form data to the database
            user = user_form.save()

            # set_password hashes the password, then we save the user
            user.set_password(user.password)
            user.save()

            # commit=False delays saving the model to avoid integrity issues
            # Create the one-to-one relationship between the profile and user
            profile = profile_form.save(commit=False)
            profile.user = user

            # If user uploaded a picture, add it, then save profile to db
            if 'picture' in request.FILES:
                profile_picture = request.FILES['picture']

                profile.save()
                # At this point, user is registered
            registered = True
        else:
            # Display errors
            print(user_form.errors, profile_form.errors)

    else:
        # Render using Blank forms ready for user input
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
コード例 #39
0
ファイル: views.py プロジェクト: 2103291s/tangowithdjango
def register_profile(request):
    if request.method == 'POST':
        profile_form = UserProfileForm(request.POST)
        if profile_form.is_valid():
            if request.user.is_authenticated():
                profile = profile_form.save(commit=False)
                user = User.objects.get(id=request.user.id)
                profile.user = user
                try:
                    profile.picture = request.FILES['picture']
                except:
                    pass
                profile.save()
                return index(request)
    else:
        form = UserProfileForm(request.GET)
    return render(request, 'rango/profile_registration.html',
                  {'profile_form': form})
コード例 #40
0
ファイル: views.py プロジェクト: haimapi/mysite
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # if the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            # hash the password with the set_password method
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
コード例 #41
0
def profile(request, username):
    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        return redirect('index')

    userprofile = UserProfile.objects.get_or_create(user=user)[0]
    form = UserProfileForm({'website': userprofile.website, 'picture': userprofile.picture})

    if request.method == 'POST':
        form = UserProfileForm(request.POST, request.FILES, instance=userprofile)
        if form.is_valid():
            form.save(commit=True)
            return redirect('profile', user.username)
        else:
            print(form.errors)

    return render(request, 'rango/profile.html', {'userprofile': userprofile, 'selecteduser': user, 'form': form})
コード例 #42
0
ファイル: views.py プロジェクト: kubkowski/tango_with_django
def register_profile(request):

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

        if form.is_valid():
            profile = form.save(commit=False)
            profile.user = request.user
            profile.save()
            return index(request)
        else:
            print form.errors

    else:
        form = UserProfileForm()

    return render(request, 'registration/profile_registration.html',
                  {'form': form})
コード例 #43
0
def register(request):
    # Sets register to False initially
    registered = False

    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()
            # Hash pssword
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            # Update registration variable
            registered = True
        else:
            # Invalid form or forms
            # Print problems to the terminal.
            print(user_form.errors, profile_form.errors)
    else:
        # Not a HTTP POST, so we render our form using two ModelForms
        # These forms will be blank, ready for user input.
        user_form = UserForm
        profile_form = UserProfileForm()

    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #44
0
def register(request):
    # Boolean for when registration was successful, false initially,
    # then set to true if successful
    registered = False

    # If it's a HTTP POST, we're interested in processing form data
    if request.method == 'POST':
        # Attempt to get information from the form
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database
            user = user_form.save()

            # Hash the password then update the user object
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            # Check if there's a profile picture
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Sve the UserProfile model instance
            profile.save()

            registered = True

        else:

            print(user_form.errors, profile_form.errrors)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
                  'rango/register.html',
                  {'user_form': user_form,
                   'profile_form':profile_form,
                   'registered': registered})
コード例 #45
0
def register(request):
    
    # tell template if registration was successful
    registered = False

    # if POST, process form data
    if request.method == "POST":
        # try to grab information from raw form
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # if both forms valid
        if user_form.is_valid() and profile_form.is_valid():
            # save to database
            user = user_form.save()

            # hash PW, update
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            # if picture provided
            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            profile.save()
            registered = True
            
        else:
            print(user_form.errors, profile.form_errors)

        # if not POST, render blank form
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # render template depending on context
    return render(request,
                    "rango/register.html",
                    {"user_form":user_form,
                    "profile_form":profile_form,
                    "registered":registered})
コード例 #46
0
def register(request):
    #if request.session.test_cookie_worked():
    #print '>>>> TEST COOKIE WORKED!'
    #request.session.delete_test_cookie()
    #just a test^
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            #user = user_form

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(
                commit=False
            )  #This is unnecessary as well since pic/url is not required
            profile.user = user  #Do we need this??
            #I guess yes, because this 'user' is new one, and needs to referenced to newly created profile...

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True

        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict = {'user_form': user_form}
    context_dict['profile_form'] = profile_form
    context_dict['registered'] = registered
    cat_list = get_cat_list()
    context_dict['cat_list'] = cat_list
    return render(request, 'rango/register.html', context_dict)
コード例 #47
0
    def post(self, request, username):
        try:
            (user, user_profile, form) = self.get_user_details(username)
        except TypeError:
            return redirect(reverse('rango:index'))

        form = UserProfileForm(request.POST, request.FILES, instance=user_profile)

        if form.is_valid():
            form.save(commit=True)
            return redirect('rango:profile', user.username)
        else:
            print(form.errors)

        context_dict = {'user_profile': user_profile,
                        'selected_user': user,
                        'form': form}

        return render(request, 'rango/profile.html', context_dict)
コード例 #48
0
def register(request):
    # A boolean value for telling the template
    # whether the registration was successful.
    # Set to False initially. Code changes value to
    # True when registration succeeds.
    registered = False

    #HTTP post
    if request.method == 'POST':
        #Attempt to take infor
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)


        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']


            profile.save()
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()

        profile_form = UserProfileForm()


    return render(request,
                  'rango/register.html',
                  {'user_form': user_form,
                   'profile_form': profile_form,
                   'registered': registered})
コード例 #49
0
def register(request):
    registered = False
    if request.method == 'POST':

        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)


        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()


            user.set_password(user.password)
            user.save()


            profile = profile_form.save(commit=False)
            profile.user = user


            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']


            profile.save()


            registered = True
        else:

            print(user_form.errors, profile_form.errors)
    else:

        user_form = UserForm()
        profile_form = UserProfileForm()


    return render(request,
                  'rango/register.html',
                  {'user_form': user_form,
                   'profile_form': profile_form,
                   'registered': registered})
コード例 #50
0
    def post(self, request):
        profile_form = UserProfileForm(request.POST, request.FILES)
        # if the form is valid
        if profile_form.is_valid():
            # now sort out the UserProfile instance
            # needed the User attribute first so commit = False for now
            profile = profile_form.save(commit=False)
            profile.user = request.user
            # did the user provide a picture
            # if 'picture' in request.FILES:
            #    profile.picture = request.FILES['picture']

            profile.save()
            return redirect(reverse('rango:index'))
        else:
            print(profile_form.errors)

        context_dict = {'form': profile_form}
        return render(request, 'rango/profile_registration.html', context_dict)
コード例 #51
0
def register_profile(request):
    form = UserProfileForm()

    if request.method == 'POST':
        profile_form = UserProfileForm(request.POST, request.FILES)

        if profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.user = request.user
            profile.save()

            return HttpResponseRedirect(reverse('index'))
        else:
            print(form.errors)

    context_dict = {'form': form}

    return render(request, 'registration/profile_registration_form.html',
                  context_dict)
コード例 #52
0
def register(request):
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response(
        'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)
コード例 #53
0
def register(request):
    # boolean value to check if the registration was successful
    registered = False

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            # save the user_form data
            user = user_form.save()

            # hash the password
            user.set_password(user.password)
            user.save()

            # deal with the UserProfile, we don't save the model because
            # we have some attributes to set
            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # save the UserProfile instance
            profile.save()

            # the registration was successful
            registered = True
        else:
            # invalid form or forms
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }
    return render(request, 'rango/register.html', context=context_dict)
コード例 #54
0
def register(request):
    # boolean for telling the template if registration was sucessful
    # starts off as false and then set to true when successful
    registered = False

    if request.method == "POST":
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            # hash password
            user.set_password(user.password)
            user.save()

            # commit=False to avoid integrity problems from manually setting attributes
            profile = profile_form.save(commit=False)
            profile.user = user

            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        # Not a POST Method then render blank forms
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request,
        "rango/register.html",
        context={
            "user_form": user_form,
            "profile_form": profile_form,
            "registered": registered,
        },
    )
コード例 #55
0
def register(request):
    #Was registration successful?
    registered = False

    #We process form data only if the request is POST
    if request.method == 'POST':
        #Get information from the raw form
        #Use both UserForm and UserProfileForm
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            #Save the data
            user = user_form.save()

            #Now we hash the password with set_password() and save the user object
            user.set_password(user.password)
            user.save()

            #UserProfile instance
            #Set attribute ourselvs so commit=False (delays save)
            profile = profile_form.save(commit=False)
            profile.user = user

            #Picture
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            registered = True #Successful registration
        
        else:
            #Invalid form
            print(user_form.errors, profile_form.errors)

    else:
        #Not a POST - create new blank forms for input
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request, 'rango/register.html',
                    context= {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
コード例 #56
0
def register(request):
    registered = False

    # If POST, process data
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            # Now sort out user profile
            profile = profile_form.save(commit=False)
            profile.user = user

            # Profile picture provided?
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Save UserProfile
            profile.save()

            # Update success variable
            registered = True

        else:
            #Invalid form etc
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #57
0
def register_profile(request):
    if not request.user.is_authenticated:# 限制未登录用户访问
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
        # print("#"*100)
    else:
        # A HTTP POST?
        if request.method == 'POST':
            user_form = UserForm(data=request.POST)
            profile_form = UserProfileForm(data=request.POST)

            # Have we been provided with a valid form?
            if profile_form.is_valid() and user_form.is_valid():
                user = user_form
                # Save the new category to the database.
                profile = profile_form.save(commit=False)
                profile.user=user

                # Did the user provide a profile picture?
                # If so, we need to get it from the input form and put it in the UserProfile model.
                if 'picture' in request.FILES:
                    profile.picture = request.FILES['picture']

                # Now we save the UserProfile model instance.
                profile.save()
                

                # Now call the index() view.
                # The user will be shown the homepage.
                return index(request)
            else:
                # The supplied form contained errors - just print them to the terminal.
                print (profile_form.errors)
        else:
            # If the request was not a POST, display the form to enter details.
            user_form = UserForm()
            profile_form = UserProfileForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).

    print("#"*100)
    return render(request, 'rango/profile_registration.html', {'profile_form': profile_form,'user_form':user_form})
コード例 #58
0
def register(request):
    """View that handles registering a new user"""
    registered = False  # A boolean value for telling the template whether the registration was successful

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        #Check if the two forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            #Did the user provide a profile picture?
            #If so, we need to save it in the UserProfile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
                #Now we save the UserProfile model instance
                profile.save()
                #Update our boolean variable to tell the template registration is successful!
                registered = True
        #what do we do if form is not valid?
        #Print the problems. Event log
        #show them to the user
        else:
            print user_form.errors, profile_form.errors
    #Not an HTTP POST? Sweet! let's render the form using ModelForm instances.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }

    return render(request, 'rango/register.html', context_dict)
コード例 #59
0
def register(request):
    # Set False initially, changes to True when registration succeeds.
    registered = False

    if request.method == 'POST':
        # Attempt to grap the raw form information, both UserForm and UserProfileForm.
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            # Hash the password, and update the user object
            user.set_password(user.password)
            user.save()
            # The commit = False delays saving the model until we avoid the integrity problems
            profile = profile_form.save(commit=False)
            profile.user = user

            # if user provide a picture, we get it from input form, put it in UserProfile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            # Update the status of registered variable
            registered = True
        else:
            # Invalid form or forms - mistakes or something? print it in the terminal.
            print(user_form.errors, profile_form.errors)
    else:
        # Not a HTTP POST, so render the forms, these forms will be blank for user input.
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render depending on the status or forms
    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
コード例 #60
0
def register(request):
    #prset reg = false, if user has reg, will --> true
    registered = False

    if request.method == 'POST':
        #get info from raw from, uses *BOTH* forms
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            #hash the pw
            user.set_password(user.password)
            user.save()

            #set commit to false to avoid integrity problems?
            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        # if problems, send errors to terminal
        else:
            print(user_form.errors, profile_form.errors)

    #if not a post request, render blank forms
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })