Beispiel #1
0
 def get_context_data(self, **kwargs):
     LOGGER.debug("rango.views.ProfileView.get_context_data")
     username = self.kwargs.get('username')
     if username:
         user = get_object_or_404(User, username=username)
     elif self.request.user.is_authenticated():
         user = self.request.user
     else:
         raise Http404
     
     return_to = self.request.GET.get('returnTo', DEFAULT_RETURNTO_PATH )
     
     p_form = UserProfileForm(instance=user.userprofile)
     user_form = UserForm(instance=user)
     userprofile=user.userprofile
     
     posts = Post.objects.all()
     
     userposts = []
     for post in posts:
         if str(post.creator) == str(username):
             userposts.append(post)
             
     show_email = user.userprofile.show_email
     
             
     p_form.initial['returnTo'] = return_to
     
     return {'userposts' : userposts, 'p_form': p_form, 
             'user_form' : user_form, 'show_email' : show_email, 
             'posts' : posts, 'userprofile' : userprofile}
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})
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} )
Beispiel #4
0
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})
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
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)
Beispiel #8
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()
    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)
Beispiel #9
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 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})
Beispiel #10
0
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)
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)
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})
Beispiel #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()
			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 })
Beispiel #14
0
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,
		})
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})
Beispiel #16
0
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})
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})
Beispiel #18
0
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}
    )
Beispiel #19
0
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, }) 
Beispiel #20
0
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})
Beispiel #21
0
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, })
Beispiel #22
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)
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)
Beispiel #24
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)

        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)
Beispiel #25
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)

        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()
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)
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})
Beispiel #28
0
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)
Beispiel #29
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}
    )
Beispiel #30
0
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})
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 raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(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 indicate that the template
            # registration 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',
    context = {'user_form': user_form,
    'profile_form': profile_form,
    'registered': registered})
Beispiel #32
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)
Beispiel #33
0
def register(request):
    #A boolean value for telling the template whether the registration was successful
    #Set false initially. 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 attributes ourselves, we set commit=False
            #This delays saving the model until we're ready to avoid integrity problems
            profile = profile_form.save(commit=False)

            #We need to establish a link between the two model instances tht we have
            #created. After creaing a new User model instance, we reference it in
            #the UserProfile instance with the line below. This is where we
            #populate the user attribute of the UserProfileForm form, which we
            #hid this field from users
            profile.user = user

            #Did the user provide a pro pic?
            #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 indicate that the template registration 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()
    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
def register(request):
	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()

			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',
		context = {
			'user_form':user_form,
			'profile_form':profile_form,
			'registered':registered

		})
def register(request):
    #a boolean value for telling the template
    # whether the registration is successful
    # initially  false, when succeeds true.
    registered = False

    # POST, handle the form data
    if request.method == "POST":
        # try to grab information from the raw form information
        # note that, we use both UserForm & UserProFileForm(additional attributes)
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        # check whether the form data is valid
        if user_form.is_valid() and profile_form.is_valid():
            # save the UserForm data into database
            user = user_form.save()

            # Note that using the hasher to set password
            # And update the user instance
            user.set_password(user.password)
            user.save()

            # handle the UserProfile instance
            # we need to set the user attribute ourselves(self-defined)
            #we set commit = False, to <delay> the save(iniitially no user instance)
            profile = profile_form.save(commit=False)
            profile.user = user

            # if user provide the icon
            # get it from the input form then put it into UserProfile mdoel
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            #save the UserProfile(Form to database) model instance
            profile.save()

            # tells the teplates, registration finished
            registered = True
        else:
            # invalid forms data
            # print problems to the terminal
            print(user_form.errors, profile_form.errors)
    else:
        # not HTTP POST(maybe get HttpRequest)
        # so provide&tender the blank form for user
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template
    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
Beispiel #36
0
def register(request):
    # A boolean value for telling the template whether the registration was successful
    # Set to False initially, use code change the value to True when registration succeeds
    registered = False

    # If it is a HTTP POST, we r interested in processing from data
    if request.method == 'POST':

        # grab information form the raw form information
        # Note that we use both UserForm and UserProfileForm
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(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 oursleves
            # we set commit=False which delays saving the model
            profile = profile_form.save(commit=False)
            profile.user = user

            # check whether the user provided a profile picture
            # If so, get it from the input form and put it in UserProfile Model
            if 'picture' in request.FILES:
                profile.picture = request.FILES('picture')

            # Now we can save
            profile.save()

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

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

    else:
        # Not a HTTP POST, so we render our form using 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',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
Beispiel #37
0
def register_profile(request, username):
    if request.method == 'POST':
        profile_form = UserProfileForm(request.POST)
        if profile_form.is_valid():
            profile_form.save(commit=True)
        else:
            print profile_form.errors

    else:
        profile_form = UserProfileForm()
    # Render the template depending on the context.
    return render(request, 'rango/profile_registration.html',
                  {'profile_form': profile_form})
Beispiel #38
0
def register(request):
    # if request.session.test_cookie_worked():#测试浏览器的cookies是否正常
    #     print(">>>> TEST COOKIE WORKED!")
    #     request.session.delete_test_cookie()
    # else:
    #     print('NO cookie')

    is_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()

            is_registered = True

        else:
            print(user_form.erros, 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':is_registered})
    return render(request, 'rango/register.html', locals())
Beispiel #39
0
def register(request):

    # A boolean value for denoting whether or not registration was successful.
    registered = False

    # If the method is POST we are interested in processing form data.
    if request.method == 'POST':

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

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

            # Save the users 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 we 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.
            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 can save the profile instance.
            profile.save()

            # Update the variable to indicate that registration was successful.
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:

        # Not a HTTP POST, we render our view using two ModelForm instances.
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
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 its a HTTP POST, we're interested in processing form data
    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():

            # 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()

            # Sort out the user profile instance
            # Since we need to set the user attribute outselves, we set commit = False.
            # This delays ssaving the model until we're ready to avoid integrity problems
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did user provide a profile picture? If so, 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 indicate that the template registration 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 2 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
        })
Beispiel #41
0
def register(request):
    # Request the context.
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict = {}
    context_dict['cat_list'] = cat_list
    # Boolean telling us whether registration was successful or not.
    # Initially False; presume it was a failure until proven otherwise!
    registered = False

    # If HTTP POST, we wish to process form data and create an account.
    if request.method == 'POST':
        # Grab raw form data - making use of both FormModels.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # Two valid forms?
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data. That one is easy.
            user = user_form.save()

            # Now a user account exists, we hash the password with the set_password() method.
            # Then we can update the account with .save().
            user.set_password(user.password)
            user.save()

            # Now we can sort out the UserProfile instance.
            # We'll be setting values for the instance ourselves, so commit=False prevents Django from saving the instance automatically.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Profile picture supplied? If so, we put it in the new UserProfile.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

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

            # We can say registration was successful.
            registered = True

        # Invalid form(s) - just print errors to the terminal.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render the two ModelForms to allow a user to input their data.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context_dict['user_form'] = user_form
    context_dict['profile_form'] = profile_form
    context_dict['registered'] = registered

    # Render and return!
    return render_to_response('rango/register.html', context_dict, context)
Beispiel #42
0
def register(request):
    #A boolean value telling the template whether
    #the registration was successfule
    #set false init. code change to true when register
    #success
    registered = False
    user_form = UserForm()
    profile_form = UserProfileForm()
    #if it is a HTTP Post, we process the data
    if request.method == 'POST':
        #grap information from the raw form info
        #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 form data to the db
            user = user_form.save()

            #hash the password with the set_password method
            #after hashed update the user object
            user.set_password(user.password)
            user.save()

            #sort the UserProfile instance
            #need to set the user attribute ourselves
            # set commit = False. This delays saving the model until
            #we ready to avoid integrity problems

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

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

            #Save the UserProfile mode instance
            profile.save()

            #Update our variable to indicate the the template registration
            #was successful
            registered = True
        else:
            print(user_form.errors, profile_form.errors)

    context_dict = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }
    return render(request, 'rango/register.html', context_dict)
