Commit 7da27841 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Fix asURL for the case when the url string contains a protocol already.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29540 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4749c6c1
...@@ -33,6 +33,7 @@ from Products.ERP5Type.Base import Base ...@@ -33,6 +33,7 @@ from Products.ERP5Type.Base import Base
from Products.ERP5.Document.Coordinate import Coordinate from Products.ERP5.Document.Coordinate import Coordinate
from Products.ERP5.Tool.NotificationTool import buildEmailMessage from Products.ERP5.Tool.NotificationTool import buildEmailMessage
from zLOG import LOG from zLOG import LOG
import urllib
no_crawl_protocol_list = ['mailto', 'javascript', ] no_crawl_protocol_list = ['mailto', 'javascript', ]
no_host_protocol_list = ['mailto', 'news', 'javascript',] no_host_protocol_list = ['mailto', 'news', 'javascript',]
...@@ -52,6 +53,11 @@ class UrlMixIn: ...@@ -52,6 +53,11 @@ class UrlMixIn:
Returns a text representation of the Url if defined Returns a text representation of the Url if defined
or None else. 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() protocol = self.getUrlProtocol()
if not protocol: if not protocol:
# A quick fix for all objects which did not # A quick fix for all objects which did not
...@@ -61,8 +67,6 @@ class UrlMixIn: ...@@ -61,8 +67,6 @@ class UrlMixIn:
protocol = default_protocol_dict[ptype] protocol = default_protocol_dict[ptype]
else: else:
protocol = 'http' protocol = 'http'
url_string = self.getUrlString()
if not url_string: return None
if protocol in no_host_protocol_list or url_string.startswith('//'): if protocol in no_host_protocol_list or url_string.startswith('//'):
return '%s:%s' % (protocol, url_string) return '%s:%s' % (protocol, url_string)
return '%s://%s' % (protocol, url_string) return '%s://%s' % (protocol, url_string)
......
...@@ -1189,6 +1189,15 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -1189,6 +1189,15 @@ class TestERP5Base(ERP5TypeTestCase):
self.assertEquals('mailto:nobody@example.com', self.assertEquals('mailto:nobody@example.com',
pers.Entity_getDefaultEmailAsURL()) 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): def test_getTranslatedId(self):
pers = self.getPersonModule().newContent( pers = self.getPersonModule().newContent(
portal_type='Person', id='default_email') portal_type='Person', id='default_email')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment