Adapt copyright copy to use current year, Add bank account info, Set the correct text on supporters page, HTML Form adapted to Django template, Create forms.py to have all forms, Create Contact Django Form View, Create a HTML template to contact email, Send contact email to info@digitalglarus.ch
This commit is contained in:
parent
76f703b9d7
commit
f667aae38e
12 changed files with 184 additions and 66 deletions
26
digitalglarus/forms.py
Normal file
26
digitalglarus/forms.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from django import forms
|
||||
from .models import Message
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
|
||||
|
||||
class ContactUsForm(forms.ModelForm):
|
||||
error_css_class = 'autofocus'
|
||||
|
||||
class Meta:
|
||||
model = Message
|
||||
fields = ['name', 'email', 'phone_number', 'message']
|
||||
widgets = {
|
||||
'name': forms.TextInput(attrs={'class': u'form-control'}),
|
||||
'email': forms.TextInput(attrs={'class': u'form-control'}),
|
||||
'phone_number': forms.TextInput(attrs={'class': u'form-control'}),
|
||||
'message': forms.Textarea(attrs={'class': u'form-control'}),
|
||||
}
|
||||
|
||||
def send_email(self):
|
||||
text_content = render_to_string('emails/contact.txt', {'data': self.cleaned_data})
|
||||
html_content = render_to_string('emails/contact.html', {'data': self.cleaned_data})
|
||||
email = EmailMultiAlternatives('Subject', text_content)
|
||||
email.attach_alternative(html_content, "text/html")
|
||||
email.to = ['to@example.com']
|
||||
email.send()
|
20
digitalglarus/migrations/0005_auto_20160407_0519.py
Normal file
20
digitalglarus/migrations/0005_auto_20160407_0519.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-04-07 05:19
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('digitalglarus', '0004_dggallery_dggalleryplugin_dgpicture_dgsupportersplugin_supporter'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='message',
|
||||
name='received_date',
|
||||
field=models.DateTimeField(auto_now_add=True),
|
||||
),
|
||||
]
|
|
@ -8,8 +8,7 @@ class Message(models.Model):
|
|||
email = models.EmailField()
|
||||
phone_number = models.CharField(max_length=200)
|
||||
message = models.TextField()
|
||||
|
||||
received_date = models.DateTimeField('date received')
|
||||
received_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s - %s" % (self.name, self.email, self.received_date)
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
<p class="text-center">Copyright © <a href="http://www.ungleich.ch">ungleich GmbH
|
||||
2016</a></p>
|
||||
{% now "Y" %}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -6,17 +6,33 @@
|
|||
<div class="row">
|
||||
<div class="box">
|
||||
<div class="col-lg-12">
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-success alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<strong>{{ message }}</strong>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<hr>
|
||||
<h2 class="intro-text text-center">
|
||||
{% placeholder 'digital_glarus_contact' %}
|
||||
<p class="text-center">
|
||||
Contact <strong>DIGITAL GLARUS</strong>
|
||||
</p>
|
||||
</h2>
|
||||
<hr>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
{% placeholder 'digital_glarus_contact_content' %}
|
||||
<p>
|
||||
<iframe frameborder="0" height="400" scrolling="no" src="//maps.google.com/maps?hl=en&ie=UTF8&ll=46.969959,9.039001&spn=56.506174,79.013672&t=m&z=12&output=embed" width="100%"></iframe>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
{% placeholder 'digital_glarus_contact_information' %}
|
||||
<p>Phone: <strong>+41 (0) 44 534 66 22</strong></p>
|
||||
|
||||
<p>Email: <strong><a href="mailto:info@digitalglarus.ch">info@digitalglarus.ch</a></strong></p>
|
||||
|
||||
<p>Address: <strong><span style="">In Der Au 7, 8762 Schwanden Switzerland</span></strong></p>
|
||||
|
||||
<div class="clearfix"> </div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
@ -26,40 +42,45 @@
|
|||
<div class="box">
|
||||
<div class="col-lg-12">
|
||||
<hr>
|
||||
<h2 class="intro-text text-center">Contact
|
||||
<strong>form</strong>
|
||||
<h2 class="intro-text text-center">
|
||||
Contact <strong>form</strong>
|
||||
</h2>
|
||||
<hr>
|
||||
<p>If you want further information on Digital Glarus, please send us a message using the form below.</p>
|
||||
<form action="{% url 'digitalglarus:contact' %}" method="post" role="form">
|
||||
<form action="" method="post" >
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="form-group col-lg-4">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name">
|
||||
<div autofocus class="form-group col-lg-4 {% if form.name.errors %}has-error text-danger{% endif %}">
|
||||
{{ form.name.label_tag }}
|
||||
{{ form.name }}
|
||||
{{ form.name.errors|striptags}}
|
||||
</div>
|
||||
<div class="form-group col-lg-4">
|
||||
<label>Email Address</label>
|
||||
<input type="email" class="form-control" name="email">
|
||||
<div class="form-group col-lg-4 {% if form.email.errors %}has-error text-danger {% endif %}">
|
||||
{{ form.email.label_tag }}
|
||||
{{ form.email }}
|
||||
{{ form.email.errors|striptags}}
|
||||
</div>
|
||||
<div class="form-group col-lg-4">
|
||||
<label>Phone Number</label>
|
||||
<input type="tel" class="form-control" name="phone_number">
|
||||
<div class="form-group col-lg-4 {% if form.phone_number.errors %}has-error text-danger {% endif %}">
|
||||
{{ form.phone_number.label_tag }}
|
||||
{{ form.phone_number }}
|
||||
{{ form.phone_number.errors|striptags}}
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="form-group col-lg-12">
|
||||
<label>Message</label>
|
||||
<textarea class="form-control" rows="6" name="message"></textarea>
|
||||
<div class="form-group col-lg-12 {% if form.message.errors %}has-error text-danger {% endif %}">
|
||||
{{ form.message.label_tag }}
|
||||
{{ form.message }}
|
||||
{{ form.message.errors|striptags}}
|
||||
</div>
|
||||
{{ form.non_field_errors }}
|
||||
<div class="form-group col-lg-12">
|
||||
<input type="hidden" name="save" value="contact">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
<button type="submit" class="btn btn-default" {% if form.name.errors %} autofocus {% endif %}>Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.container -->
|
||||
{% endblock %}
|
15
digitalglarus/templates/emails/contact.html
Normal file
15
digitalglarus/templates/emails/contact.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
<<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Name:{{data.name}}<br/>
|
||||
Email:{{data.email}}<br/>
|
||||
Phone number:{{data.phone_number}}<br/>
|
||||
Message:{{data.message}}<br/>
|
||||
|
||||
</body>
|
||||
</html>
|
15
digitalglarus/templates/emails/contact.txt
Normal file
15
digitalglarus/templates/emails/contact.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
<<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Name:{{data.name}}<br/>
|
||||
Email:{{data.email}}<br/>
|
||||
Phone number:{{data.phone_number}}<br/>
|
||||
Message:{{data.message}}<br/>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -18,11 +18,14 @@
|
|||
you can send your donation to:
|
||||
</p>
|
||||
<p>
|
||||
<strong>Bank info</strong>
|
||||
<br>
|
||||
Account: 123123123123123123
|
||||
<br>
|
||||
Name: Fake name
|
||||
<strong>Bank info</strong><br/>
|
||||
Postfinance<br/>
|
||||
89-849216-5<br/>
|
||||
<br/>
|
||||
CH36 0900 0000 8984 9216 5<br/>
|
||||
Nico Schottelius<br/>
|
||||
Hauptstrasse 14<br/>
|
||||
8775 Luchsingen<br/>
|
||||
</p>
|
||||
<p>
|
||||
If you want to donate us in other means (your time, skill, etc..)
|
||||
|
|
|
@ -14,9 +14,10 @@
|
|||
<hr>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<p>
|
||||
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
|
||||
</p>
|
||||
<div class="text-center">
|
||||
<h3>HERE ARE OUR PROUD SUPPORTERS OF PROJECT DIGITALGLARUS!</h3>
|
||||
<p class="text-center">Thanks to our supporters, the first cowerking space in Glarus will have a new look!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="text-center">
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
from .views import ContactView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'old_contact$', views.contact, name='contact'),
|
||||
url(r'contact/?$', ContactView.as_view(), name='contact'),
|
||||
url(r'supporters/?$', views.supporters, name='supporters'),
|
||||
url(r'support-us/?$', views.support, name='support'), # url(r'', views.index, name='index'),
|
||||
url(r'blog/',views.blog,name='blog'),
|
||||
|
|
|
@ -7,14 +7,26 @@ from django.core.urlresolvers import reverse
|
|||
from django.utils.translation import get_language
|
||||
from djangocms_blog.models import Post
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from .models import Message, Supporter
|
||||
from .forms import ContactUsForm
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
class MessageForm(ModelForm):
|
||||
required_css_class = 'form-control'
|
||||
class Meta:
|
||||
model = Message
|
||||
fields = ['name', 'email', 'phone_number', 'message' ]
|
||||
|
||||
class ContactView(FormView):
|
||||
template_name = 'contact.html'
|
||||
form_class = ContactUsForm
|
||||
success_url = '/digitalglarus/contact/'
|
||||
success_message = _('Message Successfully Sent')
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
form.send_email()
|
||||
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
||||
return super(ContactView, self).form_valid(form)
|
||||
|
||||
|
||||
def detail(request, message_id):
|
||||
|
@ -41,23 +53,23 @@ def home(request):
|
|||
def letscowork(request):
|
||||
return render(request, 'digitalglarus/letscowork.html')
|
||||
|
||||
def contact(request):
|
||||
message = Message(received_date=datetime.datetime.now())
|
||||
form = MessageForm(request.POST, instance=message)
|
||||
# def contact(request):
|
||||
# message = Message(received_date=datetime.datetime.now())
|
||||
# form = MessageForm(request.POST, instance=message)
|
||||
|
||||
if request.method == 'POST':
|
||||
# if request.method == 'POST':
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponseRedirect(reverse("digitalglarus:contact"))
|
||||
# if form.is_valid():
|
||||
# form.save()
|
||||
# return HttpResponseRedirect(reverse("digitalglarus:contact"))
|
||||
|
||||
# form = MessageForm()
|
||||
# # form = MessageForm()
|
||||
|
||||
context = {
|
||||
'form': form,
|
||||
}
|
||||
# context = {
|
||||
# 'form': form,
|
||||
# }
|
||||
|
||||
return render(request, 'digitalglarus/contact.html', context)
|
||||
# return render(request, 'digitalglarus/contact.html', context)
|
||||
|
||||
|
||||
def blog(request):
|
||||
|
@ -76,9 +88,11 @@ def blog_detail(request, slug):
|
|||
}
|
||||
return render(request, 'post_detail.html', context)
|
||||
|
||||
|
||||
def support(request):
|
||||
return render(request, 'support.html')
|
||||
|
||||
|
||||
def supporters(request):
|
||||
context = {
|
||||
'supporters': Supporter.objects.order_by('name')
|
||||
|
|
|
@ -181,6 +181,9 @@ DATABASES = {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.7/topics/i18n/
|
||||
|
||||
|
|
Loading…
Reference in a new issue