Beispiel #43
0
def register(request):
    #boolean to tell template true if registration succeeds.
    registered = False

    #if it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        #attempt to grab info from the raw form information.
        #need make user 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 user's form data to the database.
            user = user_form.save()

            #hash password for security, then update the user object.
            user.set_password(user.password)
            user.save()

            #to sort out Userprofile instance.
            #since we need to set the user attributes 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

            #user provided a dp?
            #true, get it from input form and put it in the userprofile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            #now save the userprofile model instance.
            profile.save()

            #update our variable to indicate that the template
            #registration was successful.
            registered = True
        else:
            #invalid form ot forms - mistakes or soemthing 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()

    #ender the template depending on the context.
    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Beispiel #44
0
def register(request):
    # Логическое значение указывающее шаблону прошла ли регистрация успешно.
    # В начале ему присвоено значение False. Код изменяет значение на True, если регистрация прошла успешно.
    registered = False

    # Если это HTTP POST, мы заинтересованы в обработке данных формы.
    if request.method == 'POST':
        # Попытка извлечь необработанную информацию из формы.
        # Заметьте, что мы используем UserForm и UserProfileForm.
        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()

            # Теперь мы хэшируем пароль с помощью метода set_password.
            # После хэширования мы можем обновить объект "пользователь".
            user.set_password(user.password)
            user.save()

            # Теперь разберемся с экземпляром UserProfile.
            # Поскольку мы должны сами назначить атрибут пользователя, необходимо приравнять commit=False.
            # Это отложит сохранение модели, чтобы избежать проблем целостности.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Предоставил ли пользователь изображение для профиля?
            # Если да, необходимо извлечь его из формы и поместить в модель UserProfile.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Теперь мы сохраним экземпляр модели UserProfile.
            profile.save()

            # Обновляем нашу переменную, чтобы указать, что регистрация прошла успешно.
            registered = True

        # Неправильная формы или формы - ошибки или ещё какая-нибудь проблема?
        # Вывести проблемы в терминал.
        # Они будут также показаны пользователю.
        else:
            print(user_form.errors, profile_form.errors)

    # Не HTTP POST запрос, следователь мы выводим нашу форму, используя два экземпляра ModelForm.
    # Эти формы будут не заполненными и готовы к вводу данных от пользователя.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Выводим шаблон в зависимости от контекста.
    return render(request,
            'rango/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
Beispiel #45
0
def register(request):
    #boolean was registration successful?
    registered = False

    #if http post, we want to process form data
    if request.method == 'POST':
        #attempt to grab information from the raw form info
        #note that we make user of both UserForm and UserProfileForm
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        #if two forms are valid
        if user_form.is_valid() and profile_form.is_valid():
            #save users form to db
            user = user_form.save()

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

            #now sort out UserProfile instance
            #since we need to set the user attribute ourselves, we set
            #commit=False. this delays saving 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 yes, get it from input form and put in userprofile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            #now save UserProfile model instance
            profile.save()

            #update our variable to indicate that the template registration
            #was successful
            registered = True
        else:
            #invalid form or forms, print problems to terminal
            print(user_form.errors, profile_form.errors)
    else:
        #not 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})
Beispiel #46
0
def register(request):
    # Like before, get the request's context.
    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 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

            # 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_to_response(
            'rango/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Beispiel #47
0
def register(request):
    # A boolean value for telling the template whether registration was successful
    # Set to False initially, changed to True when registration succeeds
    registered = False

    # If it's a HTTP POST we process form data
    if request.method == 'POST':
        # Attempt to grab info
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save user's form data to 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
            profile = profile_form.save(commit=False)
            profile.user = user

            # Check if the user provided a picture
            # If so, we take 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 instance
            profile.save()

            # Update our variable to indicate that the registration was successful
            registered = True
        else:
            # Invalid form - mistakes made in either form
            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 input
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on context
    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
Beispiel #48
0
def register(request):
    # boolean to tel the template whether registration was successful.
    # set to false to start, code changes to true when successful
    registered = False

    # if it's HTTP POST, we want to proccess form data
    if request.method == 'POST':
        # attempt to grab info from raw form info
        # use both UserForm and UserProfileForm
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

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

            # now hash the password with the set_password method
            # once hashed, update user object
            user.set_password(user.password)
            user.save()

            # now sort out the UserProfile instance. Since we set user
            # attributes 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 user provide profile pic? If so, get it from input form
            # and put it in the UserProfile models
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

                # now save UserProfile model instance
                profile.save()

                # update variables to indicate template reg. was successful
                registered = True
        else:
            # invalid form/s - mistake or something else?
            # print problem to the terminal for user
            print(user_form.errors, profile_form.errors)
    else:
        # not HTTP POST, so render the form using two ModelForm instances.
        # 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
        })
