From f4423fb1e781e3fc4cd9f3bd12b959635c485f37 Mon Sep 17 00:00:00 2001
From: Alain Takoudjou <talino@tiolive.com>
Date: Wed, 30 Jul 2014 12:35:32 +0200
Subject: [PATCH] Check for notification_message value in case of it return
 None

---
 ...Computer_checkAndUpdateAllocationScope.xml | 29 +++++++++++++------
 .../slapos_crm/Computer_checkState.xml        | 19 ++++++++----
 master/bt5/slapos_crm/bt/revision             |  2 +-
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkAndUpdateAllocationScope.xml b/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkAndUpdateAllocationScope.xml
index a30ea10a8..7a4a1b25a 100644
--- a/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkAndUpdateAllocationScope.xml
+++ b/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkAndUpdateAllocationScope.xml
@@ -83,15 +83,6 @@ if not is_service_provider:\n
   request_title = \'[MONITORING] Allocation scope has been changed for %s\' % computer_reference\n
   request_description = \'Allocation scope has been changed back to \' \\\n
                        \'open/personal for %s\' % computer_reference\n
-  message_title = \'We have changed allocation scope for %s\' % computer_reference\n
-  notification_reference = \'slapos-crm-computer_allocation_scope.notification\'\n
-  notification_message = portal.portal_notifications.getDocumentValue(\n
-                 reference=notification_reference)\n
-  mapping_dict = {\'computer_title\':computer.getTitle(),\n
-                  \'computer_id\':computer_reference,\n
-                  \'allocation_scope\':allocation_scope}\n
-  message = notification_message.asText(\n
-            substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
             \n
   support_request_url = context.Base_generateSupportRequestForSlapOS(\n
                  request_title,\n
@@ -114,6 +105,26 @@ if not is_service_provider:\n
     # Existing ticket not found, can not create event for the moment\n
     return\n
   \n
+  # Send notification message\n
+  message_title = \'We have changed allocation scope for %s\' % computer_reference\n
+  notification_reference = \'slapos-crm-computer_allocation_scope.notification\'\n
+  notification_message = portal.portal_notifications.getDocumentValue(\n
+                 reference=notification_reference)\n
+  if notification_message is None:\n
+    message = """Dear user,\n
+%s.\n
+Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.\n
+\n
+Regards,\n
+\n
+The slapos team""" % request_description\n
+  else:\n
+    mapping_dict = {\'computer_title\':computer.getTitle(),\n
+                    \'computer_id\':computer_reference,\n
+                    \'allocation_scope\':allocation_scope}\n
+    message = notification_message.asText(\n
+              substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
+  \n
   support_request.SupportRequest_trySendNotificationMessage(message_title,\n
               message, person.getRelativeUrl())\n
 </string> </value>
diff --git a/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkState.xml b/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkState.xml
index fcfb19cda..09e99d85d 100644
--- a/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkState.xml
+++ b/master/bt5/slapos_crm/SkinTemplateItem/portal_skins/slapos_crm/Computer_checkState.xml
@@ -117,11 +117,20 @@ if should_notify:\n
   notification_reference = \'slapos-crm-computer_check_state.notification\'\n
   notification_message = portal.portal_notifications.getDocumentValue(\n
                  reference=notification_reference)\n
-  mapping_dict = {\'computer_title\':context.getTitle(),\n
-                  \'computer_id\':reference,\n
-                  \'last_contact\':last_contact}\n
-  message = notification_message.asText(\n
-            substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
+  if notification_message is None:\n
+    message = """Dear user,\n
+%s.\n
+Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.\n
+\n
+Regards,\n
+\n
+The slapos team""" % description\n
+  else:\n
+    mapping_dict = {\'computer_title\':context.getTitle(),\n
+                    \'computer_id\':reference,\n
+                    \'last_contact\':last_contact}\n
+    message = notification_message.asText(\n
+              substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
   \n
   support_request.SupportRequest_trySendNotificationMessage(\n
               ticket_title.replace(\'[MONITORING] \', \'\'),\n
diff --git a/master/bt5/slapos_crm/bt/revision b/master/bt5/slapos_crm/bt/revision
index ac4213d6e..d2e1cefe8 100644
--- a/master/bt5/slapos_crm/bt/revision
+++ b/master/bt5/slapos_crm/bt/revision
@@ -1 +1 @@
-43
\ No newline at end of file
+44
\ No newline at end of file
-- 
2.30.9