Ignore:
Timestamp:
Jul 30, 2009 2:43:06 PM (15 years ago)
Author:
koval
Message:

fixed bug in rewriting of absolute links in blog entry's text

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.transmogrifier.simpleblog2quills/trunk/quintagroup/transmogrifier/simpleblog2quills/adapters.py

    r612 r1193  
    130130        urls = self.SRC.findall(text) 
    131131        blog = recurseToInterface(self.context, IBlog) 
    132         blog_url = blog.absolute_url() 
    133132        blog_path = blog.getPhysicalPath() 
     133        context_path = self.context.getPhysicalPath() 
    134134        for url in urls: 
    135135            url = str(url) 
    136136            image_id = url.rsplit('/', 1)[-1] 
    137             # bad link 
     137            # skip links with illegal url schema 
    138138            if '://' in url and not url.startswith('http://'): 
    139139                continue 
     140            # convert all all links to relative 
    140141            if url.startswith('http://'): 
    141142                for site in SITE_URLS: 
     
    152153                        if in_blog: 
    153154                            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 
    155164                            text = text.replace(url, new_url, 1) 
    156165                        break 
     
    171180                if in_blog: 
    172181                    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 
    175183                    new_url = '/'.join(['..' for i in range(level)]) 
    176184                    new_url = '/'.join([new_url, IMAGE_FOLDER, image_id]) 
    177185                    text = text.replace(url, new_url, 1) 
    178186                elif url.startswith('../'): 
    179                     # remove '../' from the start of sting 
     187                    # remove '../' from the start of string 
    180188                    new_url = url[3:] 
    181189                    text = text.replace(url, new_url, 1) 
    182190                elif url.startswith('/'): 
    183191                    # these links didn't work so rewrite them with '..' 
    184                     # find how many level self.context is under portal root 
    185                     level = len(self.context.getPhysicalPath()) - 3 
     192                    # find how many levels self.context is under portal root 
     193                    level = len(context_path) - 3 
    186194                    new_url = '/'.join(['..' for i in range(level)]) 
    187195                    new_url  = new_url + url 
Note: See TracChangeset for help on using the changeset viewer.