cciw-website / cciw / cciwmain / views / misc.py

luke 2e2eef8 

Luke Plant 1f25a9a 
luke 2e2eef8 
Luke Plant 173c221 
luke 2e2eef8 

Luke Plant 173c221 
luke 2e2eef8 
Luke Plant a5ba361 
Luke Plant 89045dd 
luke 2e2eef8 
Luke Plant 3dc66e9 
luke 2e2eef8 




Luke Plant 3dc66e9 
luke 2e2eef8 


Luke Plant 3dc66e9 




Luke Plant 3b52491 
Luke Plant 3dc66e9 


Luke Plant 3b52491 
Luke Plant 3dc66e9 





Luke Plant 3b52491 
Luke Plant 3dc66e9 


luke 2e2eef8 
Luke Plant 89045dd 
Luke Plant 3dc66e9 
Luke Plant 1bc403b 


luke 2e2eef8 
Luke Plant 173c221 

Luke Plant b2a4b69 
Luke Plant 28f5296 
Luke Plant 173c221 

Luke Plant ee80f42 
Luke Plant 3dc66e9 






Luke Plant 173c221 

Luke Plant ee80f42 
Luke Plant 173c221 
Luke Plant 3dc66e9 


Luke Plant 28f5296 
Luke Plant 173c221 

Luke Plant b2a4b69 
Luke Plant 173c221 




luke 2e2eef8 
import os

from django import forms
from django.core import mail
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.text import wrap
from django.views.generic.base import TemplateView

from cciw.cciwmain.common import get_thisyear, AjaxyFormView, DefaultMetaData
from cciw.cciwmain.forms import CciwFormMixin

def send_feedback(to_emails, from_email, name, message):
    message = wrap(message, 70)
    mail.send_mail("CCIW website feedback", """
The following message has been sent on the CCIW website feedback form:

From: %(name)s
Email: %(from_email)s
Message:
%(message)s

""" % locals(), settings.SERVER_EMAIL, to_emails)

CONTACT_CHOICE_GENERAL = 'general'
CONTACT_CHOICE_WEBSITE = 'website'
CONTACT_CHOICE_BOOKINGS = 'bookings'
CONTACT_CHOICE_BOOKINGFORM = 'bookingform'

CONTACT_CHOICES = [
    (CONTACT_CHOICE_WEBSITE, 'Web site problems'),
    (CONTACT_CHOICE_BOOKINGFORM, 'Booking form request'),
    (CONTACT_CHOICE_BOOKINGS, 'Bookings'),
    (CONTACT_CHOICE_GENERAL, 'Other'),
]

CONTACT_CHOICE_DESTS = {
    CONTACT_CHOICE_GENERAL: ['FEEDBACK_EMAIL'],
    CONTACT_CHOICE_BOOKINGFORM: ['BOOKING_FORM_EMAIL', 'FEEDBACK_EMAIL'],
    CONTACT_CHOICE_WEBSITE: ['WEBMASTER_EMAIL', 'FEEDBACK_EMAIL'],
    CONTACT_CHOICE_BOOKINGS: ['BOOKING_SECRETARY_EMAIL', 'FEEDBACK_EMAIL'],
}

class FeedbackForm(CciwFormMixin, forms.Form):
    subject = forms.ChoiceField(label="Subject", choices=CONTACT_CHOICES)
    email = forms.EmailField(label="Email address", max_length=320)
    name = forms.CharField(label="Name", max_length=200, required=False)
    message = forms.CharField(label="Message", widget=forms.Textarea)

class FeedbackBase(DefaultMetaData):
    metadata_title = u"Contact us"

class FeedbackFormView(FeedbackBase, AjaxyFormView):
    form_class = FeedbackForm
    template_name = 'cciw/feedback.html'

    def get_initial(self):
        initial = {}
        for val, caption in CONTACT_CHOICES:
            if val in self.request.GET:
                initial['subject'] = val
        return initial

    def get_success_url(self):
        return reverse('cciwmain.misc.feedback_done')

    def form_valid(self, form):
        to_emails = [getattr(settings, email) for email in CONTACT_CHOICE_DESTS[form.cleaned_data['subject']]]
        send_feedback(to_emails,
                      form.cleaned_data['email'],
                      form.cleaned_data['name'],
                      form.cleaned_data['message'])
        return super(FeedbackFormView, self).form_valid(form)

class FeedbackDone(FeedbackBase, TemplateView):
    template_name = 'cciw/feedback_done.html'

feedback = FeedbackFormView.as_view()
feedback_done = FeedbackDone.as_view()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.