# HG changeset patch # User Goffi # Date 1453490550 -3600 # Node ID 0dfb76b13115ef92341751e71fb6ab191a29d67e # Parent fe43cf3ed7d856bd06f8791a839b8a7fc768d171 server (blog): fixes: - fixed BlogMessage comments arguments when comments is None - added a couple of forgotten "u" for unicode strings - added a workaround for an issue with empty
element. This workaround doesn't cover all cases diff -r fe43cf3ed7d8 -r 0dfb76b13115 src/server/blog.py --- a/src/server/blog.py Fri Jan 22 20:22:30 2016 +0100 +++ b/src/server/blog.py Fri Jan 22 20:22:30 2016 +0100 @@ -38,8 +38,8 @@ from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML from libervia.server.constants import Const as C - PARAMS_TO_GET = (C.STATIC_BLOG_PARAM_TITLE, C.STATIC_BLOG_PARAM_BANNER, C.STATIC_BLOG_PARAM_KEYWORDS, C.STATIC_BLOG_PARAM_DESCRIPTION) +re_strip_empty_div = re.compile(r"
|
*?
") # TODO: chech disco features and use max_items when RSM is not available @@ -73,6 +73,7 @@ @param unquote_value(str): value to unquote @return (unicode): unquoted value """ + assert not isinstance(quoted_value, unicode) return urllib.unquote(quoted_value).decode('utf-8') @@ -572,6 +573,8 @@ @param comments(list[dict]): list of microblog data @param comments_count (int): total number of comments """ + if comments is None: + comments = [] timestamp = float(entry.get('published', 0)) # FIXME: for now we assume that the comments' depth is only 1 @@ -583,7 +586,7 @@ self.content = self.getText(entry, 'content') if is_comment: - self.author = (_("from {}").format(entry['author'])) + self.author = (_(u"from {}").format(entry['author'])) else: self.author = ' ' self.url = "{}/{}".format(base_url, _quote(entry['id'])) @@ -593,14 +596,14 @@ self.title = self.getText(entry, 'title') self.tags = [sanitizeHtml(tag) for tag in common.dict2iter('tag', entry)] - count_text = lambda count: D_('comments') if count > 1 else D_('comment') + count_text = lambda count: D_(u'comments') if count > 1 else D_(u'comment') self.comments_text = u"{} {}".format(comments_count, count_text(comments_count)) delta = comments_count - len(comments) if request.display_single and delta > 0: prev_url = "{}?{}".format(self.url, urllib.urlencode({'comments_max': comments_count})) - prev_text = D_("show {count} previous {comments}").format( + prev_text = D_(u"show {count} previous {comments}").format( count = delta, comments = count_text(delta)) self.all_comments_link = BlogLink(prev_url, "comments_link", prev_text) @@ -609,10 +612,15 @@ def getText(self, entry, key): try: - return fixXHTMLLinks(entry['{}_xhtml'.format(key)]) + xhtml = entry['{}_xhtml'.format(key)] except KeyError: try: processor = addURLToText if key.startswith('content') else sanitizeHtml return convertNewLinesToXHTML(processor(entry[key])) except KeyError: return None + else: + # FIXME: empty
elements provoke rendering issue + # this regex is a temporary workadound, need more investigation + xhtml = re_strip_empty_div.sub("", xhtml) + return fixXHTMLLinks(xhtml)