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(data=request.POST) print "Is this working?" # If the two forms are valid... if user_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.f print "Hello user" profile = UserProfile.objects.create(user = user) profile.save() # 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 return render(request, 'webapp/login.html') # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. else: print "Hey is this printing?" print user_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, 'webapp/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
def userform(action): form = UserForm() # conn = datastorage.init() # Cancel if form.cancel.data == True: return redirect('/index') if form.validate_on_submit(): if form.user_id.data: flash('Add task for id: {}, action: {}'.format( form.user_id.data, action)) # datastorage.add_task(conn, form.description_task.data, form.duedate_for_task.data) return redirect('/index') elif form.screen_name.data: flash('Add task for screen name: {}, action: {}'.format( form.screen_name.data, action)) # datastorage.add_task(conn, form.description_task.data, form.duedate_for_task.data) return redirect('/index') return render_template('UserForm.html', title='User ID or Screen name', form=form)
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 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() #Now we sort out the userProfile instance # Since we need to set the user attribute oursleves, we set commit=False # This delays saving the mdoel until we're ready 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 else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'webapp/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def register_user(request): context = RequestContext(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 profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response('webapp/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def contributor_profile_edit(request): """Edit user's/Coordinators profile. Arguments: - `request`: """ context = RequestContext(request) print request.user user = get_object_or_404(User, username=request.user) old_username = user.username print user.first_name print user.last_name contributor = get_object_or_404(Contributor, user=request.user) if request.method == 'POST': print "We've a request to register" contributorform = ContributorForm(data=request.POST, instance=contributor) userform = UserForm(data=request.POST, instance=user) if contributorform.is_valid() and userform.is_valid(): print "Forms are Valid" user = userform.save(commit=False) if old_username == user.username: print "Username unchanged" else: print "Username changed!. Deactivating old user." old_username = get_object_or_404(User, username=old_username) old_username.is_active = False old_username.save() # print user.username # print user.first_name # print user.last_name user.set_password(user.password) user.save() contributor = contributorform.save(commit=False) # print coordinator.contact if 'picture' in request.FILES: contributor.picture = request.FILES['picture'] contributor.user = User.objects.get(username=user.username) contributor.save() messages.success(request, "Profile updated successfully.") return HttpResponseRedirect('/contributor/profile/edit_success') else: if contributorform.errors or userform.errors: print contributorform.errors, userform.errors else: # aakashcentreform = AakashCentreForm(instance=aakashcentre) contributorform = ContributorForm() userform = UserForm() context_dict = {'contributorform': contributorform, 'userform': userform} return render_to_response('contributor_profile_edit.html', context_dict, context)
def reviewer_signup(request): """ Argument: `request`: Request from reviewer to sign up. This function is used for a new revieweer to sign up. """ context = RequestContext(request) registered = False if request.method == "POST": print "we have a request to register" user_form = UserForm(data=request.POST) reviewer_form = ReviewerForm(data=request.POST) if user_form.is_valid() and reviewer_form.is_valid(): user = user_form.save() print "Forms are Valid" print user.username print user.first_name user.set_password(user.password) user.is_active = False user.save() reviewer = reviewer_form.save(commit=False) reviewer.user = user if "picture" in request.FILES: reviewer.picture = request.FILES["picture"] reviewer.save() registered = True email_subject = "New reviewer has registered" email_message = ( """ New reviewer has registered. Details: Name:""" + user.first_name + """ """ + user.last_name + """" Email:""" + user.email + """ Waiting for your your approval""" ) # send_mail(email_subject, email_message, '*****@*****.**', ['*****@*****.**'],fail_silently=False) messages.success(request, "form successfully submitted. Waiting for activation from admin.") return HttpResponseRedirect(reverse("webapp.views.reviewer_signup")) else: if reviewer_form.errors or user_form.errors: print user_form.errors, reviewer_form.errors else: reviewer_form = ReviewerForm() user_form = UserForm() context_dict = {"user_form": user_form, "reviewer_form": reviewer_form, "registered": registered} return render_to_response("webapp/reviewer_signup.html", context_dict, context)
def profile(): user = request.user form = UserForm(request.form, obj=user) if request.method == 'POST' and form.validate(): form.populate_obj(user) data = (request.form).to_dict() data.pop('csrf_token', None) try: user.save() flash("Update Succeeded!", 'success') except NotUniqueError: flash('This username is existed!', 'error') return render_template('sites/home/profile.html', form=form)
def post(self, request): user_form = UserForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return redirect('/') else: return render(request, 'profile.html', { 'user_form': user_form, 'profile_form': profile_form })
def contributor_profile_edit(request): """ Argument: `request`: Request form contributor to edit his profile. Edit user's/Coordinators profile. """ context = RequestContext(request) print request.user user = get_object_or_404(User, username=request.user) old_username = user.username print user.first_name print user.last_name contributor = get_object_or_404(Contributor, user=request.user) if request.method == 'POST': print "We've a request to register" contributorform = ContributorForm(data=request.POST, instance=contributor) userform = UserForm(data=request.POST, instance=user) if contributorform.is_valid() and userform.is_valid(): print "Forms are Valid" user = userform.save(commit=False) if old_username != user.username: messages.error(request, 'Username cant be changed') context_dict = { 'contributorform': contributorform, 'userform': userform } return render_to_response('contributor_profile_edit.html', context_dict, context) user.set_password(user.password) user.save() contributor = contributorform.save(commit=False) if 'picture' in request.FILES: contributor.picture = request.FILES['picture'] contributor.user = User.objects.get(username=user.username) contributor.save() messages.success(request, "Profile updated successfully.") else: if contributorform.errors or userform.errors: print contributorform.errors, userform.errors else: contributorform = ContributorForm(instance=contributor) userform = UserForm(instance=user) context_dict = {'contributorform': contributorform, 'userform': userform} return render_to_response('contributor_profile_edit.html', context_dict, context)
def get(self, request): user_form = UserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) return render(request, 'profile.html', { 'user_form': user_form, 'profile_form': profile_form })
def contributor_signup(request): """Request for new contributor to signup""" context = RequestContext(request) registered = False if request.method == 'POST': print "we have a request to register" user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() print "Forms are Valid" print user.username print user.first_name user.set_password(user.password) user.is_active = False user.save() contributor = contributor_form.save(commit=False) contributor.user = user if 'picture' in request.FILES: contributor.picture = request.FILES['picture'] if 'validation_docs' in request.FILES: contributor.validation_docs=request.FILES['validation_docs'] contributor.save() registered = True email_subject="New Contributor has registered" email_message=""" New Contributor has registered. Details: Name:""" + user.first_name + """ """ + user.last_name + """" Email:""" + user.email + """ Waiting for your your approval""" #send_mail(email_subject, email_message, '*****@*****.**', ['*****@*****.**'],fail_silently=False) messages.success(request,"Form successfully submitted. Waiting for activation from admin.") return HttpResponseRedirect(reverse('webapp.views.contributor_signup')) else: if contributor_form.errors or user_form.errors: print user_form.errors, contributor_form.errors else: contributor_form = ContributorForm() user_form = UserForm() context_dict = {'user_form':user_form, 'contributor_form': contributor_form, 'registered': registered} return render_to_response('webapp/contributor_signup.html', context_dict, 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 raw form information. user_form = UserForm(data=request.POST) # If the two forms are valid... if user_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) # Did the user provide a profile picture?. if 'avatar' in request.FILES: user.avatar = request.FILES['avatar'] # Now we save the UserProfile model instance. user.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 # Not a HTTP POST, so we render our form using ModelForm instances. # This formswill be blank, ready for user input. else: user_form = UserForm() # Render the template depending on the context. return render(request, 'wombii/register.html', {'user_form': user_form, 'registered': registered} )
def handleRegister(request): registered = False # Get info from 'both' forms # It appears as one form to the user on the .html page user_form = UserForm(data=request.POST) # Check to see both forms are valid if user_form.is_valid(): # Save User Form to Database user = user_form.cleaned_data username = user['username'] password = user['password'] email = user['email'] # check if password is hashed if not (User.objects.filter(username=username).exists() and User.objects.filter(email=email).exists()): User.objects.create_user(username, email, password) user = authenticate(username=username, password=password) login(request, user) return HttpResponseRedirect(reverse('webapp:providerDashboard')) else: raise forms.ValidationError() # Hash the password # user.set_password(user.password) # Update with Hashed password # user.save() # print('----------------------------------------registering-----------' + user.password) # Registration Successful! registered = True # return render(request, 'index.html', {'user_form': user_form, 'registered': registered}) else: # One of the forms was invalid if this else gets called. user_form = UserForm() print(user_form.errors) return render(request, 'error.html', {'form': user_form})
def reviewer_profile_edit(request): """ Argument: `request`: Request from reviewer to edit his profile. Edit user's/Reviewer's profile. """ context = RequestContext(request) print request.user user = get_object_or_404(User, username=request.user) old_username = user.username print user.first_name print user.last_name reviewer = get_object_or_404(Reviewer, user=request.user) if request.method == "POST": print "We've a request to register" reviewerform = ReviewerForm(data=request.POST, instance=reviewer) userform = UserForm(data=request.POST, instance=user) if reviewerform.is_valid() and userform.is_valid(): print "Forms are Valid" user = userform.save(commit=False) if old_username != user.username: messages.error(request, "Username cant be changed") context_dict = {"reviewerform": reviewerform, "userform": userform} return render_to_response("reviewer_profile_edit.html", context_dict, context) user.set_password(user.password) user.save() reviewer = reviewerform.save(commit=False) if "picture" in request.FILES: reviewer.picture = request.FILES["picture"] reviewer.user = User.objects.get(username=user.username) reviewer.save() messages.success(request, "Profile updated successfully.") else: if reviewerform.errors or userform.errors: print reviewerform.errors, userform.errors else: reviewerform = ReviewerForm(instance=reviewer) userform = UserForm(instance=user) context_dict = {"reviewerform": reviewerform, "userform": userform} return render_to_response("reviewer_profile_edit.html", context_dict, context)
def new_user(): """New user route endpoint. Render form for custom record. Check uniqueness by email field. :return render user.html template if success """ form = UserForm() if form.validate_on_submit(): data = { "name": { "first": form.first_name.data, "last": form.last_name.data }, "gender": form.gender.data, "cell": form.phone.data, "email": form.email.data, "location": { "city": form.city.data, "country": form.country.data, "street": { "name": form.street.data }, }, "picture": { "large": form.picture.data }, } user = db.users.find_one({"email": form.email.data}) if not user: db.users.insert_one(data) flash("Successfully added") user = db.users.find_one_or_404({"email": form.email.data}) return render_template("user.html", user=user) flash("User with that email already exist") else: for field, errors in form.errors.items(): for error in errors: flash("Mistake in field '{}': {}".format( getattr(form, field).label.text, error)) return render_template("new_user.html", form=form)
def register(request): context = RequestContext(request) if request.method == 'POST': user_form = UserForm(request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() messages.success( request, 'Thank you for registering! Please wait for a staff member to activate your account.' ) return render(request, 'webapp/home.html') else: print(user_form.errors) else: user_form = UserForm() return render(request, 'webapp/register.html', context={'user_form': user_form})
def form_name_view(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(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 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'webapp/form_page.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def UserSignUpView(request): signup = False if request.method == 'POST': user_form = UserForm(data=request.POST) reporter_form = ReporterForm(data=request.POST) if user_form.is_valid() and reporter_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() reporter = reporter_form.save(commit=False) reporter.user_reporter = user reporter.save() signup = True else: print(user_form.errors, reporter_form.errors) else: user_form = UserForm() reporter_form = ReporterForm() return render(request, 'usersignup.html', { 'user_form': user_form, 'reporter_form': reporter_form, 'signup': signup })
def register(request): if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(request.POST, request.FILES) 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 profile.save() login(request, user, backend='django.contrib.auth.backends.ModelBackend') messages.success(request, 'Account successfully created!') return redirect('my_account') else: user_form = UserForm() profile_form = UserProfileForm() context_dict = {'user_form': user_form, 'profile_form': profile_form} return render(request, 'webapp/register.html', context_dict)
def update_user(user_id: str): """Update user route endpoint. Updated user info and render user.html template in case of success. :param user_id: unique record id :return render user.html template """ form = UserForm() if form.validate_on_submit(): data = { "name": { "first": form.first_name.data, "last": form.last_name.data }, "gender": form.gender.data, "cell": form.phone.data, "email": form.email.data, "location": { "city": form.city.data, "country": form.country.data, "street": { "name": form.street.data }, }, "picture": { "large": form.picture.data }, } db.users.find_one_and_replace({"_id": ObjectId(user_id)}, data) flash("Successfully added") user = db.users.find_one_or_404({"_id": ObjectId(user_id)}) return render_template("user.html", user=user) else: for field, errors in form.errors.items(): for error in errors: flash("Mistake in field '{}': {}".format( getattr(form, field).label.text, error)) user = db.users.find_one_or_404({"_id": ObjectId(user_id)}) return render_template("update_user.html", user=user, form=form)
def restaurant_sign_up(request): user_form = UserForm() restaurant_form = RestaurantForm() if request.method == "POST": user_form = UserForm(request.POST) restaurant_form = RestaurantForm(request.POST, request.FILES) if user_form.is_valid() and restaurant_form.is_valid(): new_user = User.objects.create_user(**user_form.cleaned_data) new_restaurant = restaurant_form.save(commit=False) new_restaurant.user = new_user new_restaurant.save() login(request, new_user, backend='django.contrib.auth.backends.ModelBackend') return redirect(restaurant_home) return render(request, "restaurant/sign_up.html", { "user_form": user_form, "restaurant_form": restaurant_form })
def reviewer_signup(request): """ Argument: `request`: Request from reviewer to sign up. This function is used for a new revieweer to sign up. """ context = RequestContext(request) registered = False if request.method == 'POST': print "we have a request to register" user_form = UserForm(data=request.POST) reviewer_form = ReviewerForm(data=request.POST) if user_form.is_valid() and reviewer_form.is_valid(): user = user_form.save() print "Forms are Valid" print user.username print user.first_name user.set_password(user.password) user.is_active = False user.save() reviewer = reviewer_form.save(commit=False) reviewer.user = user if 'picture' in request.FILES: reviewer.picture = request.FILES['picture'] reviewer.save() registered = True email_subject = "New reviewer has registered" email_message = """ New reviewer has registered. Details: Name:""" + user.first_name + """ """ + user.last_name + """" Email:""" + user.email + """ Waiting for your your approval""" #send_mail(email_subject, email_message, '*****@*****.**', ['*****@*****.**'],fail_silently=False) messages.success( request, "form successfully submitted. Waiting for activation from admin." ) return HttpResponseRedirect( reverse('webapp.views.reviewer_signup')) else: if reviewer_form.errors or user_form.errors: print user_form.errors, reviewer_form.errors else: reviewer_form = ReviewerForm() user_form = UserForm() context_dict = { 'user_form': user_form, 'reviewer_form': reviewer_form, 'registered': registered } return render_to_response('webapp/reviewer_signup.html', context_dict, context)
def signup_view(request): if request.user.is_authenticated: return HttpResponseRedirect('/menu') else: form = UserForm() if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): form.save() s = form.cleaned_data.get('username') messages.info(request, 'You are Register Successfully...!' + s) return HttpResponseRedirect('/login') return render(request, 'signup.html', {'form': form})
def register(request, user_type): if request.user.is_authenticated(): return HttpResponseRedirect('/') context_dict = {} if request.method == 'POST': user_form = UserForm(data=request.POST) user_profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and user_profile_form.is_valid(): # User user = user_form.save() user.set_password(user.password) user.save() # UserProfile user_profile = user_profile_form.save(commit=False) user_profile.user = user if 'picture' in request.FILES: user_profile.picture = request.FILES['picture'] else: user_profile.picture = 'img/user_avatar.png' user_profile.save() # Fan/Band Profile if user_type == 'fan': profile = FanProfile.objects.get_or_create( profile=user_profile) else: profile = BandProfile.objects.get_or_create( profile=user_profile) # Auto login. user_login(request) return HttpResponseRedirect('/') else: user_form = UserForm() profile_form = UserProfileForm() context_dict['profile_form'] = profile_form context_dict['user_form'] = user_form return render(request, 'webapp/register.html', context_dict)
def signup_user(request): """ :param request: :return: """ # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = UserForm(request.POST) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required form.save() # redirect to a new URL: return HttpResponseRedirect('/thanks/') # if a GET (or any other method) we'll create a blank form else: form = UserForm() return render(request, 'webapp/registration/signup.html', {'form': form})
def test_new_user_post(test_client): """Test new user page post""" form = UserForm() response = test_client.post("/user/new", data=form.data) assert response.status_code == 200
def contributor_signup(request): """ Argument: `request`: Request from contributor to sign up. This function is used for a new contributor to sign up. `Usage`: :: # Create an instance for UserForm() and ContributotForm() user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() # do stuff else: # do stuff """ context = RequestContext(request) registered = False if request.method == 'POST': print "we have a request to register" user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() print "Forms are Valid" print user.username print user.first_name user.set_password(user.password) user.is_active = False user.save() contributor = contributor_form.save(commit=False) contributor.user = user if 'picture' in request.FILES: contributor.picture = request.FILES['picture'] if 'validation_docs' in request.FILES: contributor.validation_docs = request.FILES['validation_docs'] contributor.save() registered = True email_subject = "New Contributor has registered" email_message = """ New Contributor has registered. Details: Name:""" + user.first_name + """ """ + user.last_name + """" Email:""" + user.email + """ Waiting for your your approval""" #send_mail(email_subject, email_message, '*****@*****.**', # ['*****@*****.**'],fail_silently=False) messages.success( request, "Form successfully submitted. Waiting for activation \ from admin.") return HttpResponseRedirect(reverse('webapp.views.contributor_signup')) else: if contributor_form.errors or user_form.errors: print user_form.errors, contributor_form.errors else: contributor_form = ContributorForm() user_form = UserForm() context_dict = { 'user_form': user_form, 'contributor_form': contributor_form, 'registered': registered, } return render_to_response('webapp/contributor_signup.html', context_dict, context)
def contributor_signup(request): """ Argument: `request`: Request from contributor to sign up. This function is used for a new contributor to sign up. `Usage`: :: # Create an instance for UserForm() and ContributotForm() user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() # do stuff else: # do stuff """ context = RequestContext(request) registered = False if request.method == 'POST': print "we have a request to register" user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() print "Forms are Valid" print user.username print user.first_name user.set_password(user.password) user.is_active = False user.save() contributor = contributor_form.save(commit=False) contributor.user = user if 'picture' in request.FILES: contributor.picture = request.FILES['picture'] if 'validation_docs' in request.FILES: contributor.validation_docs = request.FILES['validation_docs'] contributor.save() registered = True email_subject = "New Contributor has registered" email_message = """ New Contributor has registered. Details: Name:""" + user.first_name + """ """ + user.last_name + """" Email:""" + user.email + """ Waiting for your your approval""" # send_mail(email_subject, email_message, '*****@*****.**', # ['*****@*****.**'],fail_silently=False) messages.success( request, "Form successfully submitted. Waiting for activation from admin." ) return HttpResponseRedirect('webapp.views.contributor_signup') else: if contributor_form.errors or user_form.errors: print user_form.errors, contributor_form.errors else: contributor_form = ContributorForm() user_form = UserForm() context_dict = { 'user_form': user_form, 'contributor_form': contributor_form, 'registered': registered, } return render_to_response('webapp/contributor_signup.html', context_dict, context)
def contributor_signup(request): """ Argument: `request`: Request from contributor to sign up. This function is used for a new contributor to sign up. `Usage`: :: # Create an instance for UserForm() and ContributotForm() user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() # do stuff else: # do stuff """ context = RequestContext(request) registered = False if request.method == "POST": print "we have a request to register" user_form = UserForm(data=request.POST) contributor_form = ContributorForm(data=request.POST) if user_form.is_valid() and contributor_form.is_valid(): user = user_form.save() print "Forms are Valid" print user.username print user.first_name user.set_password(user.password) user.is_active = False user.save() contributor = contributor_form.save(commit=False) contributor.user = user if "picture" in request.FILES: contributor.picture = request.FILES["picture"] if "validation_docs" in request.FILES: contributor.validation_docs = request.FILES["validation_docs"] contributor.save() registered = True email_subject = "New Contributor has registered" email_message = ( """ New Contributor has registered. Details: Name:""" + user.first_name + """ """ + user.last_name + """" Email:""" + user.email + """ Waiting for your your approval""" ) # send_mail(email_subject, email_message, '*****@*****.**', # ['*****@*****.**'],fail_silently=False) messages.success( request, "Form successfully submitted. Waiting for activation \ from admin.", ) return HttpResponseRedirect(reverse("webapp.views.contributor_signup")) else: if contributor_form.errors or user_form.errors: print user_form.errors, contributor_form.errors else: contributor_form = ContributorForm() user_form = UserForm() context_dict = {"user_form": user_form, "contributor_form": contributor_form, "registered": registered} return render_to_response("webapp/contributor_signup.html", context_dict, context)