[Erp5-report] r29540 - in /erp5/trunk/products/ERP5: Document/Url.py tests/testERP5Base.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Oct 9 16:51:08 CEST 2009


Author: yo
Date: Fri Oct  9 16:51:05 2009
New Revision: 29540

URL: http://svn.erp5.org?rev=29540&view=rev
Log:
Fix asURL for the case when the url string contains a protocol already.

Modified:
    erp5/trunk/products/ERP5/Document/Url.py
    erp5/trunk/products/ERP5/tests/testERP5Base.py

Modified: erp5/trunk/products/ERP5/Document/Url.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Url.py?rev=29540&r1=29539&r2=29540&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Url.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Url.py [utf8] Fri Oct  9 16:51:05 2009
@@ -33,6 +33,7 @@
 from Products.ERP5.Document.Coordinate import Coordinate
 from Products.ERP5.Tool.NotificationTool import buildEmailMessage
 from zLOG import LOG
+import urllib
 
 no_crawl_protocol_list = ['mailto', 'javascript', ]
 no_host_protocol_list = ['mailto', 'news', 'javascript',]
@@ -52,6 +53,11 @@
     Returns a text representation of the Url if defined
     or None else.
     """
+    url_string = self.getUrlString()
+    if not url_string:
+      return None
+    if urllib.splittype(url_string)[0]:
+      return url_string
     protocol = self.getUrlProtocol()
     if not protocol:
       # A quick fix for all objects which did not
@@ -61,8 +67,6 @@
         protocol = default_protocol_dict[ptype]
       else:
         protocol = 'http'
-    url_string = self.getUrlString()
-    if not url_string: return None
     if protocol in no_host_protocol_list or url_string.startswith('//'):
       return '%s:%s' % (protocol, url_string)
     return '%s://%s' % (protocol, url_string)

Modified: erp5/trunk/products/ERP5/tests/testERP5Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testERP5Base.py?rev=29540&r1=29539&r2=29540&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testERP5Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testERP5Base.py [utf8] Fri Oct  9 16:51:05 2009
@@ -1189,6 +1189,15 @@
     self.assertEquals('mailto:nobody at example.com',
                       pers.Entity_getDefaultEmailAsURL())
 
+  def test_LinkAsURL(self):
+    person = self.getPersonModule().newContent(portal_type='Person')
+    link = person.newContent(portal_type='Link',
+                             url_string='http://www.nexedi.com/')
+    self.assertEquals(link.asURL(), 'http://www.nexedi.com/')
+    link = person.newContent(portal_type='Link',
+                             url_string='www.nexedi.com')
+    self.assertEquals(link.asURL(), 'http://www.nexedi.com')
+
   def test_getTranslatedId(self):
     pers = self.getPersonModule().newContent(
                 portal_type='Person', id='default_email')




More information about the Erp5-report mailing list