comparison frontends/src/quick_frontend/quick_blog.py @ 1666:dbac3cb19159

quick frontend (blog): replaced mbdata2tags and tags2mbdata by sat.tools.common.dict2iter and iter2dict
author Goffi <goffi@goffi.org>
date Tue, 24 Nov 2015 23:28:11 +0100
parents 47224056ce5c
children bf67dc424784
comparison
equal deleted inserted replaced
1665:14fcbaa82fd4 1666:dbac3cb19159
47 """ 47 """
48 self.id = data['id'] 48 self.id = data['id']
49 self.title = data.get('title') 49 self.title = data.get('title')
50 self.title_rich = None 50 self.title_rich = None
51 self.title_xhtml = data.get('title_xhtml') 51 self.title_xhtml = data.get('title_xhtml')
52 self.tags = mbdata2tags(data) 52 self.tags = list(common.dict2iter('tag', data))
53 self.content = data.get('content') 53 self.content = data.get('content')
54 self.content_rich = None 54 self.content_rich = None
55 self.content_xhtml = data.get('content_xhtml') 55 self.content_xhtml = data.get('content_xhtml')
56 self.author = data['author'] 56 self.author = data['author']
57 try: 57 try:
259 name = '{}{}'.format(prefix, suffix) 259 name = '{}{}'.format(prefix, suffix)
260 value = getattr(self.item, name) 260 value = getattr(self.item, name)
261 if value is not None: 261 if value is not None:
262 mb_data[name] = value 262 mb_data[name] = value
263 263
264 mb_data.update(tags2mbdata(self.item.tags)) 264 common.iter2dict('tag', self.item.tags, mb_data)
265 265
266 if self.blog.new_message_target not in (C.PUBLIC, C.GROUP): 266 if self.blog.new_message_target not in (C.PUBLIC, C.GROUP):
267 raise NotImplementedError 267 raise NotImplementedError
268 268
269 if self.level == 0: 269 if self.level == 0:
460 else: 460 else:
461 raise ValueError("type_ should be ENTRY or COMMENT") 461 raise ValueError("type_ should be ENTRY or COMMENT")
462 if COMMENTS_CLS is None: 462 if COMMENTS_CLS is None:
463 COMMENTS_CLS = ENTRY_CLS 463 COMMENTS_CLS = ENTRY_CLS
464 464
465
466 def mbdata2tags(mb_data):
467 """Parse the tags in microblog data.
468
469 @param mb_data (dict): microblog data as return by bridge methods
470 @return list[unicode]
471 """
472 return [tag for key, tag in mb_data.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
473
474 def tags2mbdata(tags): 465 def tags2mbdata(tags):
475 """Build from the tags a dict using the microblog data format. 466 """Build from the tags a dict using the microblog data format.
476 467
477 @param tags (list[unicode]): list of tags 468 @param tags (list[unicode]): list of tags
478 @return dict 469 @return dict