ContactView (was contact) now a class on its own in contactview.py
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 5 Sep 2013 12:41:30 +0000 (14:41 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 5 Sep 2013 12:41:30 +0000 (14:41 +0200)
portal/contactview.py [new file with mode: 0644]
portal/urls.py
portal/views.py

diff --git a/portal/contactview.py b/portal/contactview.py
new file mode 100644 (file)
index 0000000..44357f2
--- /dev/null
@@ -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)
+
+    })
+
index b23e0a2..81016c7 100644 (file)
@@ -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<platformname>[\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
index e554f1b..de2a997 100644 (file)
@@ -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 = []