slice-req-denied email added
authorYasin <mohammed-yasin.rahman@lip6.fr>
Fri, 29 Aug 2014 14:57:22 +0000 (16:57 +0200)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Fri, 29 Aug 2014 14:57:22 +0000 (16:57 +0200)
portal/actions.py
portal/templates/management-tab-requests.html
portal/templates/slice_request_denied.html [new file with mode: 0644]
portal/templates/slice_request_denied.txt [new file with mode: 0644]

index d95a78e..0845619 100644 (file)
@@ -483,7 +483,37 @@ def portal_reject_request(wsgi_request, request_ids):
                 request_status['SFA authority'] = {'status': False, 'description': str(e)}
                       
         elif request['type'] == 'slice':
-            request_status['SFA slice'] = {'status': True }           
+            request_status['SFA slice'] = {'status': True } 
+
+            # getting user email based on id 
+            ## RAW SQL queries on Django DB- https://docs.djangoproject.com/en/dev/topics/db/sql/
+            for user in PendingUser.objects.raw('SELECT * FROM portal_pendingslice WHERE id = %s', [request['id']]):
+                user_email= user.type_of_nodes # XXX type_of_nodes field contains the email [shd be renamed]
+
+                # get the domain url
+                current_site = Site.objects.get_current()
+                current_site = current_site.domain
+
+                ctx = {
+                    'portal_url'    : current_site,
+                    }
+                try:
+                    theme.template_name = 'slice_request_denied.txt'
+                    text_content = render_to_string(theme.template, ctx)
+                    theme.template_name = 'slice_request_denied.html'
+                    html_content = render_to_string(theme.template, ctx)
+                    theme.template_name = 'email_default_sender.txt'
+                    sender =  render_to_string(theme.template, ctx)
+                    sender = sender.replace('\n', '')
+                               
+                    subject = 'Slice request denied.'
+
+                    msg = EmailMultiAlternatives(subject, text_content, sender, [user_email])
+                    msg.attach_alternative(html_content, "text/html")
+                    msg.send()
+                except Exception, e:
+                    print "Failed to send email, please check the mail templates and the SMTP configuration of your server"
+                      
             PendingSlice.objects.get(id=request['id']).delete()
         elif request['type'] == 'authority':
             request_status['SFA authority'] = {'status': True }           
@@ -578,8 +608,9 @@ def create_pending_slice(wsgi_request, request, email):
         slice_name      = request['slice_name'],
         user_hrn        = request['user_hrn'],
         authority_hrn   = request['authority_hrn'],
-        number_of_nodes = request['url'],
+        number_of_nodes = request['url'], # field needs to be renamed
         purpose         = request['purpose'],
+        type_of_nodes   = request['email'] # field needs to be renamed 
     )
     s.save()
 
index c570c7c..346ecb0 100644 (file)
         Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
         {% else %}
             {% if request.type == 'slice' %}
-        Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
+        Slice name: {{request.slice_name}} -- Url: {{request.number_of_nodes}} -- Email: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
             {% else %} {# authority #}
         Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
             {% endif %}
diff --git a/portal/templates/slice_request_denied.html b/portal/templates/slice_request_denied.html
new file mode 100644 (file)
index 0000000..d9ebaad
--- /dev/null
@@ -0,0 +1,13 @@
+<img src="{{ STATIC_URL }}img/onelab.png">
+<br>
+<p>Dear OneLab user,</p>
+<p></p>
+<p>You have recently requested a slice in the OneLab portal. We are sorry to inform you that, a manager of your institution has rejected your request. Please contact the manager of your institution for further information. For any other queries, contact us by replying to this email.</p>
+<p></p>
+<p>On behalf of the entire team, I wish you a fruitful user experience on OneLab.</p>
+<p></p>
+<p>Yours sincerely,</p>
+<p></p>
+<p>Timur Friedman</p>
+<p>Executive Director</p>
+
diff --git a/portal/templates/slice_request_denied.txt b/portal/templates/slice_request_denied.txt
new file mode 100644 (file)
index 0000000..c2587df
--- /dev/null
@@ -0,0 +1,11 @@
+Dear OneLab user,
+
+You have recently requested a slice in the OneLab portal. We are sorry to inform you that, a manager of your institution has rejected your request. Please contact the manager of your institution for further information. For any other queries, contact us by replying to this email.
+
+On behalf of the entire team, I wish you a fruitful user experience on OneLab..
+
+Yours sincerely,
+
+Timur Friedman
+Executive Director
+