Django CMS - enable URL prefix (useful for proxy URLs)

This modification is to add a URL prefix to all URLs, so all the link generated within the CMS will have that prefix automatically implemented.

The reason I have implemented that change is because I had to match the URLs from my site to URL being proxied from another server. Since the proxied URL contains extra path (.eg example.com/welcome) and my site is running under the root (eg.mysite.com), I'm adding this prefix (in that case it would be /welcome) to all my site URL so it matches the ones from the proxy.

Ok so first, we must added this setting in settings.py:

CMS_URL_PREFIX = '/welcome'

Please we won't use a slash in the end, since it's already added by the URL resolver.

There are 2 areas where that prefix must be added:

In cms/models/page_model.py:

def get_absolute_url(self, language=None, fallback=True):
    if self.is_home():
        return reverse('pages-root', prefix=settings.CMS_URL_PREFIX)
    if settings.CMS_FLAT_URLS:
        path = self.get_slug(language, fallback)
        return urlutils.urljoin(reverse('pages-root', prefix=settings.CMS_URL_PREFIX), path)
    path = self.get_path(language, fallback)
    return urlutils.urljoin(reverse('pages-root', prefix=settings.CMS_URL_PREFIX), path)

Modified line 122:

return reverse('pages-root', prefix=settings.CMS_URL_PREFIX)

Modified line 125:

return urlutils.urljoin(reverse('pages-root', prefix=settings.CMS_URL_PREFIX), path)

Modified line 128:

return urlutils.urljoin(reverse('pages-root', prefix=settings.CMS_URL_PREFIX), path)

In menus/menu_pool.py:

def _mark_selected(self, request, nodes):
    sel = None
    for node in nodes:
        node.sibling = False
        node.ancestor = False
        node.descendant = False
        node.selected = False
        url_to_comp = settings.CMS_URL_PREFIX+request.path[:len(node.get_absolute_url())]
        if node.get_absolute_url().strip('/') == url_to_comp.strip('/'):
            if sel:
                if len(node.get_absolute_url()) > len(sel.get_absolute_url()):
                    sel = node
            else:
                sel = node
        else:
            node.selected = False
    if sel:
        sel.selected = True
    return nodes

Modified line 173:

url_to_comp = settings.CMS_URL_PREFIX+request.path[:len(node.get_absolute_url())]

Modified line 174:

if node.get_absolute_url() == url_to_comp.strip('/'):
< / >