ContactView (was contact) now a class on its own in contactview.py
[myslice.git] / portal / contactview.py
1 from django.shortcuts           import render
2
3 from django.views.generic       import View
4
5 from myslice.viewutils          import topmenu_items, the_user
6
7 from portal.forms               import ContactForm
8
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']
23
24             #recipients = authority_get_pi_emails(authority_hrn)
25             recipients = ['yasin.upmc@gmail.com', 'thierry.parmentelat@inria.fr', ]
26             if cc_myself:
27                 recipients.append(email)
28
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
32     else:
33         form = ContactForm() # An unbound form
34     
35     return render(request, 'contact.html', {
36         'form': form,
37         'topmenu_items': topmenu_items('Contact Us', request),
38         'username': the_user (request)
39
40     })
41