Changeset 1193 in products for quintagroup.transmogrifier.simpleblog2quills/trunk/quintagroup/transmogrifier
- Timestamp:
- Jul 30, 2009 2:43:06 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.transmogrifier.simpleblog2quills/trunk/quintagroup/transmogrifier/simpleblog2quills/adapters.py
r612 r1193 130 130 urls = self.SRC.findall(text) 131 131 blog = recurseToInterface(self.context, IBlog) 132 blog_url = blog.absolute_url()133 132 blog_path = blog.getPhysicalPath() 133 context_path = self.context.getPhysicalPath() 134 134 for url in urls: 135 135 url = str(url) 136 136 image_id = url.rsplit('/', 1)[-1] 137 # bad link137 # skip links with illegal url schema 138 138 if '://' in url and not url.startswith('http://'): 139 139 continue 140 # convert all all links to relative 140 141 if url.startswith('http://'): 141 142 for site in SITE_URLS: … … 152 153 if in_blog: 153 154 image_id = self.fixImageId(image, image_id, blog_path) 154 new_url = '/'.join((blog_url, IMAGE_FOLDER, image_id)) 155 level = len(context_path) - len(blog_path) - 1 156 new_url = '/'.join(['..' for i in range(level)]) 157 new_url = '/'.join((new_url, IMAGE_FOLDER, image_id)) 158 text = text.replace(url, new_url, 1) 159 else: 160 # find how many levels self.context is under portal root 161 level = len(context_path) - 3 162 new_url = '/'.join(['..' for i in range(level)]) 163 new_url = new_url + '/' + relative_url 155 164 text = text.replace(url, new_url, 1) 156 165 break … … 171 180 if in_blog: 172 181 image_id = self.fixImageId(image, image_id, blog_path) 173 path = self.context.getPhysicalPath() 174 level = len(path) - len(blog_path) - 1 182 level = len(context_path) - len(blog_path) - 1 175 183 new_url = '/'.join(['..' for i in range(level)]) 176 184 new_url = '/'.join([new_url, IMAGE_FOLDER, image_id]) 177 185 text = text.replace(url, new_url, 1) 178 186 elif url.startswith('../'): 179 # remove '../' from the start of st ing187 # remove '../' from the start of string 180 188 new_url = url[3:] 181 189 text = text.replace(url, new_url, 1) 182 190 elif url.startswith('/'): 183 191 # these links didn't work so rewrite them with '..' 184 # find how many level self.context is under portal root185 level = len( self.context.getPhysicalPath()) - 3192 # find how many levels self.context is under portal root 193 level = len(context_path) - 3 186 194 new_url = '/'.join(['..' for i in range(level)]) 187 195 new_url = new_url + url
Note: See TracChangeset
for help on using the changeset viewer.