diff 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
line wrap: on
line diff
--- a/src/plugins/plugin_exp_events.py	Fri Jun 30 01:08:13 2017 +0200
+++ b/src/plugins/plugin_exp_events.py	Sun Jul 02 19:47:25 2017 +0200
@@ -74,6 +74,10 @@
                               in_sign='ssa{ss}s', out_sign='',
                               method=self._eventInviteeSet,
                               async=True)
+        host.bridge.addMethod("eventInviteesList", ".plugin",
+                              in_sign='sss', out_sign='a{sa{ss}}',
+                              method=self._eventInviteesList,
+                              async=True),
         host.bridge.addMethod("eventInvite", ".plugin", in_sign='ssssassssssss', out_sign='',
                               method=self._invite,
                               async=True)
@@ -320,6 +324,42 @@
         item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt)
         return self._p.publish(client, service, node, items=[item_elt])
 
+    def _eventInviteesList(self, service, node, profile_key):
+        service = jid.JID(service) if service else None
+        node = node if node else NS_EVENT
+        client = self.host.getClient(profile_key)
+        return self.eventInviteesList(client, service, node)
+
+    @defer.inlineCallbacks
+    def eventInviteesList(self, client, service, node):
+        """Retrieve attendance from event node
+
+        @param service(unicode, None): PubSub service
+        @param node(unicode): PubSub node of the event
+        @return (dict): a dict with current attendance status,
+            an empty dict is returned if nothing has been answered yed
+        """
+        items, metadata = yield self._p.getItems(service, node, profile_key=client.profile)
+        invitees = {}
+        for item in items:
+            try:
+                event_elt = next(item.elements(NS_EVENT, u'invitee'))
+            except IndexError:
+                # no item found, event data are not set yet
+                log.warning(_(u"no data found for {item_id} (service: {service}, node: {node})".format(
+                    item_id=item['id'],
+                    service=service,
+                    node=node
+                    )))
+            data = {}
+            for key in (u'attend', u'guests'):
+                try:
+                    data[key] = event_elt[key]
+                except KeyError:
+                    continue
+            invitees[item['id']] = data
+        defer.returnValue(invitees)
+
     def _invite(self, service, node, id_=NS_EVENT, email=u'', emails_extra=None, name=u'', host_name=u'', language=u'', url_template=u'',
         message_subject=u'', message_body=u'', profile_key=C.PROF_KEY_NONE):
         client = self.host.getClient(profile_key)