comparison sat/tools/common/data_objects.py @ 2807:0b7ce5daee9b

plugin XEP-0277: blog items data are now entirely serialised before going to bridge: So far, and for historical reasons, blog items data where serialised using a unicode: unicode dict, which was causing trouble for many types of values (timestamps, booleans, lists). This patch changes it by serialising the whole items before going to bridge, and deserialising it when going back. This way, complex data can be used easily in items. This impact psEvent and serItemsData* methods which are renamed transItemsData* because there are not always serialising anymore (a new argument "serialise" allows to specify it). When editing a blog post in jp, metadata are now more easy to manipulate, specially lists like tags.
author Goffi <goffi@goffi.org>
date Sat, 23 Feb 2019 18:59:00 +0100
parents 003b8b4b56a7
children 8dbef2d190eb
comparison
equal deleted inserted replaced
2806:2400cad2dace 2807:0b7ce5daee9b
71 return data 71 return data
72 72
73 73
74 class BlogItem(object): 74 class BlogItem(object):
75 def __init__(self, mb_data, parent): 75 def __init__(self, mb_data, parent):
76 self.mb_data = mb_data 76 self.mb_data = data_format.deserialise(mb_data)
77 self.parent = parent 77 self.parent = parent
78 self._tags = None
79 self._groups = None
80 self._comments = None 78 self._comments = None
81 self._comments_items_list = None 79 self._comments_items_list = None
82 80
83 @property 81 @property
84 def id(self): 82 def id(self):
124 def author_email(self): 122 def author_email(self):
125 return self.mb_data.get(u"author_email") 123 return self.mb_data.get(u"author_email")
126 124
127 @property 125 @property
128 def tags(self): 126 def tags(self):
129 if self._tags is None: 127 return self.mb_data.get(u'tags', [])
130 self._tags = list(data_format.dict2iter("tag", self.mb_data))
131 return self._tags
132 128
133 @property 129 @property
134 def groups(self): 130 def groups(self):
135 if self._groups is None: 131 return self.mb_data.get(u'groups', [])
136 self._groups = list(data_format.dict2iter("group", self.mb_data))
137 return self._groups
138 132
139 @property 133 @property
140 def title(self): 134 def title(self):
141 return self.mb_data.get(u"title") 135 return self.mb_data.get(u"title")
142 136