|
@@ -1,6 +1,10 @@
|
|
|
# from django.shortcuts import render
|
|
|
from django.shortcuts import render, get_object_or_404
|
|
|
# from django.http import HttpResponse
|
|
|
+# for the form:
|
|
|
+from django.http import HttpResponseRedirect
|
|
|
+from django.core.mail import send_mail, get_connection
|
|
|
+from .forms import ContactForm
|
|
|
|
|
|
from . models import Page
|
|
|
|
|
@@ -21,3 +25,25 @@ def index(request, pagename):
|
|
|
# assert False # django debug page is cool!
|
|
|
return render(request, 'pages/page.html', context)
|
|
|
|
|
|
+
|
|
|
+def contact(request):
|
|
|
+ submitted = False
|
|
|
+ if request.method == 'POST':
|
|
|
+ form = ContactForm(request.POST)
|
|
|
+ if form.is_valid():
|
|
|
+ cd = form.cleaned_data
|
|
|
+ con = get_connection('django.core.mail.backends.console.EmailBackend')
|
|
|
+ send_mail(
|
|
|
+ cd['subject'],
|
|
|
+ cd['message'],
|
|
|
+ cd.get('email', '[email protected]'),
|
|
|
+ ['[email protected]'],
|
|
|
+ connection=con
|
|
|
+ )
|
|
|
+ return HttpResponseRedirect('/contact?submitted=True')
|
|
|
+ else:
|
|
|
+ form = ContactForm()
|
|
|
+ if 'submitted' in request.GET:
|
|
|
+ submitted = True
|
|
|
+ return render(request, 'pages/contact.html', {'form': form, 'page_list': Page.objects.all(), 'submitted': submitted})
|
|
|
+
|