def edit_contact(request): contact = get_object_or_404(Contact, pk=1) if request.method == 'POST': form_person = PersonForm( request.POST, request.FILES, prefix='person', instance=contact.person ) form_contact = ContactForm( request.POST, request.FILES, prefix='contact', instance=contact ) is_ajax_request = form_person.data.get('person-is_ajax_request',0) if form_person.is_valid() and form_contact.is_valid(): # Process the data in form.cleaned_data form_person.save() form_contact.save() response = json.dumps({ 'success': True, 'html': 'Data is succesfully updated.' }) else: html = form_person.errors.as_ul() + form_contact.errors.as_ul() response = json.dumps({'success': False, 'html': html}) if is_ajax_request: return HttpResponse(response, content_type="application/javascript") else: if form_person.is_valid() and form_contact.is_valid(): return HttpResponseRedirect(reverse('index')) # Redirect after POST else: form_contact = ContactForm( prefix="contact", instance=contact ) form_person = PersonForm( prefix="person", instance=contact.person ) return render_to_response('edit_contact.html', { 'contact': contact, 'form_contact': form_contact, 'form_person': form_person, }, context_instance=RequestContext(request) )
def contact(request): mail_sent = None if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): url = request.build_absolute_uri() name = form.cleaned_data['name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] subject = u'Contato de ' + name message = form.cleaned_data['message'] message = u'Mensagem enviada por %s <%s> %s \n\n%s \n\n\nMensagem enviada através da página:\n%s' % (name, email, phone, message, url) try: mail_managers(subject, message, fail_silently = False) mail_sent = True except Exception as e: mail_sent = False if settings.DEBUG: raise # reraises the exception else: form = ContactForm() template = loader.get_template('contact/contact.html') context = RequestContext(request, { 'form' : form, 'mail_sent' : mail_sent, }) return HttpResponse(template.render(context))
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data subject=cd['subject'] message=cd['message'] from_email=cd.get('from_email', '*****@*****.**') sender=EMAIL_HOST_USER try: send_mail(subject,[from_email,message],sender, ['*****@*****.**'], fail_silently=False) thread = Thread(target=send_mail,args=(subject,message,from_email,['*****@*****.**'])) thread.start() except BadHeaderError: return HttpResponse('Invalid header found.') return HttpResponseRedirect('/poohApp/thanks/') else: form = ContactForm( initial = {'subject':'I love this one!'} ) c = {} c = RequestContext(request, { 'form':form, }) return render_to_response('contact/contact.html',c)
def contact(request): if request.method == 'POST': c={} form = ContactForm(request.POST) if form.is_valid(): feedback = Feedback() try: feedback.name = form.cleaned_data["con_name"] feedback.email = form.cleaned_data["con_emailid"] try: feedback.mobile = str(form.cleaned_data["con_mobile"]) except: feedback.mobile = "" #if feedback.mobile is None: # feedback.mobile = 0 feedback.value = form.cleaned_data["con_text"] feedback.save() c.update({"success":True}) except: print sys.exc_info()[1] return HttpResponse('Error in sending feedback'+str(vars(feedback))+str(sys.exc_info()[0])) c.update(csrf(request)) return render_to_response('contact.html',c) else: c={} c.update({"form":form}) c.update(csrf(request)) return render_to_response('contact.html',c) c={} c.update(csrf(request)) return render_to_response('contact.html',c)
def contato(request): sucesso = False if request.method == 'POST': # If the form has been submitted... form = ContactForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass contato = Contato() contato.nome = form.cleaned_data['nome'] contato.email = form.cleaned_data['email'] contato.assunto = form.cleaned_data['assunto'] contato.mensagem = form.cleaned_data['mensagem'] contato.save() sucesso = True else: form = ContactForm() # An unbound form try: texto_contato = TextoContato.objects.get(slug='texto_contato') except: texto_contato = None try: configs_contato = ConfiguracoesContato.objects.get(slug='configs_contato') except: configs_contato = None return render_to_response('contact.html',{'form':form,'current':'contato','sucesso':sucesso,'texto_contato':texto_contato,'configs_contato':configs_contato},context_instance=RequestContext(request))
def contact(request): errors = [] if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data try: send_mail( cd['subject'], cd['message'] + " Send by " + cd['email'], cd.get('email', '*****@*****.**'), #'*****@*****.**'), ['*****@*****.**'], #['*****@*****.**'], ) except: # Because of the verfication problem with SES. send_mail( cd['subject'], cd['message'] + " Send by " + cd['email'], cd.get('mail', '*****@*****.**'), ['*****@*****.**'], ) messages.add_message(request, messages.SUCCESS, ugettext("The enquiry has been sent.")) #return HttpResponseRedirect('/contact/thanks') # thanks/ return render_to_response('contact/thanks.html', context_instance=RequestContext(request)) else: form = ContactForm( initial={'subject':'For the singularity!'}) return render_to_response('contact/form.html', {'form':form}, context_instance=RequestContext(request))
def makeorder(request): order=OrderRequest(request) if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): try: cd = form.cleaned_data cd["decoration_id"] = order.decorationId if cd["DecorationIngredient"]: cd["decoration_ingredient_name"] = DecorationIngredient.objects.get(pk=cd["DecorationIngredient"]).title_ru utils.send_order_email(cd) return HttpResponseRedirect(reverse("mail_sent_confirmation")) print "Mail sent" except Exception as ex: form._errors["__all__"] = form.error_class([str(ex)]) print "Error in mail sending!!!" else: print "data is not valid", form.errors else: form = ContactForm() data = {"order": order, "form": form, "decoration_ingredients": DecorationIngredient.objects.all()} response=render_to_response("makeorder.html", data, context_instance=RequestContext(request, processors=[base_proc])) #order.save(response) return response
def contact_add_typed(request, type_id, response_format='html'): "Contact add with preselected type" contact_type = get_object_or_404(ContactType, pk=type_id) if not request.user.profile.has_permission(contact_type, mode='x'): return user_denied(request, message="You don't have access to create " + unicode(contact_type)) if request.POST: if 'cancel' not in request.POST: form = ContactForm( request.user.profile, contact_type, request.POST, files=request.FILES) if form.is_valid(): contact = form.save(request, contact_type) contact.set_user_from_request(request) return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id])) else: return HttpResponseRedirect(reverse('identities_index')) else: form = ContactForm(request.user.profile, contact_type) types = Object.filter_by_request( request, ContactType.objects.order_by('name')) return render_to_response('identities/contact_add_typed', {'type': contact_type, 'types': types, 'form': form}, context_instance=RequestContext(request), response_format=response_format)
def contact_edit(request, contact_id, response_format='html'): "Contact edit" contact = get_object_or_404(Contact, pk=contact_id) if not request.user.profile.has_permission(contact, mode='w'): return user_denied(request, message="You don't have write access to this Contact") if request.POST: if 'cancel' not in request.POST: form = ContactForm(request.user.profile, contact.contact_type, request.POST, files=request.FILES, instance=contact) if form.is_valid(): contact = form.save(request) return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id])) else: return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id])) else: form = ContactForm( request.user.profile, contact.contact_type, instance=contact) types = Object.filter_by_request( request, ContactType.objects.order_by('name')) return render_to_response('identities/contact_edit', {'contact': contact, 'types': types, 'form': form}, context_instance=RequestContext(request), response_format=response_format)
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): fromemail = form.cleaned_data['from_email'] header = form.cleaned_data['subject'] to = DEFAULT_ADMIN_EMAIL_LIST content = form.cleaned_data['content'] msg = EmailMultiAlternatives(header, content, fromemail, to) msg.content_subtype = "html" msg.send() return HttpResponseRedirect('/virtual/confirm/?h=success&t=Email Sent!&c=We will try to come back to you ASAP! &b1=main&b2=console') else: if request.user.is_authenticated(): init_data = {'from_email':request.user.email} form = ContactForm(initial=init_data) else: form = ContactForm() args = {} args.update(csrf(request)) args['contactform'] = form args['user'] = request.user return render_to_response('contact_form.html', args)
def contact(request): c = {} c.update(csrf(request)) if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data #send_mail( # cd['subject'], # cd['message'], # cd.get('email', '*****@*****.**'), # ['*****@*****.**'], #) #return HttpResponse("Your post was submitted successfully!") return HttpResponseRedirect('/bookstore/search/') else: return render_to_response('bookstore/contact_form.html', {'form': form, 'hometab': "selected"}, context_instance=RequestContext(request) ) else: form = ContactForm( initial={'subject': 'I love your site!'} ) return render_to_response('bookstore/contact_form.html', {'form': form, 'hometab': "selected"}, context_instance=RequestContext(request), )
def contact(request): # errors = [] if request.method == "POST": # if not request.POST.get('subject', ''): # errors.append('Enter a subject.') # if not request.POST.get('message', ''): # errors.append('Enter a message.') # if request.POST.get('email') and '@' not in request.POST['email']: # errors.append('Enter a valid e-mail address.') # if not errors: form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data s = smtplib.SMTP("smtp.gmail.com", "25") s.ehlo() s.starttls() s.login("*****@*****.**", "su123456") send_mail( cd["subject"], cd["message"], cd.get("email", "*****@*****.**"), ["*****@*****.**"] ) s.quit() return HttpResponseRedirect("/accounts/contact/thanks/") else: form = ContactForm(initial={"subject": "I love this one!"}) c = RequestContext(request, {"form": form}) return render_to_response("contact/contact_form.html", context_instance=c)
def contact(request): form = ContactForm() if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): return HttpResponseRedirect('thanks/') return render(request, 'contact.html', {'form': form})
def contactanos(request, razon_contacto): template = "contactanos.html", if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): tema = form.cleaned_data['tema'] mensaje = form.cleaned_data['mensaje'] correo = form.cleaned_data['correo'] nombre = form.cleaned_data['nombre'] enviar_mail_contactanos(nombre, correo, tema, mensaje) return redirect('perfiles:despues_contacto', razon_contacto=razon_contacto, correo_contacto=correo) else: if razon_contacto == "registrar_biblioteca": form = ContactForm(initial={'tema': "Registrar nueva Biblioteca Compartida"}) form.fields['mensaje'].placeholder = "Hola, deseo registrar una Biblioteca Compartida ..." elif razon_contacto == "donacion": form = ContactForm(initial={'tema': "Hacer una donación de libros"}) form.fields[ 'mensaje'].placeholder = "Hola, deseo donar mis libros, quiero que alguien más pueda leerlos ..." else: form = ContactForm() context = {'form': form, 'razon_contacto': razon_contacto} return render(request, template, context)
def main_list(request): peer_list = Peer.objects.all() if request.method == 'POST': c_form = ContactForm(request.POST) if c_form.is_valid(): peer = c_form.save(commit=False) peer.user = request.user peer.save() else: c_form = ContactForm() if 'q' in request.GET and request.GET['q']: q = request.GET['q'] people = Peer.objects.filter(name__icontains=q) return render(request, 'peer-search-block.html', { 'peer_list': peer_list, 'c_form': c_form, 'people': people, 'query': q }) return render(request, 'peer-list-block.html', { 'peer_list': peer_list, 'c_form': c_form, })
def show_about(request): if request.method == "POST": copyRequest = request.POST.copy() if request.user.is_authenticated(): ## in case of user is logged in, username and email fields are not shown ## get username and email from database user = MyUser.objects.get(username = request.user) copyRequest['name'] = user.username copyRequest['email'] = user.email form = ContactForm(copyRequest) if form.is_valid(): recipients = [settings.ADMINS[0][1], ] name = form.cleaned_data['name'] subject = "Mysite message from {0}".format(name) message = form.cleaned_data['message'] sender = form.cleaned_data['email'] messages.success(request, "Сообщение отправлено") send_mail(subject, message, sender, recipients) return HttpResponseRedirect(reverse('thankyou_url')) # Redirect after POST else: pass else: form = ContactForm() template_context = {'form':form, 'my_age':get_my_age(),} return render_to_response('about/form.html', template_context, RequestContext(request))
def contact(request): if request.method == 'POST': # create a form instance and populate it with data from the request: form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] message_1 = form.cleaned_data['message'] sender = form.cleaned_data['sender'] cc_myself = form.cleaned_data['cc_myself'] message = message_1 + '\n' + sender recipients = ['*****@*****.**'] if cc_myself: recipients.append(sender) send_mail(subject, message, sender, recipients) return HttpResponseRedirect('http://www.culture-clap.com/thankyou.html') else: form = ContactForm() return render(request, 'contact.html', {'form': form, })
def contact(request): title='Contact Us' 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 = 'Visitor Message' from_email = settings.EMAIL_HOST_USER to_email = [form_email, '*****@*****.**'] #email is sent to form_email and [email protected] contact_message = "fullname is %s message : %s email : %s" % ( form_full_name, form_message, form_email ) send_mail(subject, contact_message, from_email, to_email, fail_silently=False) context = { "form": form, "title": title, } return render(request, "forms.html", context)
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() contact = form.instance mandir_staff = getattr(settings, "MANDIR_STAFF", None) ## Send Thank you email message = "Dear " + contact.name + "\n" message += "Thank you for your message. We will get back to you soon!" send_mail("Thank you from Ved Mandir!", message, '*****@*****.**', [contact.email]) ## Notify Ved mandir staff message = "New Contact message received from: " + contact.name + "\n" message += "Subject: " + contact.subject + "\n" message += "Message: \n" message += contact.message + "\n" message += "-----------------------------------------------------\n" send_mail("New Contact Message", message, '*****@*****.**', mandir_staff) return render(request, 'ved/contact.html', {} ) else: return render(request, 'ved/contact.html', {'form':form} ) else: form = ContactForm() return render(request, 'ved/contact.html', {'form':form} )
def contact(request): test_expression, answer = produce_expression() request.session['last_answer'] = request.session.get('answer', None) request.session['answer'] = answer #answer = request.session['answer'] if request.method == 'POST': # If the form has been submitted... # form = ContactForm(request.POST) # A form bound to the POST data # A form bound to the POST data form = ContactForm(request.POST, request=request) if form.is_valid(): # All validation rules pass cd = form.cleaned_data recipients = ['*****@*****.**'] if cd['cc_myself']: recipients.append(cd['sender']) send_mail(cd['subject'], cd['message'], '*****@*****.**', recipients, fail_silently=False) # Process the data in form.cleaned_data # Redirect after POST return HttpResponseRedirect(reverse('index')) # return HttpResponseRedirect('/thanks/') # Redirect after POST else: form = ContactForm() # An unbound form c = {'subtitle': 'Contact Us', 'form': form, 'test': test_expression} c.update(csrf(request)) return render_to_response('blog_app/contact_form.html', c)
def index(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): t = loader.get_template('feedback/emails/body.txt') c = { 'data': form.cleaned_data, 'site': Site.objects.get_current(), 'date': datetime.now(), } subject = render_to_string('feedback/emails/subject.txt', c).replace('\n','') html_body = t.render(Context(c)) text_body = strip_tags(html_body) msg = EmailMultiAlternatives(subject, text_body, form.cleaned_data['email'], settings.MANAGERS) msg.attach_alternative(html_body, "text/html") msg.send() form = ContactForm() messages.success(request, "Ваше сообщение успешно отправлено!") else: form = ContactForm() return render(request, 'feedback/index.html', {'form':form})
def contatti (request): """ Visualizza il form di contatto in caso di get mentre in caso di post invia la mail. :param request: la richiesta :return: il render del template corretto a seconda dell'operazione """ if request.method == 'POST': # If the form has been submitted... form = ContactForm(request.POST) #form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data subject = form.cleaned_data['oggetto'] message = form.cleaned_data['messaggio'] sender = form.cleaned_data['email'] cc_myself = form.cleaned_data['invia_una_copia_a_me_stesso'] recipients = ['*****@*****.**'] message=message+'\n\nModulo inviato da: '+sender if cc_myself: recipients.append(sender) send_mail(subject, message, sender, recipients) context={'titolo':'Messaggio inviato','corpo':"La tua richiesta e' stata registrata."} return render(request,'GestioneUtenti/avviso.html',context) # Redirect after POST else: return render(request,'AsteOnLine/contatti.html',{ 'form': form, 'messaggio':'Compila i campi obbligatori' }) else: # GET request: just visualize the form form = ContactForm() # An unbound form return render(request, 'AsteOnLine/contatti.html', { 'form': form })
def contact(request): c = {} c.update(csrf(request)) if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data # send_mail( # cd['subject'], # cd['message'], # cd.get('email', '*****@*****.**'), # ['*****@*****.**'], # ) # return HttpResponse("Your post was submitted successfully!") return HttpResponseRedirect("/inventory/search/") else: return render_to_response( "inventory/contact.html", {"form": form, "contact_link": "selected"}, context_instance=RequestContext(request), ) else: form = ContactForm(initial={"subject": "I love your site!"}) return render_to_response( "inventory/contact.html", {"form": form, "contact_link": "selected"}, context_instance=RequestContext(request), )
def contact(request): errors = [] if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data email_message = cd.get('email', 'No email') + u'\n' + cd.get('subject', 'no subject') + u'\n' + cd.get('message','No message') db = email_list( email = cd.get('email', 'No email'), content = email_message ) db.save() send_mail( cd['subject'], email_message, '*****@*****.**', ['*****@*****.**'], fail_silently=True, ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject':u'网站还可以哦'}) return render_to_response('contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data if check_contact_form(request, cd): # This is spam m = _(u"Erreur lors de l'envoi réessayer ultérieurement.") messages.add_message(request, messages.ERROR, m) else: for m in [ _(u'Merci de nous avoir contactés.'), _(u'Nous vous répondrons très rapidement.'),]: messages.add_message(request, messages.INFO, m) message = '%s\r\n' % cd['message'] message += 'From: %s\r\n' % cd['sender'] message += 'Email: %s\r\n' % cd['email'] send_mail( cd['subject'].encode("utf-8"), message.encode("utf-8"), settings.SERVER_EMAIL, ['*****@*****.**', '*****@*****.**']) return HttpResponseRedirect('/contact') else: messages.add_message(request, messages.ERROR, 'Formulaire invalide.') else: form = ContactForm(label_suffix='') context = { 'body_class': 'about', 'form': form } return render_to_response( 'web/contact.html', context, context_instance=RequestContext(request))
def create_contact(request): if request.user.is_authenticated(): user = request.user if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): obj = form.save(commit=False) obj.user = user obj.save() return HttpResponseRedirect('/contacts/mycontacts/') else: form = ContactForm(initial={'user' : User}) args = {} args.update(csrf(request)) args['form'] = form return render_to_response('contacts/create_contact.html', args) else: c = {} c.update(csrf(request)) return render_to_response('registration/login.html', c)
def email(request): contact_flatpage = get_object_or_404(FlatPage, url='/help/contacts/') if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): code = 'CONTACT_FORM' ctx = form.cleaned_data try: event_type = CommunicationEventType.objects.get(code=code) except CommunicationEventType.DoesNotExist: # No event-type in database, attempt to find templates for this # type and render them immediately to get the messages. Since we # have not CommunicationEventType to link to, we can't create a # CommunicationEvent instance. templates = CommunicationEventType.objects.get_and_render(code, ctx) event_type = None else: templates = event_type.get_messages(ctx) Dispatcher().dispatch_direct_messages(CONTACT_FORM_BCC, templates) messages.success(request, 'Ваше сообщение успешно отрпавлено') else: form = ContactForm() return render(request, 'flatpages/default.html', { "form": form, "flatpage": contact_flatpage, })
def send(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): msg = Message() msg.username = form.cleaned_data['username'] msg.email = form.cleaned_data['email'] msg.phone = form.cleaned_data['phone'] msg.location = form.cleaned_data['location'] msg.job = form.cleaned_data['job'] msg.description = form.cleaned_data['description'] msg.area = form.cleaned_data['area'] try: msg.save() mail_managers('ZUBIRD webpage - new message received', 'Otrzymałeś nową wiadomość.') except Exception as e: import traceback logger.error(str(e)) logger.error(traceback.format_exc()) return render_to_response('error.html', {}) return render_to_response('thanks.html', {}) else: return render_to_response('base.html', Context({'form':form})) else: return index(request)
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] cc_myself = form.cleaned_data['cc_myself'] recipients = ['*****@*****.**'] if cc_myself: recipients.append(sender) # as confs de e-mail no settings.py sao ficticias # por isso send_mail esta comentada # send_mail(subject, message, sender, recipients) return HttpResponseRedirect('/thanks') else: form = ContactForm() return render_to_response('contact.html', { 'form': form, }, context_instance=RequestContext(request))
def contact(request, template_name="about/contactus.html"): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): from datetime import datetime name = form.cleaned_data['name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] message = form.cleaned_data['message'] subject = "Contact Us message from " + name if request.user.is_authenticated(): form.submitter = request.user form.submitteddate = datetime.now() contact = form.save() message = 'Email: %s\nPhone: %s\n\n' % (email, phone) + message recipients = settings.CONTACT_EMAIL.split(';') from django.core.mail import send_mail try: send_mail(subject, message, settings.CONTACT_EMAIL, recipients) except: pass request.user.message_set.create(message="Contact Us message has been successfully submitted") return HttpResponseRedirect(reverse('contactus')) # Redirect after POST else: if request.user.is_authenticated(): profile = request.user.get_profile() kwargs = { "email": request.user.email, "name": profile.name, } form = ContactForm(initial=kwargs) else: form = ContactForm() return render_to_response(template_name, { "form": form, }, context_instance=RequestContext(request))
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data ## send_mail( ## cd['subject'], ## cd['message'], ## cd.get('email', '*****@*****.**'), ## ['*****@*****.**'], ## ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render(request, 'contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data # send_mail( # cd['subject'], # cd['message'], # cd.get('email', '*****@*****.**'), # ['*****@*****.**'], # ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject': 'I love your site!'}) return render_to_response('books/contact_form.html', {'form': form})
def get_contact(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, "contacts.html", {'form': form})
def create(request): if request.POST: form = ContactForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/contacts') else: form = ContactForm() args = {} args.update(csrf(request)) args['form'] = form t = loader.get_template('contacts/contact_form.html') c = RequestContext(request, args) return HttpResponse(t.render(c))
def contact(request): if request.POST: f = ContactForm(request.POST) if f.is_valid(): name = f.cleaned_data['name'] content = f.cleaned_data['content'] email = f.cleaned_data['email'] Contact.objects.create(name=name, email=email, content=content, date=datetime.datetime.now()) f = ContactForm() else: f = ContactForm() return render(request, 'contact.html', locals())
def post(self, request): form = ContactForm(request.POST) if not form.is_valid(): messages.error(request, "Looks like your captcha was wrong!") return render(request, 'accounts/contact.html', {'form': form}) else: mail_admins( "New contact form submission from {0}".format( form.cleaned_data['email']), form.cleaned_data["feedback"], ) messages.success( request, "Thank you! We'll get back to you as soon as possible.") return render(request, 'accounts/contact.html', {'form': ContactForm()})
def contact(request): if request.method =='post': form = ContactForm(request.POST) if form.is_valid(): topic =form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data.get('sender', '*****@*****.**') send_mail( 'Feedback from your site,topic' % topic, message,sender, ['*****@*****.**'] ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render_to_response('../templates/contact.html',{'form':form})
def contactUs(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] send_mail('feedback for you: %s' % (topic,), message, sender, [DEFAULT_MAIL_RECEIVER], ) return HttpResponseRedirect("/contactUs/thx") else: form = ContactForm() return render_to_response("contactUs.html",{'form':form},context_instance=RequestContext(request))
def contact(request): if request.method == 'POST': # 处理用户提交动作 # ContactForm会自动校验用户输入. form = ContactForm(request.POST) if form.is_valid(): topic = form.data['topic'] message = form.data['message'] sender = form.data.get('sender', '*****@*****.**') send_mail('Feedback from your site, topic: %s' % topic, message, sender, ['*****@*****.**']) # 在一个POST请求过后, 如果用户选择刷新页面, 这个请求就重复提交了. # 在POST之后重定向页面是一个有用的模式, 可以避免这样的情况出现. return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'sender': '*****@*****.**'}) return render_to_response('books/contact.html', {'form': form})
def contact_post(request): form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data # send_mail( # cd['subject'], # cd['message'], # cd.get('email', '*****@*****.**'), # ['*****@*****.**'], # ) return HttpResponseRedirect('thanks') else: return render(request, 'contact_form.html', {'form': form})
def contact(request): request.session.name = "" form = ContactForm() if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): content = form.cleaned_data['contact_name'] request.session.name = content #form = ContactForm() #s = SessionStore() #form_class = ContactForm(request.POST) #s['key'] = form_class.cleaned_data['contact_name'] #s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead') return render(request, "lol_app/index.html", {'form': form})
def services(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('success') context = {"form": form, "links": nav_links} return render(request, "contact.html", context)
def contact(request): form = ContactForm(request.POST or None) # if form.is_valid(): ## we can't save it # for key in form.cleaned_data: # print key # #print form.cleaned_data.get(key) #print form.cleaned_data #email = form.cleaned_data("email") # message = form.cleaned_data("message") # full_name = form.cleaned_data("full_name") if form.is_valid(): print form.cleaned_data context = { "form": form, } return render(request,"home.html",context)
def contact(request): errors = [] if request.method == 'POST': #if not request.POST.get('subject', ''): errors.append('Enter a subject.') #if not requesst.POST.get('message', ''): errors.append('Enter a message.') #if not request.POST.get('email') and '@' not in request.POST['emal']: errors.append('Enter a valid e-mail address.') ## if not errors: ## send_mail( ## request.POST['subject'], ## request.POST['message'], ## request.POST.get('emal', '*****@*****.**'), ## ['*****@*****.**'], ## ) ## return HttpResponseRedirect('/contact/thanks/') form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data try: send_mail( cd['subject'], cd['message'] + " Send by " + cd['email'], cd.get('email', '*****@*****.**'), #'*****@*****.**'), ['*****@*****.**'], #['*****@*****.**'], ) except: # Because of the verfication problem with SES. send_mail( cd['subject'], cd['message'] + " Send by " + cd['email'], cd.get('mail', '*****@*****.**'), ['*****@*****.**'], ) messages.add_message(request, messages.SUCCESS, ugettext("The enquiry has been sent.")) #return HttpResponseRedirect('/contact/thanks') # thanks/ return render_to_response('contact/thanks.html', context_instance=RequestContext(request)) else: form = ContactForm(initial={'subject': 'For the singularity!'}) return render_to_response('contact/form.html', {'form': form}, context_instance=RequestContext(request))
def contact_view(request): context = {} if (request.method == "POST"): form = ContactForm(request.POST) context['form'] = form if form.is_valid(): send_mail("States Django: %s" % form.cleaned_data['name'], form.cleaned_data['message'], form.cleaned_data['email'], [settings.EMAIL_HOST_USER], fail_silently=False) else: form = ContactForm() context['form'] = form return render_to_response('contact_view.html', context, context_instance=RequestContext(request))
def contact(request): errors = [] if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject': 'I love your site!'}) return render( request, 'contact_form.html', {'form': form}) #solve csrf problem, do not use render_response
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.send_mail() return redirect('thanks') else: form = ContactForm() response_data = { 'contact_form': form, } return render_to_response('contact.html', response_data, context_instance=RequestContext(request))
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd.get('email', '*****@*****.**') + " says:\n" + cd['message'], '*****@*****.**', ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() c = {'form': form} c.update(csrf(request)) return render_to_response('contact_form.html', c)
def edit_form_contact(request, id): contacts = Contact.objects.get(pk=id) if request.POST and request.is_ajax(): form = ContactForm(request.POST, request.FILES, instance=contacts) if form.is_valid(): contact = form.save(commit=False) contact.save() return HttpResponse('OK') else: errors_dict = {} for e in form.errors: error = form.errors[e] errors_dict[e] = unicode(error) return HttpResponseBadRequest(json.dumps(errors_dict)) else: form = ContactForm(instance=contacts) return render(request, 'edit_form.html', {'form': form})
def contact(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data email = cd.get('email', '') em = EmailMessage( cd['subject'], cd['message'], '*****@*****.**', # change this name to=['*****@*****.**'], ) em.send() request.session['email'] = email return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject': ""}) return render(request, 'contact.html', {'form': form, 'contact': 'active'})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): author_name = form.cleaned_data['author_name'] email = form.cleaned_data['email'] message = form.cleaned_data['message'] message_title = 'Message from AdelDavletshina.com' send_mail(message_title, message, '*****@*****.**', ['*****@*****.**']) contact = Contact(author_name = author_name, email = email, message = message) contact.save() return HttpResponseRedirect('/contact/') else: form = ContactForm() return render_to_response('contact/contact.html', {'form': form}, RequestContext(request))
def new_contact_from_share(request): if request.method == 'POST': contact_form = ContactForm(request.POST, instance=Contact()) if contact_form.is_valid(): contact_form.save() return HttpResponseRedirect(reverse('manage_contact')) else: project_pk = request.session.get('viewing_project', None) if project_pk is None: return HttpResponseRedirect(reverse('no_project')) contact_form = ContactForm(instance=Contact(), initial={'project': project_pk}) context = { 'contact_form': contact_form, 'project_name': Project.objects.get(pk=project_pk).name } context.update(csrf(request)) return render_to_response('viewer/contact/new_contact_from_share.html', context, context_instance=RequestContext(request))
def contact(request): if request.POST: form = ContactForm(request.POST) else: form = ContactForm() if form.is_valid(): try: send_mail( form.cleaned_data['subject'] + ' ' + form.cleaned_data['type_of_work'], form.cleaned_data['message'], form.cleaned_data['email'], ['*****@*****.**']) except BadHeaderError: return render('Invalid header found.') return redirect('thankyou.html') else: return render(request, 'contact.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data email = EmailMessage( subject=cd['subject'], body=bodyString(cd['name'], cd['message']), from_email='*****@*****.**', to=['*****@*****.**'], ) email.send(fail_silently=False) return HttpResponseRedirect(reverse('books:thanks')) else: form = ContactForm() return render(request, 'books/contact.html', { 'form': form, 'tab_title': 'Contact Us' })
def contact(request): errors = False if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): send_mail('Website Enquiry', "Message from: " + form.cleaned_data['email'] + "\r\n" + form.cleaned_data['message'], form.cleaned_data['email'], [form.cleaned_data['to']]) return redirect('/contact/thanks/') else: errors = True latest_news = NewsItem.objects.all()[0] contacts = SaturnaliaContact.objects.all() return render_to_response('contact.html', {'latest_news': latest_news, 'contacts': contacts, 'errors': errors}, context_instance=RequestContext(request))
def submit(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): data = form.cleaned_data d = { 'title': data['title'], 'email': data['email'], } subject = _('%(title)s from %(email)s.') % d from_email, to = data['email'], settings.DEFAULT_FROM_EMAIL content = data['text'] send_mail(subject, content, from_email, [to]) return redirect('contact_tnx') else: form = ContactForm() return { 'form': form, }
def POST(self): if self.request.user.is_authenticated(): form = ContactForm(self.request.POST) else: form = AnonymousContactForm(self.request.POST) if not form.is_valid(): return self.context_response('main/contact.html', { 'form': form, 'current_tab': 'contact' }) # Send an email to admins if self.request.user.is_authenticated(): user = self.request.user subject = I18nString( _("[%(site_name)s] %(username)s: %(email_subject)s"), { 'site_name': settings.SITE_NAME, 'username': user.username, 'email_subject': form.cleaned_data["subject"] }) message = I18nString(_(u"Registered user %(username)s sends the following "\ " message:\n%(message)s"), { 'username': user.username, 'message': form.cleaned_data["message"] }) else: subject = I18nString( _("[%(site_name)s] %(email)s: %(email_subject)s"), { 'site_name': settings.SITE_NAME, 'email': form.cleaned_data["email"], 'email_subject': form.cleaned_data["subject"] }) message = I18nString(_("Registered user %(name)s whose email is %(email)s"\ " sends the following message:\n%(message)s"), { 'name': form.cleaned_data["name"], 'email': form.cleaned_data["email"], 'message': form.cleaned_data["message"] }) mail_owners(subject, message) self.flash(_("Mail sent, we'll answer you as soon as possible.")) return redirect('main.views.index')
def post(self, request, *args, **kwargs): contact_form = ContactForm(request.POST) if contact_form.is_valid(): try: newComment = Comentarios(nombre=request.POST['name'], email=request.POST['email'], comentario=request.POST['content']) email = EmailMessage( "MAMJA - Nuevo mensaje de contacto", "De " + request.POST['name'] + " (" + request.POST['email'] + ")\n\nContenido del mensaje: \n" + request.POST['content'], request.POST['email'], ["*****@*****.**"], reply_to=[request.POST['email']]) email.send() newComment.save() return redirect(reverse('contacto') + "?enviado") except: return redirect(reverse('contacto') + "?error")
def post(self, request, **kwargs): form = ContactForm(request.POST) context = {"form": form} if form.is_valid(): msg = form.save() subject = "Contact Form Submission" toAddr = "*****@*****.**" if settings.DEBUG else "*****@*****.**" email = EmailMessage( subject, msg.message, '*****@*****.**', [toAddr], reply_to=[msg.email], ) try: email.send() except Exception as e: raise return HttpResponseRedirect('/thank-you/') return render(request, self.template_name, context)
def render(self, context, instance, placeholder): request = context['request'] if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): form.send(instance.site_email) context.update( { 'contact': instance, }) return context else: form = ContactForm() context.update({ 'contact': instance, 'form': form, }) return context