コード例 #1
0
ファイル: views.py プロジェクト: rangeonnicolas/alternwebsite
def home(request):
    '''Homepage'''

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():

            form.save()

            # send a notification email to the administrator
            sender = '*****@*****.**'
            receivers = [mail for (_, mail) in settings.ADMINS]

            message = "[00001] New mail: " + form.cleaned_data[
                'email'] + " " + str(datetime.datetime.now())

            try:
                smtpObj = smtplib.SMTP('localhost')
                smtpObj.sendmail(sender, receivers, message)
                print("Successfully sent email")
            except (smtplib.SMTPException, smtplib.ConnectionRefusedError):
                print("Error: unable to send email")

    else:
        form = ContactForm()

    # Topic list to display in the navgation bar
    topics = Topic.objects.all()

    return render(request, 'home/home.html', locals())
コード例 #2
0
ファイル: views.py プロジェクト: rangeonnicolas/alternwebsite
def home(request):
    '''Homepage'''

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():

            form.save()


            # send a notification email to the administrator
            sender = '*****@*****.**'
            receivers = [mail for (_,mail) in settings.ADMINS]

            message = "[00001] New mail: " + form.cleaned_data['email'] + " " + str(datetime.datetime.now())

            try:
               smtpObj = smtplib.SMTP('localhost')
               smtpObj.sendmail(sender, receivers, message)
               print("Successfully sent email")
            except (smtplib.SMTPException, smtplib.ConnectionRefusedError):
               print("Error: unable to send email")

    else:
        form = ContactForm()

    # Topic list to display in the navgation bar
    topics = Topic.objects.all()

    return render(request, 'home/home.html', locals())
コード例 #3
0
ファイル: views.py プロジェクト: Aakash-rai1/FoodForAll-1
    def post(self, request):
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/contact')

        args = {'form': form}
        return render(request, self.template_name, args)
コード例 #4
0
def contact_View(request):
    if request.method =='POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return redirect('home')
    else:
        form =ContactForm()
    return render(request,'home/contact.html', {'form':form})
コード例 #5
0
ファイル: views.py プロジェクト: Aim-Entity/barber
def index(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("home")
    else:
        form = ContactForm()

    context = {"form": form}
    return render(request, "service/index.htm", context)
コード例 #6
0
ファイル: views.py プロジェクト: Aim-Entity/barber
def index(request):
    testimonial = Testimonial.objects.all()
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("home")
    else:
        form = ContactForm()

    context = {"form": form, "tests": testimonial}
    return render(request, 'home/index.htm', context)
コード例 #7
0
def contact(request):
    if request.method == "GET":
        contactform = ContactForm()
        context = {'contactform': contactform}
        return render(request, 'home/contact.html', context)

    if request.method == "POST":
        contactform = ContactForm(request.POST)
        if contactform.is_valid():
            contactform.save()

        print(contactform)
        return render(request, 'home/contact.html')
コード例 #8
0
def Contact(request):

    form = ContactForm()

    if request.method == "POST":
        form = ContactForm(request.POST)
        confirm = False

        if form.is_valid():
            form.save()
            confirm = True

        return render(request, "contact.html", {'form': form, 'confirm': confirm})
        
    else:
        return render(request, "contact.html", {"form": form})    
コード例 #9
0
def partner(request):
	if request.method == 'POST':
		form2 = ContactForm(request.POST, request.FILES or None)
		print(form2.errors)
		if form2.is_valid():
			
			form2.save()
			#return redirect('partner')
			subject= form2.cleaned_data.get('subject')
			message=form2.cleaned_data.get('mssg')
			recepient=form2.cleaned_data.get('email')
			send_mail(subject, 
				message, recepient, [ EMAIL_HOST_USER], fail_silently = False)	
			return render(request, 'home/success.html', {'recepient': recepient})
	else:
		form2 = ContactForm()

	context = {'form2' : form2}
	return render(request,'home/partner.html',context)
コード例 #10
0
ファイル: views.py プロジェクト: RNSAINJU/Pythonproject
 def post(self, request):
     form = ContactForm(request.POST)
     if form.is_valid():
         post = form.save(commit=False)
         post.date = timezone.now()
         post.save()
         return redirect('about')
     else:
         form = ContactForm()
     return render(request, self.template_name, {'form': form})
コード例 #11
0
 def test_valid_contact_form_data(self):
     form = ContactForm({
         'name': "Test User",
         'email': "*****@*****.**",
         'message': "Here is my test message",
     })
     self.assertTrue(form.is_valid())
     message = form.save()
     self.assertEqual(message.name, "Test User")
     self.assertEqual(message.email, "*****@*****.**")
     self.assertEqual(message.message, "Here is my test message")
     self.assertTrue('contacted')