diff src/server/blog.py @ 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 d3d2b97aa12c
children 12e0bfdfe9c6
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')