contact form

This commit is contained in:
j 2018-02-21 20:31:25 +05:30
parent bc33331889
commit 57481d4dbe
6 changed files with 60 additions and 1 deletions

View File

@ -145,6 +145,9 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'data/images')
IMAGE_PREFIX = 'http://studio.camp/images/' IMAGE_PREFIX = 'http://studio.camp/images/'
CONTACT_FROM_EMAIL = 'contact@studio.camp'
CONTACT_TO_EMAIL = ['contact@studio.camp']
try: try:
from local_settings import * from local_settings import *
except: except:

View File

@ -187,3 +187,9 @@ table thead, table tbody, table tfoot {
label, button {
color: #ffffff !important;
}
button {
background: #99999 !important;
}

View File

@ -36,6 +36,8 @@ urlpatterns = [
url(r'directions.html', RedirectView.as_view(url='/directions/')), url(r'directions.html', RedirectView.as_view(url='/directions/')),
url(r'campstudio.html', RedirectView.as_view(url='/directions/')), url(r'campstudio.html', RedirectView.as_view(url='/directions/')),
url(r'^contact/$', views.contact),
url(r'^texts/index/$', views.section_list, {'section': 'Texts'}, name='texts_list'), url(r'^texts/index/$', views.section_list, {'section': 'Texts'}, name='texts_list'),
url(r'^events/index/$', views.section_list, {'section': 'Events'}, name='events_list'), url(r'^events/index/$', views.section_list, {'section': 'Events'}, name='events_list'),
url(r'^projects/index/$', views.section_list, {'section': 'Projects'}, name='projects_list'), url(r'^projects/index/$', views.section_list, {'section': 'Projects'}, name='projects_list'),

7
content/forms.py Normal file
View File

@ -0,0 +1,7 @@
from django import forms
from django.conf import settings
class ContactForm(forms.Form):
name = forms.CharField(label='Name', required=True)
email = forms.EmailField(label='E-Mail', required=True)
message = forms.CharField(label='Message', widget=forms.Textarea, required=True)

View File

@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% block content %}
<div class="large-8 medium-8 columns special-column">
<div class="index-text">
{% if sent %}
<p>Thanks for getting in touch!</p>
{% else %}
<form method="post">
{% csrf_token %}
{{form}}
<br>
<input type="submit" value="Send Message">
</form>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -3,18 +3,21 @@ from __future__ import unicode_literals
from datetime import datetime from datetime import datetime
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import EmailMessage
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse from django.urls import reverse
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from photologue.views import GalleryListView from photologue.views import GalleryListView
from photologue.models import Photo, Gallery from photologue.models import Photo, Gallery
from .models import Content, ContentContent from .models import Content, ContentContent
from . import forms
ITEMS_PER_PAGE = 30 ITEMS_PER_PAGE = 30
@ -165,6 +168,26 @@ def page(request, shortname):
raise Http404 raise Http404
return render(request, 'page.html', {'content': content}) return render(request, 'page.html', {'content': content})
def contact(request):
context = {}
if request.method == 'POST':
form = forms.ContactForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
email = form.cleaned_data['email']
message = form.cleaned_data['message']
subject = '{} has left a message on studio.camp'.format(name)
from_ = settings.CONTACT_FROM_EMAIL
to = settings.CONTACT_TO_EMAIL
msg = EmailMessage(subject, message, from_, to, reply_to=[email])
msg.send(fail_silently=True)
#msg.send()
context['sent'] = True
else:
form = forms.ContactForm()
context['form'] = form
return render(request, 'contact.html', context)
def limit_content(content, q): def limit_content(content, q):
if q: if q: