1 from django.shortcuts import render
2 from django.template.loader import render_to_string
3 from django.views.generic import View
4 from django.core.mail import send_mail
6 from ui.topmenu import topmenu_items, the_user
8 from portal.forms import ContactForm
10 # splitting the 2 functions done here
11 # GET is for displaying the empty form
12 # POST is to process it once filled - or show the form again if anything is missing
13 class ContactView (View):
14 def post (self, request):
15 form = ContactForm(request.POST) # A form bound to the POST data
16 if form.is_valid(): # All validation rules pass
17 # Process the data in form.cleaned_data
18 first_name = form.cleaned_data['first_name']
19 last_name = form.cleaned_data['last_name']
20 affiliation = form.cleaned_data['affiliation']
21 subject = form.cleaned_data['subject']
22 message = form.cleaned_data['message']
23 email = form.cleaned_data['email'] # email of the sender
24 cc_myself = form.cleaned_data['cc_myself']
26 #recipients = authority_get_pi_emails(authority_hrn)
27 recipients = ['yasin.upmc@gmail.com', 'thierry.parmentelat@inria.fr', ]
29 recipients.append(email)
31 msg = render_to_string('slice-request-email.txt', form.cleaned_data)
32 send_mail("Onelab user %s submitted a query "%email, msg, email, recipients)
33 return render(request,'contact_sent.html') # Redirect after POST
35 return self._display (request, form)
37 def get (self, request):
38 return self._display (request, ContactForm()) # A fresh unbound form
40 def _display (self, request, form):
41 return render(request, 'contact.html', {
43 'topmenu_items': topmenu_items('Contact Us', request),
44 'username': the_user (request)