def register(request):
    # 用来返回给模版文件注册是否成功的标识变量。
    # 初始设置为 False, 注册成功后设置为 True
    registed = False

    # 如果请求的类型是 POST, 那么我们将对提交的注册信息进行处理
    if request.method == 'POST':
        # 试图从原始提交的表格信息中提取有用的信息
        # 需要注意的是我们同时需要 UserForm 和 UserProfileForm的信息
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # 假如两个 Form的数据都通过校验...
        if user_form.is_valid() and profile_form.is_valid():
            # 将用户注册 Form 中的信息直接存入数据库
            user = user_form.save()

            # 使用 set_password方法,来对用户的密码进行哈希算法的加密
            # 加密完成后,应该更新用户的密码数据,以在数据库中保存
            user.set_password(user.password)
            user.save()

            # 现在开始处理用户档案数据的Form信息,因为我们还需要补充输入相关的属性数据
            # 所以我们在这里设置 commit=False ,来延迟数据被直接存入数据库
            # 当我们完成所有的设置工作后,再真正提交数据库保存,这样能保证数据的完整性,避免异常的BUG
            profile = profile_form.save(commit=False)
            profile.user = user

            # 在这里我们判断用户是否上传了头像图片
            # 如果用户上传了,那么我们需要从提交Form的数据中取出文件,并更新到我们的用户档案model中去
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # 现在我们对用户档案的模型进行保存,即存入了数据库
            profile.save()

            # 更新标识变量,以告诉模板我们已经注册成功了
            registed = True
        else:
            # 如果 Form 数据校验不通过——存在某些错误
            # 在 Terminal 中将错误打印出来
            print(user_form.errors, profile_form.errors)
    else:
        # 如果请求类型不是 POST,那么我们将用使用两个 ModelForm 的实例来进行模板渲染
        # 并且这两个实例的数据为空
        user_form = UserForm()
        profile_form = UserProfileForm()

    # 返回模板渲染,并传入上下文参数
    return render(request, 'rango/register.html', {
        'user_form': user_form,
        'profile_form': profile_form,
        'registed': registed
    })
Beispiel #50
0
def register(request):
    # like before, get request context
    context = RequestContext(request)
    # a boolean value for telling template whether registration was successful
    # set false initially. code changes value to true when registration succeed
    registered = False
    # if it's a HTTP POST, we're interested in processing form data
    if request.method == 'POST':
        # attempt to grab information from raw form information
        # note we make use of both UserForm and UserProfileForm
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        # if two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # save user's form data to the database
            user = user_form.save()
            # now we hash the password with 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 user attribute ourselvs we set commit=False
            # this delays saving model until 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 input form, put it in UserProfile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # now we save the UserProfile instance
            profile.save()
            # update our variable to tell template registration successful
            registered = True

        # invalid form or forms - mistakes or something else?
        # print problems to terminal
        # they'll be shown to user
        else:
            print user_form.errors, profile_form.errors

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

    # render the template depending on the context
    return render_to_response(
        'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)
Beispiel #51
0
def register(request):

    #Bool for login (Changes to true when logged in)
    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():
            user = user_form.save()

            #Hash and save password
            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

            #If we have a profile picture, deal with it
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            #Update
            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
        })
