From e591623d1baa418d5d925b6b9d4fbcb8da915321 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Sat, 18 Nov 2006 12:16:42 +0000
Subject: [PATCH] add button for hot relaoding of Constraints do not create
 Constraint with empty class name

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11366 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Constraint/__init__.py       |  1 +
 product/ERP5Type/Tool/ClassTool.py            | 22 ++++++++++++++++++-
 product/ERP5Type/dtml/editConstraintForm.dtml |  1 +
 product/ERP5Type/dtml/viewConstraintList.dtml |  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Type/Constraint/__init__.py b/product/ERP5Type/Constraint/__init__.py
index 314b62836e..b4f1ef3cac 100644
--- a/product/ERP5Type/Constraint/__init__.py
+++ b/product/ERP5Type/Constraint/__init__.py
@@ -8,3 +8,4 @@ from CategoryExistence import CategoryExistence
 from PortalTypeClass import PortalTypeClass
 from CategoryAcquiredMembershipArity import CategoryAcquiredMembershipArity
 from TALESConstraint import TALESConstraint
+from BankAccountRIB import BankAccountRIB
diff --git a/product/ERP5Type/Tool/ClassTool.py b/product/ERP5Type/Tool/ClassTool.py
index 9d0f8a5e8e..e23b640f53 100644
--- a/product/ERP5Type/Tool/ClassTool.py
+++ b/product/ERP5Type/Tool/ClassTool.py
@@ -545,7 +545,11 @@ class Test(ERP5TypeTestCase):
       def newConstraint(self, class_id, REQUEST=None):
         """
           Updates a Constraint with a new text
-        """
+        """        
+        if class_id == '':
+          if REQUEST is not None:
+            REQUEST.RESPONSE.redirect('%s/manage_viewConstraintList?message=You+must+specify+a+class+name' % (self.absolute_url(),))
+            return
         text = """
 ##############################################################################
 #
@@ -608,6 +612,22 @@ class ConstraintTemplate(Constraint):
         if REQUEST is not None:
           REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Saved' % (self.absolute_url(), class_id))
 
+      security.declareProtected( Permissions.ManageExtensions, 'importConstraint' )
+      def importConstraint(self, class_id, REQUEST=None):
+        """
+          Imports a Constraint class
+        """
+        from Products.ERP5Type.Utils import importLocalConstraint
+        local_product = self.Control_Panel.Products.ERP5Type
+        app = local_product._p_jar.root()['Application']
+        importLocalConstraint(class_id)
+        # Reset _aq_dynamic after reload
+        # There is no need to reset the cache in this case because
+        # XXX it is not sure however that class defined propertysheets will be updated
+        _aq_reset() 
+        if REQUEST is not None:
+          REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Reloaded+Successfully' % (self.absolute_url(), class_id))
+
       security.declareProtected( Permissions.ManageExtensions, 'generateProduct' )
       def generateProduct(self, product_id,
                           document_id_list=(), property_sheet_id_list=(), constraint_id_list=(),
diff --git a/product/ERP5Type/dtml/editConstraintForm.dtml b/product/ERP5Type/dtml/editConstraintForm.dtml
index 2143ca7e13..805ba3626a 100644
--- a/product/ERP5Type/dtml/editConstraintForm.dtml
+++ b/product/ERP5Type/dtml/editConstraintForm.dtml
@@ -10,6 +10,7 @@
 <br>
 <input type="hidden" name="class_id:string" value="<dtml-var class_id>">
 <input type="submit" value="Save" name="editConstraint:method">
+<input type="submit" value="Reload" name="importConstraint:method">  
 </form>
 
 <dtml-var manage_page_footer>
diff --git a/product/ERP5Type/dtml/viewConstraintList.dtml b/product/ERP5Type/dtml/viewConstraintList.dtml
index e93457457e..ae4aa4e5ab 100644
--- a/product/ERP5Type/dtml/viewConstraintList.dtml
+++ b/product/ERP5Type/dtml/viewConstraintList.dtml
@@ -2,7 +2,7 @@
 <dtml-var manage_tabs>
 
 <div class="std-text"><p><strong>Local Constraint Classes</strong></p></div>
-
+<dtml-if message><dtml-var message></dtml-if>
 <form method="POST" action="newConstraint">
 <table width="100%">
   <tr class="list-header">
-- 
2.30.9