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 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 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): """ 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): """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): """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 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): """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): 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': 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 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 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 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(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 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 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 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 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 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_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 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")