-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2018-update' of https://github.com/okfn/foundation into…
… 2018-update
- Loading branch information
Showing
11 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django import forms | ||
|
||
|
||
# define form fields and specify what data types to expect | ||
class ContactForm(forms.Form): | ||
email = forms.EmailField(required=True) | ||
name = forms.CharField(required=True) | ||
organisation = forms.CharField(required=True) | ||
message = forms.CharField(widget=forms.Textarea, required=True) | ||
type = forms.CharField(widget=forms.HiddenInput(), required=True) | ||
|
||
# check if filled form data is valid | ||
def is_valid(self): | ||
valid = super(ContactForm, self).is_valid() | ||
|
||
if not valid: | ||
return False | ||
|
||
# ensure that form data that's emailed is from one of the two forms | ||
if self.cleaned_data['type'] not in ['Press', 'Service']: | ||
return False | ||
|
||
return True |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf.urls import url | ||
# from django.contrib import admin | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
url('contact/', views.contactview, name='contact'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.shortcuts import render | ||
from django.contrib import messages | ||
from django.core.mail import send_mail, BadHeaderError | ||
from django.http import HttpResponse | ||
from .forms import ContactForm | ||
|
||
|
||
# check if form data is valid | ||
def contactview(request): | ||
if request.method == 'GET': | ||
form = ContactForm() | ||
else: | ||
form = ContactForm(request.POST) | ||
if form.is_valid(): | ||
name = form.cleaned_data['name'] | ||
email = form.cleaned_data['email'] | ||
message = form.cleaned_data['message'] | ||
organisation = form.cleaned_data['organisation'] | ||
type = form.cleaned_data['type'] | ||
|
||
# collate and send filled form data in one email | ||
email_message = 'From: ' + email + '\n' + 'Name: ' + name + '\n' | ||
+ 'Organisation: ' + organisation + '\n' | ||
+ 'Message: ' + message + '\n' | ||
email_subject = type + ' Enquiry from ' + name | ||
|
||
# specify where form data is sent, depending on the type of enquiry | ||
if type == 'Service': | ||
recepients = ['oks@okfn.org'] | ||
else: | ||
recepients = ['press@okfn.org'] | ||
|
||
# all form data will originate from the same email address | ||
try: | ||
send_mail( | ||
email_subject, email_message, | ||
"info@okfn.org", recepients) | ||
except BadHeaderError: | ||
return HttpResponse('Invalid header found.') | ||
|
||
# pop up message once form data has been sent successfully | ||
messages.info( | ||
request, | ||
'Thank you for your message. ' + | ||
'Someone from Open Knowledge International' + | ||
'will be in touch soon.') | ||
|
||
# reload the contact page after form data has been sent successfully | ||
return render(request, "cms_contact.html", {'form': form}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters