comparison libervia/server/blog.py @ 1156:3048bd137aaf

server, browser: changed blog items serialisation following changes in backend
author Goffi <goffi@goffi.org>
date Sat, 23 Feb 2019 21:03:21 +0100
parents 2af117bfe6cc
children 1276452c0d32
comparison
equal deleted inserted replaced
1155:813d54af8c0c 1156:3048bd137aaf
351 @param profile 351 @param profile
352 """ 352 """
353 353
354 def gotItems(items): 354 def gotItems(items):
355 items, metadata = items 355 items, metadata = items
356 items = [data_format.deserialise(i) for i in items]
356 item = items[0] # assume there's only one item 357 item = items[0] # assume there's only one item
357 358
358 def gotMetadata(result): 359 def gotMetadata(result):
359 dummy, rsm_metadata = result 360 dummy, rsm_metadata = result
360 try: 361 try:
375 comments = [ 376 comments = [
376 ( 377 (
377 item["comments_service"], 378 item["comments_service"],
378 item["comments_node"], 379 item["comments_node"],
379 "", 380 "",
380 comments[0], 381 [data_format.deserialise(c) for c in comments[0]],
381 comments[1], 382 comments[1],
382 ) 383 )
383 ] 384 ]
384 self.renderHTML( 385 self.renderHTML(
385 [(item, comments)], metadata, request, pub_jid, profile 386 [(item, comments)], metadata, request, pub_jid, profile
486 487
487 def gotItems(data): 488 def gotItems(data):
488 # Generate a clean atom feed with uri linking to this blog 489 # Generate a clean atom feed with uri linking to this blog
489 # from microblog data 490 # from microblog data
490 items, metadata = data 491 items, metadata = data
492 items = [data_format.deserialise(i) for i in items]
491 feed_elt = domish.Element((NS_ATOM, u"feed")) 493 feed_elt = domish.Element((NS_ATOM, u"feed"))
492 title = _(u"{user}'s blog").format(user=profile) 494 title = _(u"{user}'s blog").format(user=profile)
493 feed_elt.addElement(u"title", content=title) 495 feed_elt.addElement(u"title", content=title)
494 496
495 base_blog_url = self.host.getExtBaseURL( 497 base_blog_url = self.host.getExtBaseURL(
572 author_elt.addElement("email", content=item["author_email"]) 574 author_elt.addElement("email", content=item["author_email"])
573 except KeyError: 575 except KeyError:
574 pass 576 pass
575 577
576 # categories 578 # categories
577 for tag in data_format.dict2iter("tag", item): 579 for tag in item.get('tags', []):
578 category_elt = entry_elt.addElement(u"category") 580 category_elt = entry_elt.addElement(u"category")
579 category_elt["term"] = tag 581 category_elt["term"] = tag
580 582
581 # content 583 # content
582 try: 584 try:
853 self.url = "{}/{}".format(base_url, _quote(entry["id"])) 855 self.url = "{}/{}".format(base_url, _quote(entry["id"]))
854 query_data = getDefaultQueryData(request) 856 query_data = getDefaultQueryData(request)
855 if query_data: 857 if query_data:
856 self.url += "?{}".format(_urlencode(query_data)) 858 self.url += "?{}".format(_urlencode(query_data))
857 self.title = self.getText(entry, "title") 859 self.title = self.getText(entry, "title")
858 self.tags = [sanitizeHtml(tag) for tag in data_format.dict2iter("tag", entry)] 860 self.tags = [sanitizeHtml(tag) for tag in entry.get('tags', [])]
859 861
860 count_text = lambda count: D_(u"comments") if count > 1 else D_(u"comment") 862 count_text = lambda count: D_(u"comments") if count > 1 else D_(u"comment")
861 863
862 self.comments_text = u"{} {}".format( 864 self.comments_text = u"{} {}".format(
863 comments_count, count_text(comments_count) 865 comments_count, count_text(comments_count)