quick_frontend (quick_blog): retrieve and set the tags from/to microblog data
This commit is contained in:
parent
435a3fcb90
commit
323006d216
1 changed files with 30 additions and 5 deletions
|
|
@ -41,13 +41,14 @@ class Item(object):
|
|||
|
||||
def __init__(self, data):
|
||||
"""
|
||||
@param data(dict, None): microblog data as return by bridge methods
|
||||
if data is None, set a default values
|
||||
@param data(dict): microblog data as return by bridge methods
|
||||
if data values are not defined, set default values
|
||||
"""
|
||||
self.id = data['id']
|
||||
self.title = data.get('title')
|
||||
self.title_rich = None
|
||||
self.title_xhtml = data.get('title_xhtml')
|
||||
self.tags = mbdata2tags(data)
|
||||
self.content = data.get('content')
|
||||
self.content_rich = None
|
||||
self.content_xhtml = data.get('content_xhtml')
|
||||
|
|
@ -197,7 +198,7 @@ class Entry(EntriesManager):
|
|||
|
||||
used during init (it's a set and not a reset then)
|
||||
or later (e.g. message sent, or cancellation of an edition
|
||||
@param idem_data(dict): data as in __init__
|
||||
@param idem_data(dict, None): data as in __init__
|
||||
"""
|
||||
if item_data is None:
|
||||
self.new = True
|
||||
|
|
@ -213,7 +214,7 @@ class Entry(EntriesManager):
|
|||
self.author_jid = self.service
|
||||
self.mode = C.ENTRY_MODE_TEXT if self.item.content_xhtml is None else C.ENTRY_MODE_XHTML
|
||||
|
||||
def refresh(semf):
|
||||
def refresh(self):
|
||||
"""Refresh the display when data have been modified"""
|
||||
pass
|
||||
|
||||
|
|
@ -243,7 +244,7 @@ class Entry(EntriesManager):
|
|||
def send(self):
|
||||
"""Send entry according to parent QuickBlog configuration and current level"""
|
||||
|
||||
# keys other to keep other than content* and title*
|
||||
# keys to keep other than content*, title* and tag*
|
||||
keys_to_keep = ('id', 'comments', 'author', 'author_jid', 'published')
|
||||
|
||||
mb_data = {}
|
||||
|
|
@ -259,6 +260,8 @@ class Entry(EntriesManager):
|
|||
if value is not None:
|
||||
mb_data[name] = value
|
||||
|
||||
mb_data.update(tags2mbdata(self.item.tags))
|
||||
|
||||
if self.level == 0:
|
||||
if self.blog.new_message_target == C.PUBLIC:
|
||||
if self.new:
|
||||
|
|
@ -451,3 +454,25 @@ def registerClass(type_, cls):
|
|||
raise ValueError("type_ should be ENTRY or COMMENT")
|
||||
if COMMENTS_CLS is None:
|
||||
COMMENTS_CLS = ENTRY_CLS
|
||||
|
||||
|
||||
def mbdata2tags(mb_data):
|
||||
"""Parse the tags in microblog data.
|
||||
|
||||
@param mb_data (dict): microblog data as return by bridge methods
|
||||
@return list[unicode]
|
||||
"""
|
||||
return [tag for key, tag in mb_data.iteritems() if (key == "tag" or key.startswith("tag#")) and tag]
|
||||
|
||||
def tags2mbdata(tags):
|
||||
"""Build from the tags a dict using the microblog data format.
|
||||
|
||||
@param tags (list[unicode]): list of tags
|
||||
@return dict
|
||||
"""
|
||||
data = {}
|
||||
count = 0
|
||||
for tag in tags:
|
||||
data[('tag#%i' % count) if count else 'tag'] = tag
|
||||
count += 1
|
||||
return data
|
||||
|
|
|
|||
Loading…
Reference in a new issue