def participate(request): if request.user.is_authenticated(): return HttpResponseRedirect(reverse('my_account')) if request.method == "POST": shop_form = ParticipateForm(request.POST) login_form = CustomLoginForm() if shop_form.is_valid(): shop_first_name = shop_form.cleaned_data.get('contact_first_name') shop_last_name = shop_form.cleaned_data.get('contact_last_name') shop_contact_email = shop_form.cleaned_data.get('contact_email') shop_password = shop_form.cleaned_data.get('password') shop_retype_password = shop_form.cleaned_data.get('retype_password') user = User.objects.create_user(shop_contact_email, shop_contact_email, shop_password) user.first_name = shop_first_name user.last_name = shop_last_name user.save() shop = Shop(user = user) shop.name = shop_form.cleaned_data.get('name') shop.public_phone = shop_form.cleaned_data.get('public_phone') shop.address_line_1 = shop_form.cleaned_data.get('address_line_1') shop.address_line_2 = shop_form.cleaned_data.get('address_line_2') shop.city = shop_form.cleaned_data.get('city') shop.state = shop_form.cleaned_data.get('state') shop.zip_code = shop_form.cleaned_data.get('zipcode') shop.URL = shop_form.cleaned_data.get('website') coordinates = gmaps.geocode(shop.address_line_1+", "+shop.address_line_2+", "+shop.city+", "+shop.state+", "+shop.zipcode) shop.latitude = coordinates[0]['geometry']['location']['lat'] shop.latitude = coordinates[0]['geometry']['location']['lng'] shop.save() return HttpResponseRedirect(reverse('index')) else: shop_form = ParticipateForm() login_form = CustomLoginForm() return render(request, "participate.html", {'store_form': shop_form, 'form':login_form})