def registration(request):
project_code = request.session['project_code']
if request.POST:
user_form = UserForm(request.POST)
vendor_form = UserDetailsForm(request.POST, request.FILES)
print vendor_form
if user_form.is_valid() and vendor_form.is_valid():
if(User.objects.filter(username = user_form.cleaned_data['username']).exists()):
messages.warning(request, 'username already exists with same name')
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form': vendor_form})
if (User.objects.filter(email=user_form.cleaned_data['email']).exists()):
messages.warning(request, 'Email already exists with same email')
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form': vendor_form})
obj = user_form.save()
vendor = UserDetails()
vendor.user_id = obj.id
vendor.address= vendor_form.cleaned_data['address']
vendor.contact = vendor_form.cleaned_data['contact']
vendor.dob = vendor_form.cleaned_data['dob']
vendor.profile_pic = vendor_form.cleaned_data['profile_pic']
vendor.video = vendor_form.cleaned_data['video']
vendor.age = vendor_form.cleaned_data['age']
vendor.city = vendor_form.cleaned_data['city']
vendor.profession = vendor_form.cleaned_data['profession']
vendor.country = vendor_form.cleaned_data['country']
vendor.gender = vendor_form.cleaned_data['gender']
vendor.language = vendor_form.cleaned_data['language']
vendor.education = vendor_form.cleaned_data['education']
vendor.project_code = project_code
vendor.domain = 'admin'
val = UserDetails.objects.filter(contact=vendor.contact, project_code=project_code)
vendor.save()
messages.warning(request, 'User added successfully')
return redirect('screencultures:home')
else:
messages.warning(request, 'Please enter Valid username and emailid')
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form': vendor_form ,'id': id, 'project_code' : project_code })
else:
user_form = UserForm()
vendor_form = UserDetailsForm()
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form':vendor_form, 'id': id, 'project_code' : project_code})
project_code = request.session['project_code']
if request.POST:
user_form = UserForm(request.POST)
vendor_form = UserDetailsForm(request.POST, request.FILES)
print vendor_form
if user_form.is_valid() and vendor_form.is_valid():
if(User.objects.filter(username = user_form.cleaned_data['username']).exists()):
messages.warning(request, 'username already exists with same name')
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form': vendor_form})
if (User.objects.filter(email=user_form.cleaned_data['email']).exists()):
messages.warning(request, 'Email already exists with same email')
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form': vendor_form})
obj = user_form.save()
vendor = UserDetails()
vendor.user_id = obj.id
vendor.address= vendor_form.cleaned_data['address']
vendor.contact = vendor_form.cleaned_data['contact']
vendor.dob = vendor_form.cleaned_data['dob']
vendor.profile_pic = vendor_form.cleaned_data['profile_pic']
vendor.video = vendor_form.cleaned_data['video']
vendor.age = vendor_form.cleaned_data['age']
vendor.city = vendor_form.cleaned_data['city']
vendor.profession = vendor_form.cleaned_data['profession']
vendor.country = vendor_form.cleaned_data['country']
vendor.gender = vendor_form.cleaned_data['gender']
vendor.language = vendor_form.cleaned_data['language']
vendor.education = vendor_form.cleaned_data['education']
vendor.project_code = project_code
vendor.domain = 'admin'
val = UserDetails.objects.filter(contact=vendor.contact, project_code=project_code)
vendor.save()
messages.warning(request, 'User added successfully')
return redirect('screencultures:home')
else:
messages.warning(request, 'Please enter Valid username and emailid')
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form': vendor_form ,'id': id, 'project_code' : project_code })
else:
user_form = UserForm()
vendor_form = UserDetailsForm()
return render(request, 'registration.html', {'user_form': user_form, 'vendor_form':vendor_form, 'id': id, 'project_code' : project_code})
No comments:
Post a Comment