comparison src/plugins/plugin_exp_events.py @ 2294:78048f002a3c

plugin events: added eventInviteesList method to get all R.S.V.P. at once.
author Goffi <goffi@goffi.org>
date Sun, 02 Jul 2017 19:47:25 +0200
parents c05000d00dbb
children 37887b5acb25
comparison
equal deleted inserted replaced
2293:cbc989508474 2294:78048f002a3c
72 async=True) 72 async=True)
73 host.bridge.addMethod("eventInviteeSet", ".plugin", 73 host.bridge.addMethod("eventInviteeSet", ".plugin",
74 in_sign='ssa{ss}s', out_sign='', 74 in_sign='ssa{ss}s', out_sign='',
75 method=self._eventInviteeSet, 75 method=self._eventInviteeSet,
76 async=True) 76 async=True)
77 host.bridge.addMethod("eventInviteesList", ".plugin",
78 in_sign='sss', out_sign='a{sa{ss}}',
79 method=self._eventInviteesList,
80 async=True),
77 host.bridge.addMethod("eventInvite", ".plugin", in_sign='ssssassssssss', out_sign='', 81 host.bridge.addMethod("eventInvite", ".plugin", in_sign='ssssassssssss', out_sign='',
78 method=self._invite, 82 method=self._invite,
79 async=True) 83 async=True)
80 84
81 def _eventGet(self, service, node, id_=u'', profile_key=C.PROF_KEY_NONE): 85 def _eventGet(self, service, node, id_=u'', profile_key=C.PROF_KEY_NONE):
317 event_elt[key] = data.pop(key) 321 event_elt[key] = data.pop(key)
318 except KeyError: 322 except KeyError:
319 pass 323 pass
320 item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt) 324 item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt)
321 return self._p.publish(client, service, node, items=[item_elt]) 325 return self._p.publish(client, service, node, items=[item_elt])
326
327 def _eventInviteesList(self, service, node, profile_key):
328 service = jid.JID(service) if service else None
329 node = node if node else NS_EVENT
330 client = self.host.getClient(profile_key)
331 return self.eventInviteesList(client, service, node)
332
333 @defer.inlineCallbacks
334 def eventInviteesList(self, client, service, node):
335 """Retrieve attendance from event node
336
337 @param service(unicode, None): PubSub service
338 @param node(unicode): PubSub node of the event
339 @return (dict): a dict with current attendance status,
340 an empty dict is returned if nothing has been answered yed
341 """
342 items, metadata = yield self._p.getItems(service, node, profile_key=client.profile)
343 invitees = {}
344 for item in items:
345 try:
346 event_elt = next(item.elements(NS_EVENT, u'invitee'))
347 except IndexError:
348 # no item found, event data are not set yet
349 log.warning(_(u"no data found for {item_id} (service: {service}, node: {node})".format(
350 item_id=item['id'],
351 service=service,
352 node=node
353 )))
354 data = {}
355 for key in (u'attend', u'guests'):
356 try:
357 data[key] = event_elt[key]
358 except KeyError:
359 continue
360 invitees[item['id']] = data
361 defer.returnValue(invitees)
322 362
323 def _invite(self, service, node, id_=NS_EVENT, email=u'', emails_extra=None, name=u'', host_name=u'', language=u'', url_template=u'', 363 def _invite(self, service, node, id_=NS_EVENT, email=u'', emails_extra=None, name=u'', host_name=u'', language=u'', url_template=u'',
324 message_subject=u'', message_body=u'', profile_key=C.PROF_KEY_NONE): 364 message_subject=u'', message_body=u'', profile_key=C.PROF_KEY_NONE):
325 client = self.host.getClient(profile_key) 365 client = self.host.getClient(profile_key)
326 kwargs = {u'profile': client.profile, 366 kwargs = {u'profile': client.profile,