From bb8c5314bc4eaed5484780d8c668e8fd9a261b66 Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 7 Apr 2016 00:26:50 -0500 Subject: [PATCH] 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 --- digitalglarus/forms.py | 26 +++++ .../migrations/0005_auto_20160407_0519.py | 20 ++++ digitalglarus/models.py | 3 +- digitalglarus/templates/base_glarus.html | 2 +- digitalglarus/templates/contact.html | 95 +++++++++++-------- digitalglarus/templates/emails/contact.html | 15 +++ digitalglarus/templates/emails/contact.txt | 15 +++ digitalglarus/templates/support.html | 13 ++- digitalglarus/templates/supporters.html | 7 +- digitalglarus/urls.py | 3 +- digitalglarus/views.py | 48 ++++++---- dynamicweb/settings/base.py | 3 + 12 files changed, 184 insertions(+), 66 deletions(-) create mode 100644 digitalglarus/forms.py create mode 100644 digitalglarus/migrations/0005_auto_20160407_0519.py create mode 100644 digitalglarus/templates/emails/contact.html create mode 100644 digitalglarus/templates/emails/contact.txt diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py new file mode 100644 index 00000000..631fc4cf --- /dev/null +++ b/digitalglarus/forms.py @@ -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() diff --git a/digitalglarus/migrations/0005_auto_20160407_0519.py b/digitalglarus/migrations/0005_auto_20160407_0519.py new file mode 100644 index 00000000..17e64289 --- /dev/null +++ b/digitalglarus/migrations/0005_auto_20160407_0519.py @@ -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), + ), + ] diff --git a/digitalglarus/models.py b/digitalglarus/models.py index f22ec6ec..6c24ae0d 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -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) diff --git a/digitalglarus/templates/base_glarus.html b/digitalglarus/templates/base_glarus.html index bebc5efe..eac3faba 100644 --- a/digitalglarus/templates/base_glarus.html +++ b/digitalglarus/templates/base_glarus.html @@ -101,7 +101,7 @@

Copyright © ungleich GmbH - 2016

+ {% now "Y" %}

diff --git a/digitalglarus/templates/contact.html b/digitalglarus/templates/contact.html index 11767a8a..be6d6335 100755 --- a/digitalglarus/templates/contact.html +++ b/digitalglarus/templates/contact.html @@ -6,17 +6,33 @@
-
+ {% for message in messages %} + + {% endfor %} +

- {% placeholder 'digital_glarus_contact' %} +

+ Contact DIGITAL GLARUS +


- {% placeholder 'digital_glarus_contact_content' %} +

+ +

- {% placeholder 'digital_glarus_contact_information' %} +

Phone: +41 (0) 44 534 66 22

+ +

Email: info@digitalglarus.ch

+ +

Address:  In Der Au 7,  8762 Schwanden Switzerland

+ +
 
@@ -25,41 +41,46 @@
-
-

Contact - form -

-
-

If you want further information on Digital Glarus, please send us a message using the form below.

-
- {% csrf_token %} -
-
- - -
-
- - -
-
- - -
-
-
- - -
-
- - -
-
-
+
+

+ Contact form +

+
+

If you want further information on Digital Glarus, please send us a message using the form below.

+
+ {% csrf_token %} +
+
+ {{ form.name.label_tag }} + {{ form.name }} + {{ form.name.errors|striptags}} +
+
+ {{ form.email.label_tag }} + {{ form.email }} + {{ form.email.errors|striptags}} +
+
+ {{ form.phone_number.label_tag }} + {{ form.phone_number }} + {{ form.phone_number.errors|striptags}} +
+
+
+ {{ form.message.label_tag }} + {{ form.message }} + {{ form.message.errors|striptags}} +
+ {{ form.non_field_errors }} +
+ + +
+
+
+
-
{% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/emails/contact.html b/digitalglarus/templates/emails/contact.html new file mode 100644 index 00000000..a87121a3 --- /dev/null +++ b/digitalglarus/templates/emails/contact.html @@ -0,0 +1,15 @@ + +< + + + + + + +Name:{{data.name}}
+Email:{{data.email}}
+Phone number:{{data.phone_number}}
+Message:{{data.message}}
+ + + diff --git a/digitalglarus/templates/emails/contact.txt b/digitalglarus/templates/emails/contact.txt new file mode 100644 index 00000000..a87121a3 --- /dev/null +++ b/digitalglarus/templates/emails/contact.txt @@ -0,0 +1,15 @@ + +< + + + + + + +Name:{{data.name}}
+Email:{{data.email}}
+Phone number:{{data.phone_number}}
+Message:{{data.message}}
+ + + diff --git a/digitalglarus/templates/support.html b/digitalglarus/templates/support.html index cc6d5e56..3b2a0b76 100644 --- a/digitalglarus/templates/support.html +++ b/digitalglarus/templates/support.html @@ -18,11 +18,14 @@ you can send your donation to:

- Bank info -
- Account: 123123123123123123 -
- Name: Fake name + Bank info
+ Postfinance
+ 89-849216-5
+
+ CH36 0900 0000 8984 9216 5
+ Nico Schottelius
+ Hauptstrasse 14
+ 8775 Luchsingen

If you want to donate us in other means (your time, skill, etc..) diff --git a/digitalglarus/templates/supporters.html b/digitalglarus/templates/supporters.html index d4940435..f4b932f1 100644 --- a/digitalglarus/templates/supporters.html +++ b/digitalglarus/templates/supporters.html @@ -14,9 +14,10 @@


-

- 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. -

+
+

HERE ARE OUR PROUD SUPPORTERS OF PROJECT DIGITALGLARUS!

+

Thanks to our supporters, the first cowerking space in Glarus will have a new look!

+
diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index cfd3452c..9e27c57c 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -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'), diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 15bdecc2..f544ea97 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -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') diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index f6486c56..1a3f0e65 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -181,6 +181,9 @@ DATABASES = { } } + + + # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/