From 00ccef62a48c74fabda3b047fd78a7411e73f691 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 5 Sep 2013 14:41:30 +0200 Subject: [PATCH] ContactView (was contact) now a class on its own in contactview.py --- portal/contactview.py | 41 +++++++++++++++++++++++++++++++++++++++++ portal/urls.py | 5 +++-- portal/views.py | 35 +---------------------------------- 3 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 portal/contactview.py diff --git a/portal/contactview.py b/portal/contactview.py new file mode 100644 index 00000000..44357f2d --- /dev/null +++ b/portal/contactview.py @@ -0,0 +1,41 @@ +from django.shortcuts import render + +from django.views.generic import View + +from myslice.viewutils import topmenu_items, the_user + +from portal.forms import ContactForm + +# view for contact form +class ContactView (View): + def dispatch(self, request): + if request.method == 'POST': # If the form has been submitted... + form = ContactForm(request.POST) # A form bound to the POST data + if form.is_valid(): # All validation rules pass + # Process the data in form.cleaned_data + first_name = form.cleaned_data['first_name'] + last_name = form.cleaned_data['last_name'] + affiliation = form.cleaned_data['affiliation'] + subject = form.cleaned_data['subject'] + message = form.cleaned_data['message'] + email = form.cleaned_data['email'] # email of the sender + cc_myself = form.cleaned_data['cc_myself'] + + #recipients = authority_get_pi_emails(authority_hrn) + recipients = ['yasin.upmc@gmail.com', 'thierry.parmentelat@inria.fr', ] + if cc_myself: + recipients.append(email) + + from django.core.mail import send_mail + send_mail("Onelab user submitted a query ", [first_name,last_name,affiliation,subject,message], email, recipients) + return render(request,'contact_sent.html') # Redirect after POST + else: + form = ContactForm() # An unbound form + + return render(request, 'contact.html', { + 'form': form, + 'topmenu_items': topmenu_items('Contact Us', request), + 'username': the_user (request) + + }) + diff --git a/portal/urls.py b/portal/urls.py index b23e0a2c..81016c77 100644 --- a/portal/urls.py +++ b/portal/urls.py @@ -24,11 +24,12 @@ from django.views.generic.base import TemplateView from django.conf.urls import patterns, include, url from portal.views import PresViewView, ValidatePendingView -from portal.views import account_process, contact, slice_request, register_4m_f4f +from portal.views import account_process, slice_request, register_4m_f4f from portal.platformsview import PlatformsView from portal.platformview import PlatformView from portal.dashboardview import DashboardView from portal.accountview import AccountView +from portal.contactview import ContactView # DEPRECATED #named_register_forms = ( @@ -54,7 +55,7 @@ urlpatterns = patterns('', url(r'^platform/(?P[\w\.]+)/?$', PlatformView.as_view(), name='platform'), url(r'^account/account_process/?$', account_process), url(r'^register/?$', register_4m_f4f), - url(r'^contact/?$', contact), + url(r'^contact/?$', ContactView.as_view(), name='contact'), # Slice request url(r'^slice_request/?$', slice_request), # Validate pending requests diff --git a/portal/views.py b/portal/views.py index e554f1bd..de2a9971 100644 --- a/portal/views.py +++ b/portal/views.py @@ -24,7 +24,6 @@ import os.path, re import json -#from django.views.generic import View from django.views.generic.base import TemplateView from django.shortcuts import render from django.template.loader import render_to_string @@ -38,7 +37,7 @@ from plugins.pres_view import PresView from portal.event import Event from portal import signals -from portal.forms import SliceRequestForm, ContactForm +from portal.forms import SliceRequestForm from portal.util import RegistrationView, ActivationView from portal.models import PendingUser, PendingSlice from portal.actions import authority_get_pi_emails, get_request_by_authority, manifold_add_user, manifold_update_user @@ -234,38 +233,6 @@ def register_4m_f4f(request): }) -# view for contact form -def contact(request): - if request.method == 'POST': # If the form has been submitted... - form = ContactForm(request.POST) # A form bound to the POST data - if form.is_valid(): # All validation rules pass - # Process the data in form.cleaned_data - first_name = form.cleaned_data['first_name'] - last_name = form.cleaned_data['last_name'] - affiliation = form.cleaned_data['affiliation'] - subject = form.cleaned_data['subject'] - message = form.cleaned_data['message'] - email = form.cleaned_data['email'] # email of the sender - cc_myself = form.cleaned_data['cc_myself'] - - #recipients = authority_get_pi_emails(authority_hrn) - recipients = ['yasin.upmc@gmail.com'] - if cc_myself: - recipients.append(email) - - from django.core.mail import send_mail - send_mail("Onelab user submitted a query ", [first_name,last_name,affiliation,subject,message], email, recipients) - return render(request,'contact_sent.html') # Redirect after POST - else: - form = ContactForm() # An unbound form - - return render(request, 'contact.html', { - 'form': form, - 'topmenu_items': topmenu_items('Contact Us', request), - 'username': the_user (request) - - }) - @login_required def slice_request(request): errors = [] -- 2.43.0