comparison src/plugins/plugin_xep_0277.py @ 2415:59100136f07a

plugin XEP-0277: minor id generation change
author Goffi <goffi@goffi.org>
date Sat, 04 Nov 2017 22:10:01 +0100
parents 8b37a62336c3
children 014feb75092d
comparison
equal deleted inserted replaced
2414:8b37a62336c3 2415:59100136f07a
347 def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE): 347 def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE):
348 """Convert a data dict to en entry usable to create an item 348 """Convert a data dict to en entry usable to create an item
349 349
350 @param data: data dict as given by bridge method. 350 @param data: data dict as given by bridge method.
351 @param item_id(unicode, None): id of the item to use 351 @param item_id(unicode, None): id of the item to use
352 if None the id will be generated randomly
353 @return: deferred which fire domish.Element 352 @return: deferred which fire domish.Element
354 """ 353 """
355 if item_id is None:
356 item_id = unicode(uuid.uuid4())
357 client = self.host.getClient(profile) 354 client = self.host.getClient(profile)
358 entry_elt = domish.Element((NS_ATOM, 'entry')) 355 entry_elt = domish.Element((NS_ATOM, 'entry'))
359 356
360 ## language ## 357 ## language ##
361 if u'language' in data: 358 if u'language' in data:
442 for tag in data_format.dict2iter("tag", data): 439 for tag in data_format.dict2iter("tag", data):
443 category_elt = entry_elt.addElement("category") 440 category_elt = entry_elt.addElement("category")
444 category_elt['term'] = tag 441 category_elt['term'] = tag
445 442
446 ## id ## 443 ## id ##
447 entry_id = data.get('id', item_id) # FIXME: use a proper id (see XEP-0277 §7.1) 444 entry_id = data.get('id', item_id or unicode(uuid.uuid4())) # FIXME: use a proper id (see XEP-0277 §7.1)
448 entry_elt.addElement('id', content=entry_id) # 445 entry_elt.addElement('id', content=entry_id) #
449 446
450 ## comments ## 447 ## comments ##
451 if 'comments' in data: 448 if 'comments' in data:
452 link_elt = entry_elt.addElement('link') 449 link_elt = entry_elt.addElement('link')