From ccbe8e6feddb9264d4f6e0cab88da8f1716797e3 Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Mon, 26 Jan 2004 16:27:50 +0000
Subject: [PATCH] added setter and getter for guid

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@340 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Base.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py
index 5c14e0a616..77dcaf8b83 100755
--- a/product/ERP5Type/Base.py
+++ b/product/ERP5Type/Base.py
@@ -59,6 +59,8 @@ import pickle
 from cStringIO import StringIO
 from email.MIMEBase import MIMEBase
 from email import Encoders
+from socket import gethostname, gethostbyaddr
+import random
 
 from zLOG import LOG
 
@@ -1206,6 +1208,30 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
 
   psyco.bind(getObjectMenu)
 
+  security.declareProtected(Permissions.ModifyPortalContent, 'setGuid')
+  def setGuid(self):
+    """
+    This generate a global and unique id
+    It will be defined like this :
+     full dns name + portal_name + uid + random
+     the guid should be defined only one time for each object
+    """
+    if not hasattr(self, 'guid'):
+      guid = ''
+      # Set the dns name
+      guid += gethostbyaddr(gethostname())[0]
+      guid += '_' + self.portal_url.getPortalPath()
+      guid += '_' + str(self.uid)
+      guid += '_' + str(random.randrange(1,2147483600))
+    setattr(self,'guid',guid)
+
+  security.declareProtected(Permissions.AccessContentsInformation, 'getGuid')
+  def getGuid(self):
+    """
+    Get the global and unique id
+    """
+    return getattr(self,'guid',None)
+
 class TempBase(Base):
   """
     If we need Base services (categories, edit, etc) in temporary objects
-- 
2.30.9