Beispiel #52
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/user_profile.html',{'userprofile':userprofile,'selecteduser':user,'form':form})
Beispiel #53
0
def register(request):
    # Boolean telling whether the registration was successful
    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(request.POST)
        profile_form = UserProfileForm(request.POST)

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

            # set_password method is used for hashing
            # once hashed, update the 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 form the input form and
            # put it into the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()
            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.
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered,
                  })
Beispiel #54
0
def register(request):
    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 2 forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # save the users form data to the database
            user = user_form.save()

            # now we hash the password with set_password
            # 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 indicate that the template
            # 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()

    # return the template depending on context
    return render(
        request, 'rango/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Beispiel #55
0
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')
    context_dict = {'form': form}
    return render(request, 'rango/profile_registration.html', context_dict)
Beispiel #56
0
def register_profile(request):
    try:
        user_profile = request.user.userprofile
    except UserProfile.DoesNotExist:
        user_profile = UserProfile(user=request.user)

    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=user_profile)
        print "request.POST: %s \n" % request.POST
        if form.is_valid():
            form.save()
            return redirect('/rango/profile')
    else:
        form = UserProfileForm(instance=user_profile)
        context_dict = {'form': form}
        return render(request, 'rango/profile_registration.html', context_dict)
def register(request):
    #  A boolean value
    #  whether the registeration was secessful
    #  true when registration succeeds
    registered = False

    # If a HTTP POST->process form data
    if request.method == 'POST':
        #  Attempt to grab information from the raw form information
        #  Make use of UserForm and UserProfileForm
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        # if 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 the UserProfile instance
            # Set commit=False. This delays saving the model
            # Until we are ready to avoid integrity problems
            profile = profile_form.save(commit=False)
            profile.user = user

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

            # Save the UserProfile model instance
            profile.save()

            # Update the variable and registeration 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 instance
        # These forms will be blank, reandy 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
                  })
def register(request):
    # A boolean value for telling the template
    # whether the registration was successful.
    registered = False

    # POST: 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 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
            user.set_password(user.password)
            user.save()

            # 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)

            # reference of the User instance in the UserProfile
            # populate the user attribute of the UserProfileForm form
            profile.user = user

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

            profile.save()

            # 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
        })
def register(request):

    # boolean telling the template if the registreation was succ
    # inital false, when registred turn to true
    registered = False

    #if itsa post we're intrested in processing form data
    if request.method == 'POST':

        # attempt to grab info from form
        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 with set_password method
            # once hashed update the user object
            user.set_password(user.password)
            user.save()

            # we dont save to begin with as we need to add user, 
            # do this later
            profile = profile_form.save(commit=False)
            profile.user = user

            # if the user provided a pic save it
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # now we save the user profile
            profile.save()

            # update vairable to show suer registered
            registered = True

        else:

            print(user_form.errors, profile_form.errors)

    else:

        #theyre not a user yet so we render the forms as blank
        user_form = UserForm()
        profile_form = UserProfileForm()

    # render the form depending on the context
    return render(request, 'rango/register.html', 
                    context = {'user_form':user_form, 
                    'profile_form':profile_form,
                    'registered':registered})
def register(request):
    #Boolean for telling template whether the registration was succesful
    #False initially and changes when registration succeeds.
    registered = False

    #If HTTP POST we want to process form data
    if request.method == 'POST':
        #Try to grab info from form info
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

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

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

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

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

            #Now save UserProfile model instance
            profile.save()

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

    #Render template depending on context
    return render(request,
                  'rango/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })