comparison 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
comparison
equal deleted inserted replaced
883:74be6217d913 884:763da94ba28b
33 from jinja2 import Environment, PackageLoader 33 from jinja2 import Environment, PackageLoader
34 from datetime import datetime 34 from datetime import datetime
35 import re 35 import re
36 import os 36 import os
37 import sys 37 import sys
38 import urlparse
38 import urllib 39 import urllib
39 40
40 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML 41 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML
41 from libervia.server.constants import Const as C 42 from libervia.server.constants import Const as C
42 43
396 # from microblog data 397 # from microblog data
397 items, metadata= data 398 items, metadata= data
398 feed_elt = domish.Element((NS_ATOM, u'feed')) 399 feed_elt = domish.Element((NS_ATOM, u'feed'))
399 title = _(u"{user}'s blog").format(user=profile) 400 title = _(u"{user}'s blog").format(user=profile)
400 feed_elt.addElement(u'title', content=title) 401 feed_elt.addElement(u'title', content=title)
401 if self.host.base_url_ext is not None: 402
402 base_blog_url = u"{}blog/{user}".format(self.host.base_url_ext, user=profile) 403 # to construct base blog url, we use base_url_ext if given by user
403 else: 404 # and complete unknown parts with what we find in request's url
404 url_path = request.URLPath() 405 url_path = request.URLPath()
405 base_blog_url = u"{0.scheme}://{0.netloc}/blog/{user}".format(url_path, user=profile) 406 ext_data = self.host.base_url_ext_data
407 base_blog_url = urlparse.urlunsplit((
408 ext_data.scheme or url_path.scheme.decode('utf-8'),
409 ext_data.netloc or url_path.netloc.decode('utf-8'),
410 u'{}blog/{user}'.format(ext_data.path or u'/', user=profile),
411 '',
412 ''))
406 413
407 # atom link 414 # atom link
408 link_feed_elt = feed_elt.addElement('link') 415 link_feed_elt = feed_elt.addElement('link')
409 link_feed_elt['href'] = u'{base}/atom.xml'.format(base=base_blog_url) 416 link_feed_elt['href'] = u'{base}/atom.xml'.format(base=base_blog_url)
410 link_feed_elt['type'] = u'application/atom+xml' 417 link_feed_elt['type'] = u'application/atom+xml'