Mercurial > libervia-web
changeset 884:763da94ba28b
blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 09 Mar 2016 20:40:27 +0100 |
parents | 74be6217d913 |
children | 12e0bfdfe9c6 |
files | src/server/blog.py src/server/server.py |
diffstat | 2 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/server/blog.py Wed Mar 09 20:40:27 2016 +0100 +++ b/src/server/blog.py Wed Mar 09 20:40:27 2016 +0100 @@ -35,6 +35,7 @@ import re import os import sys +import urlparse import urllib from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML @@ -398,11 +399,17 @@ feed_elt = domish.Element((NS_ATOM, u'feed')) title = _(u"{user}'s blog").format(user=profile) feed_elt.addElement(u'title', content=title) - if self.host.base_url_ext is not None: - base_blog_url = u"{}blog/{user}".format(self.host.base_url_ext, user=profile) - else: - url_path = request.URLPath() - base_blog_url = u"{0.scheme}://{0.netloc}/blog/{user}".format(url_path, user=profile) + + # to construct base blog url, we use base_url_ext if given by user + # and complete unknown parts with what we find in request's url + url_path = request.URLPath() + ext_data = self.host.base_url_ext_data + base_blog_url = urlparse.urlunsplit(( + ext_data.scheme or url_path.scheme.decode('utf-8'), + ext_data.netloc or url_path.netloc.decode('utf-8'), + u'{}blog/{user}'.format(ext_data.path or u'/', user=profile), + '', + '')) # atom link link_feed_elt = feed_elt.addElement('link')
--- a/src/server/server.py Wed Mar 09 20:40:27 2016 +0100 +++ b/src/server/server.py Wed Mar 09 20:40:27 2016 +0100 @@ -1469,8 +1469,13 @@ self.base_url_ext = self.options.pop('base_url_ext') if self.base_url_ext[-1] != '/': self.base_url_ext += '/' + self.base_url_ext_data = urlparse.urlsplit(self.base_url_ext) else: self.base_url_ext = None + # we split empty string anyway so we can do things like + # scheme = self.base_url_ext_data.scheme or 'https' + self.base_url_ext_data = urlparse.urlsplit('') + if not self.options['port_https_ext']: self.options['port_https_ext'] = self.options['port_https'] if self.options['data_dir'] == DATA_DIR_DEFAULT: