def contact(request): """View handle contact form requests""" if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): message = request.POST['message'] subject = request.POST['subject'] send_mail( subject, "Message from: " + request.POST['email'] + "Message: " + message, '*****@*****.**', ['*****@*****.**'], fail_silently=False, ) messages.success(request, "Your message has been sent.We will get back to you within 7 working days!", extra_tags="alert-success") return redirect(reverse('index')) else: messages.error(request, "Unable to send message at this time", extra_tags="alert-danger") else: contact_form = ContactForm() return render(request, 'contact.html', {'contact_form': contact_form})
def contact(request): """View handle contact form requests""" if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): message = request.POST['message'] subject = request.POST['subject'] send_mail( subject, "Message from: " + request.POST['email'] + "Message: " + message, '*****@*****.**', ['*****@*****.**'], fail_silently=False, ) messages.success(request, "Your message has been sent!", extra_tags="alert-success") return redirect(reverse('index')) else: messages.error(request, "Unable to send message at this time", extra_tags="alert-danger") else: contact_form = ContactForm() return render(request, 'contact.html', {'contact_form': contact_form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): mail_admins_sender( form.cleaned_data['subject'], 'Message from %s <%s>:\n\n%s' % ( form.cleaned_data['name'], form.cleaned_data['email'], form.cleaned_data['message'] ), form.cleaned_data['email'], ) messages.info( request, _('Message has been sent to administrator.') ) return HttpResponseRedirect(reverse('home')) else: initial = {} if request.user.is_authenticated(): initial['name'] = request.user.get_full_name() initial['email'] = request.user.email if 'subject' in request.GET: initial['subject'] = request.GET['subject'] form = ContactForm(initial=initial) return render_to_response('contact.html', RequestContext(request, { 'form': form, 'title': _('Contact'), }))
def contact(request): if request.method == 'POST': contact_form = ContactForm(request.POST or None) if contact_form.is_valid(): data = contact_form.cleaned_data city = data.get('city') language = data.get('language') email = data.get('email') qs = Error.objects.filter(timestamp=dt.date.today()) if qs.exists(): # если добавлена запись err = qs.first() data = err.data.get('user_data', [])# если данные пустые мы получаемпустой список data.append({'city': city, 'email': email, 'language': language})# если данные есть они наполняются данными err.data['user_data'] = data # и добавим новые данные перзапишем err.save() else:# если пусто, тогда создаем новый список data = {'user_data': [ {'city': city, 'email': email, 'language': language} ]} Error(data=data).save() messages.success(request, 'Данные отправлены администрации.') return redirect('accounts:update') else: return redirect('accounts:update')# если форма н евалидна else: return redirect('accounts:login')
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): mail_admins_sender( form.cleaned_data['subject'], 'Message from %s <%s>:\n\n%s' % (form.cleaned_data['name'], form.cleaned_data['email'], form.cleaned_data['message']), form.cleaned_data['email'], ) messages.info(request, _('Message has been sent to administrator.')) return HttpResponseRedirect(reverse('home')) else: initial = {} if request.user.is_authenticated(): initial['name'] = request.user.get_full_name() initial['email'] = request.user.email if 'subject' in request.GET: initial['subject'] = request.GET['subject'] form = ContactForm(initial=initial) return render_to_response( 'contact.html', RequestContext(request, { 'form': form, 'title': _('Contact'), }))
def contact_view(request): if request.method == 'POST': contact_form = ContactForm(request.POST or None) if contact_form.is_valid(): data = contact_form.cleaned_data city = data.get('city') language = data.get('language') email = data.get('email') qs = Error.objects.filter(timestamp=datetime.date.today()) if qs.exists(): err = qs.first() data = err.data.get({'user_data', []}) data.append({ 'city': city, 'language': language, 'email': email }) err.save() messages.success(request, 'Спасибо:) Данные отправлены.') else: data = [{'city': city, 'language': language, 'email': email}] Error(data=data).save() return redirect('accounts:preference') else: return redirect('accounts:preference') else: return redirect('accounts:login')
def post(self, request, *args, **kwargs): form = ContactForm(data=request.POST) if form.is_valid(): self.send_mail(form.cleaned_data) form = ContactForm() return render(request, self.template_name , {'form': form}) return render(request, self.template_name, {'form': form})
def contact(request): """ Sends an email to the user when someone submits the form. """ username = request.subdomain user = get_object_or_404(User, username=username) profile = user.get_profile() customer = user.customer if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] body = message if sender: body = body + '\n\nSender: ' + sender send_mail('Someone contacted you!', body, '*****@*****.**', [user.email]) variables = RequestContext(request, {'form': ContactForm(), 'username': username, 'profile': profile, 'customer': customer, 'thanks': True} ) return render_to_response('portfolios/contact_page.html', variables) else: form = ContactForm() variables = RequestContext(request, {'form': form, 'username': username, 'profile': profile, 'customer': customer,} ) return render_to_response('portfolios/contact_page.html', variables)
def contact(request): if request.method == 'POST': contact_form = ContactForm(request.POST or None) if contact_form.is_valid(): data = contact_form.cleaned_data city = data.get('city') language = data.get('language') email = data.get('email') qs = Error.objects.filter(timestamp=dt.date.today()) if qs.exists(): err = qs.first() data = err.data.get('user_data', []) data.append({ 'city': city, 'email': email, 'language': language }) err.data['user_data'] = data err.save() else: data = [{'city': city, 'email': email, 'language': language}] Error(data=f"user_data:{data}").save() messages.success(request, 'Данные отправлены администрации.') return redirect('accounts:update') else: return redirect('accounts:update') else: return redirect('accounts:login')
def preference_view(request): contact_form = ContactForm() if request.user.is_authenticated: user = request.user if request.method == 'POST': form = UserPreferenceForm(request.POST) if form.is_valid(): data = form.cleaned_data user.city = data['city'] user.language = data['language'] user.mailing = data['mailing'] user.save() messages.info(request, 'Данные обновлены') return redirect('accounts:preference') else: form = UserPreferenceForm( initial={ 'city': user.city, 'language': user.language, 'mailing': user.mailing }) return render(request, 'accounts/preference.html', { 'form': form, 'contact_form': contact_form }) else: return redirect('accounts:login')
def update_view(request): contact_form = ContactForm() if request.user.is_authenticated: user = request.user if request.method == 'POST': form = UserUpdateForm(request.POST) if form.is_valid(): data = form.cleaned_data user.city = data['city'] user.language = data['language'] user.send_email = data['send_email'] user.save() messages.success(request, 'Данные сохраненны.') return redirect('accounts:update') form = UserUpdateForm( initial={ 'city': user.city, 'language': user.language, 'send_email': user.send_email }) return render(request, 'accounts/update.html', { 'form': form, 'contact_form': contact_form }) else: return redirect('accounts:login')
def email(request): if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] from_email = form.cleaned_data['from_email'] message = form.cleaned_data['message'] try: send_mail(subject, message, from_email, ['*****@*****.**']) except BadHeaderError: return HttpResponse('Invalid header found.') return redirect('thanks') return render(request, "contact.html", {'form': form})
def contact_page(request): contact_form = ContactForm(request.POST or None) context = { "title": "Contact", "content": "This Is Contact Page", "form": contact_form } if contact_form.is_valid(): if request.is_ajax(): return JsonResponse({"message": "Sucess"}, status=200) if contact_form.errors: errors = contact_form.errors.as_json() return HttpResponse(errors, status=400, content_type='application/json') return render(request, "contact/view.html", context)
def contact(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): mail_admins_contact("%(subject)s", CONTACT_TEMPLATE, form.cleaned_data, form.cleaned_data["email"]) messages.info(request, _("Message has been sent to administrator.")) return redirect("home") else: initial = {} if request.user.is_authenticated(): initial["name"] = request.user.get_full_name() initial["email"] = request.user.email if "subject" in request.GET: initial["subject"] = request.GET["subject"] form = ContactForm(initial=initial) return render_to_response("accounts/contact.html", RequestContext(request, {"form": form, "title": _("Contact")}))
def contact(request): """View handle contact form requests""" if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): message = request.POST['message'] subject = request.POST['subject'] send_mail( subject, "Message from: " + request.POST['email'] + "\nMessage: " + message, 'SERVER_EMAIL', ['*****@*****.**'], fail_silently=False, ) messages.success(request, "Your message has been sent!", extra_tags="alert-success") return redirect(reverse('index')) else: messages.error(request, "Unable to send message at this time", extra_tags="alert-danger") else: if request.user.is_authenticated: contact_form = ContactForm(initial={ 'email': request.user.email, 'name': request.user.get_full_name }) else: contact_form = ContactForm() return render(request, 'contact.html', {'contact_form': contact_form})
def contact(request): """ Sends an email to me when someone submits the contact form. """ if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] body = 'Sender: ' + sender + '\n\nMessage:\n' + message send_mail('Someone submitted the contact form', body, '*****@*****.**', ['*****@*****.**']) return HttpResponseRedirect('/thanks/') else: form = ContactForm() variables = RequestContext(request, {'form': form} ) return render_to_response('contact_page.html', variables)
def post(self, request, *args, **kwargs): form = ContactForm(request.POST) if form.is_valid(): form.save() name = form.cleaned_data['contact_person'] phone = form.cleaned_data['phone'] message = form.cleaned_data['company_name'] email = form.cleaned_data['email'] email = EmailMessage( subject='Inquiry from ' + str(email), body='Name: ' + str(name) + '\n' + 'message: ' + str(message) + '\n' + 'email: ' + str(email) + '\n' + 'phonenumber: ' + str(phone) + '\n', from_email='*****@*****.**', to=[]) email.send() return redirect(reverse('accounts:index'))
def create_contact(request): form = ContactForm() if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() return redirect('contact') context = {'form': form} return render(request, 'contact/create_contact.html', context)
def contact_add(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): form.save() else: form = ContactForm() return HttpResponseRedirect(reverse('contact_list'))
def login_view(request): contact_form = ContactForm() form = UserLoginForm(request.POST or None) if form.is_valid(): data = form.cleaned_data email = data.get('email') password = data.get('password') user = authenticate(request, email=email, password=password) login(request, user) return redirect('home') return render(request, 'accounts/login.html', {'form': form})
def get(self, request, *args, **kwargs): request.session['cart'] = True form = ContactForm() context = {'form': form} prod_obj = Product.objects.featured() count = prod_obj.count() ads_obj = prod_obj[random.randint(0, count-1)] ads_obj_db , created = Ads.objects.get_or_create(product = ads_obj) ads_obj_db.views += 1 ads_obj_db.save() context["ads_obj"] = ads_obj return render(request, self.template_name, context)
def contact(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): mail_admins_sender( form.cleaned_data["subject"], "Message from %s <%s>:\n\n%s" % (form.cleaned_data["name"], form.cleaned_data["email"], form.cleaned_data["message"]), form.cleaned_data["email"], ) messages.info(request, _("Message has been sent to administrator.")) return HttpResponseRedirect(reverse("home")) else: initial = {} if request.user.is_authenticated(): initial["name"] = request.user.get_full_name() initial["email"] = request.user.email if "subject" in request.GET: initial["subject"] = request.GET["subject"] form = ContactForm(initial=initial) return render_to_response("contact.html", RequestContext(request, {"form": form, "title": _("Contact")}))
def updateContact(request, pk): action = 'update' cont = Contact.objects.get(id=pk) form = ContactForm(instance=cont) if request.method == 'POST': form = ContactForm(request.POST, instance=cont) if form.is_valid(): form.save() return redirect('/contact/' + str(cont.id)) context = {'action': action, 'form': form} return render(request, 'contact/contact_update.html', context)
def contact_edit(request): if request.method == "POST": id = request.POST.get('id') contact = Contact.objects.get(id=id) form = ContactForm(request.POST, instance=contact) if form.is_valid(): form.save() else: form = ContactForm(instance=contact) return HttpResponseRedirect(reverse('contact_list'))
def index(request): if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): contact_form.save() messages.success(request, 'form was posted') else: contact_form = ContactForm() return render(request, 'index.html', {'contact_form': contact_form})
def contact_page(request): request.session['cart'] = True form = ContactForm(request.POST or None) context = { 'title': "Contact", 'content': "Please send us a message here.", 'form': form, } if form.is_valid(): if request.is_ajax(): return JsonResponse({"message": "Thank You for your submisssion!",}) if form.errors: if request.is_ajax(): errors = form.errors.as_json() return HttpResponse(errors, status=400, content_type='application/json') return render(request, 'contact/view.html',context) def get_context_data(self, **kwargs): context = super(contact_page, request).get_context_data(**kwargs) context["contact"] = "something" return context
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() return redirect('main:main') else: raise ValidationError('Form is not valid.') else: form = ContactForm() context = {'contact_form': form} return render(request, 'main/contact.html', context)
def home(request): form = ContactForm() products = ShopItem.objects.all().order_by('-id')[:3] if request.method == "POST": subject = 'New Contact {}'.format(request.POST.get("contact_name")) message = request.POST.get("content") email_from = request.POST.get("contact_email") msg = EmailMultiAlternatives(subject, message, email_from, [settings.EMAIL_ADDRESS]) msg.send() return HttpResponseRedirect('/') return render(request, "accounts/home.html", { 'form': form, 'products': products })
def ContactUsView(request): title = 'Contact Us' title_align_center = True form = ContactForm(request.POST or None) if form.is_valid(): form_email = form.cleaned_data.get("email") form_message = form.cleaned_data.get("message") form_full_name = form.cleaned_data.get("full_name") subject = form.cleaned_data.get("subject") from_email = settings.EMAIL_HOST_USER to_email = [ form_email, ] contact_message = "%s: %s via %s" % (form_full_name, subject, form_email) some_html_message = form_message send_mail(subject, contact_message, from_email, to_email, html_message=some_html_message, fail_silently=False) if request.user.is_authenticated: user = request.user tutor = get_object_or_404(UserProfile, user=user) context = { "tutor": tutor, } context = { "form": form, "title": title, "title_align_center": title_align_center, # "tutor": tutor, } return render(request, "contactus/contact_us.html", context)
def contact_view(request): if request.method == "POST": contact_form = ContactForm(request.POST or None) if contact_form.is_valid(): data = contact_form.cleaned_data city = data.get("city") language = data.get("language") email = data.get("email") qs = Error.objects.filter(timestamp=dt.date.today()) if qs.exists(): err = qs.first() data = err.data.get("user_data", []) data.append({"city": city, "language": language, "email": email}) err.data["user_data"] = data err.save() else: data = [{"city": city, "language": language, "email": email}] Error(data=f"user_data:{data}").save() messages.success(request, 'Данные отправлены') return redirect("accounts:update") else: return redirect("accounts:update") else: return redirect("accounts:login")
def contact(request): if request.method == 'POST': u_form = ContactForm(request.POST) if u_form.is_valid(): u_form.save() messages.success(request, f'Your Contact Send Successfully') return redirect('index') else: u_form = ContactForm() context = { 'form': u_form } return render(request, 'contact.html', context)
def cart(request): customer = Customer.objects.get(id=request.session['customer']) contactform = ContactForm(instance=customer) if request.method == 'POST': contactform = ContactForm(request.POST, instance=customer) if contactform.is_valid(): contactform.save() return redirect('cart') context = { 'name': customer.name, 'contact': customer.contact, 'address': customer.address, 'contactform': contactform } return render(request, 'foods/cart.html', context)
def update_view(request): contact_form = ContactForm() if request.user.is_authenticated: user = request.user if request.method == 'POST': form = UserUpdateForm(request.POST) if form.is_valid(): data = form.cleaned_data user.city = data['city'] user.language = data['language'] user.is_subscribed = data['is_subscribed'] user.save() messages.success(request, 'User successfully updated!') return redirect('update') form = UserUpdateForm( initial={'city': user.city, 'language': user.language, 'is_subscribed': user.is_subscribed}) return render(request, 'accounts/update.html', {'form': form, 'contact_form': contact_form}) else: return redirect('login')
def update_view(request): contact_form = ContactForm() # форма для заплнения пожелания if request.user.is_authenticated: user = request.user# проверяем зарегестрировался ли пользователь if request.method == 'POST': form = UserUpdateForm(request.POST)# получив данные из формы, изменить значение в этом юзере if form.is_valid():# если форма валидна data = form.cleaned_data user.city = data['city']# берем данные из data user.language = data['language'] user.send_email = data['send_email'] user.save() messages.success(request, 'Данные сохраненны.') return redirect('accounts:update') form = UserUpdateForm(# нполняем форму начальными значениями котры есть у юзера initial={'city': user.city, 'language': user.language, 'send_email': user.send_email}) return render(request, 'accounts/update.html', {'form': form, 'contact_form': contact_form})# будет доступна contact_form форма для заплнения пожелания else: return redirect('accounts:login')# если нет перенаправить на страницу входа
def update_view(request): contact_form = ContactForm() if request.user.is_authenticated: user = request.user if request.method == "POST": form = UserUpdateForm(request.POST) if form.is_valid(): data = form.cleaned_data user.city = data["city"] user.language = data["language"] user.send_email = data["send_email"] user.save() messages.success(request, "Настройки успешно изменены") return redirect("accounts:update") else: form = UserUpdateForm(initial={"city": user.city, "language": user.language, "send_email": user.send_email}) context = {"form": form, "contact_form": contact_form} return render(request, "accounts/update.html", context) else: return redirect("accounts:login")