comparison src/plugins/plugin_xep_0277.py @ 1664:5d0ff155be1a

plugin XEP-0277: tags are handled through atom categories
author Goffi <goffi@goffi.org>
date Tue, 24 Nov 2015 23:18:32 +0100
parents 96ee986dab3c
children 1895846fc9cb
comparison
equal deleted inserted replaced
1663:47224056ce5c 1664:5d0ff155be1a
26 from twisted.internet import defer 26 from twisted.internet import defer
27 from twisted.python import failure 27 from twisted.python import failure
28 from sat.core import exceptions 28 from sat.core import exceptions
29 from sat.tools import xml_tools 29 from sat.tools import xml_tools
30 from sat.tools import sat_defer 30 from sat.tools import sat_defer
31 from sat.tools import common
31 32
32 # XXX: tmp.pubsub is actually use instead of wokkel version 33 # XXX: tmp.pubsub is actually use instead of wokkel version
33 from wokkel import pubsub 34 from wokkel import pubsub
34 try: 35 try:
35 from feed.date import rfc3339 36 from feed.date import rfc3339
312 except StopIteration: 313 except StopIteration:
313 pass 314 pass
314 else: 315 else:
315 microblog_data['author_email'] = unicode(email_elt) 316 microblog_data['author_email'] = unicode(email_elt)
316 317
318 # categories
319 categories = (category_elt.getAttribute('term','') for category_elt in entry_elt.elements(NS_ATOM, 'category'))
320 common.iter2dict('tag', categories, microblog_data)
321
317 defer.returnValue(microblog_data) 322 defer.returnValue(microblog_data)
318 323
319 @defer.inlineCallbacks 324 @defer.inlineCallbacks
320 def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE): 325 def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE):
321 """Convert a data dict to en entry usable to create an item 326 """Convert a data dict to en entry usable to create an item
396 current_time = time.time() 401 current_time = time.time()
397 entry_elt.addElement('updated', 402 entry_elt.addElement('updated',
398 content=rfc3339.timestamp_from_tf(float(data.get('updated', current_time)))) 403 content=rfc3339.timestamp_from_tf(float(data.get('updated', current_time))))
399 entry_elt.addElement('published', 404 entry_elt.addElement('published',
400 content=rfc3339.timestamp_from_tf(float(data.get('published', current_time)))) 405 content=rfc3339.timestamp_from_tf(float(data.get('published', current_time))))
406
407 ## categories ##
408 for tag in common.dict2iter("tag", data):
409 category_elt = entry_elt.addElement("category")
410 category_elt['term'] = tag
401 411
402 ## id ## 412 ## id ##
403 entry_id = data.get('id', item_id) # FIXME: use a proper id (see XEP-0277 §7.1) 413 entry_id = data.get('id', item_id) # FIXME: use a proper id (see XEP-0277 §7.1)
404 entry_elt.addElement('id', content=entry_id) # 414 entry_elt.addElement('id', content=entry_id) #
405 415