1 from django.shortcuts import render
3 from django.views.generic import View
5 from myslice.viewutils import topmenu_items, the_user
7 from portal.forms import ContactForm
9 # view for contact form
10 class ContactView (View):
11 def dispatch(self, request):
12 if request.method == 'POST': # If the form has been submitted...
13 form = ContactForm(request.POST) # A form bound to the POST data
14 if form.is_valid(): # All validation rules pass
15 # Process the data in form.cleaned_data
16 first_name = form.cleaned_data['first_name']
17 last_name = form.cleaned_data['last_name']
18 affiliation = form.cleaned_data['affiliation']
19 subject = form.cleaned_data['subject']
20 message = form.cleaned_data['message']
21 email = form.cleaned_data['email'] # email of the sender
22 cc_myself = form.cleaned_data['cc_myself']
24 #recipients = authority_get_pi_emails(authority_hrn)
25 recipients = ['yasin.upmc@gmail.com', 'thierry.parmentelat@inria.fr', ]
27 recipients.append(email)
29 from django.core.mail import send_mail
30 send_mail("Onelab user submitted a query ", [first_name,last_name,affiliation,subject,message], email, recipients)
31 return render(request,'contact_sent.html') # Redirect after POST
33 form = ContactForm() # An unbound form
35 return render(request, 'contact.html', {
37 'topmenu_items': topmenu_items('Contact Us', request),
38 'username': the_user (request)