Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_lists.py @ 3464:54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Feb 2021 15:53:20 +0100 |
parents | 483bcfeb11c9 |
children | c063cbb2ad6e |
comparison
equal
deleted
inserted
replaced
3463:483bcfeb11c9 | 3464:54b9cdbeb335 |
---|---|
253 in_sign="sss", | 253 in_sign="sss", |
254 out_sign="s", | 254 out_sign="s", |
255 method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema( | 255 method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema( |
256 service, nodeIdentifier, default_node=self.namespace, | 256 service, nodeIdentifier, default_node=self.namespace, |
257 profile_key=profile_key), | 257 profile_key=profile_key), |
258 async_=True, | |
259 ) | |
260 host.bridge.addMethod( | |
261 "listsList", | |
262 ".plugin", | |
263 in_sign="sss", | |
264 out_sign="s", | |
265 method=self._listsList, | |
258 async_=True, | 266 async_=True, |
259 ) | 267 ) |
260 host.bridge.addMethod( | 268 host.bridge.addMethod( |
261 "listTemplatesNamesGet", | 269 "listTemplatesNamesGet", |
262 ".plugin", | 270 ".plugin", |
364 ) | 372 ) |
365 | 373 |
366 return await self._s.set( | 374 return await self._s.set( |
367 client, service, node, values, schema, item_id, extra, deserialise, form_ns | 375 client, service, node, values, schema, item_id, extra, deserialise, form_ns |
368 ) | 376 ) |
377 | |
378 def _listsList(self, service, node, profile): | |
379 service = jid.JID(service) if service else None | |
380 node = node or None | |
381 client = self.host.getClient(profile) | |
382 d = defer.ensureDeferred(self.listsList(client, service, node)) | |
383 d.addCallback(data_format.serialise) | |
384 return d | |
385 | |
386 async def listsList( | |
387 self, client, service: Optional[jid.JID], node: Optional[str]=None | |
388 ) -> List[dict]: | |
389 """Retrieve list of pubsub lists registered in personal interests | |
390 | |
391 @return list: list of lists metadata | |
392 """ | |
393 items, metadata = await self.host.plugins['LIST_INTEREST'].listInterests( | |
394 client, service, node, namespace=APP_NS_TICKETS) | |
395 lists = [] | |
396 for item in items: | |
397 interest_elt = item.interest | |
398 if interest_elt is None: | |
399 log.warning(f"invalid interest for {client.profile}: {item.toXml}") | |
400 continue | |
401 if interest_elt.getAttribute("namespace") != APP_NS_TICKETS: | |
402 continue | |
403 pubsub_elt = interest_elt.pubsub | |
404 list_data = { | |
405 "id": item["id"], | |
406 "name": interest_elt["name"], | |
407 "service": pubsub_elt["service"], | |
408 "node": pubsub_elt["node"], | |
409 "creator": C.bool(pubsub_elt.getAttribute("creator", C.BOOL_FALSE)), | |
410 } | |
411 try: | |
412 list_elt = next(pubsub_elt.elements(APP_NS_TICKETS, "list")) | |
413 except StopIteration: | |
414 pass | |
415 else: | |
416 list_type = list_data["type"] = list_elt["type"] | |
417 if list_type in TEMPLATES: | |
418 list_data["icon_name"] = TEMPLATES[list_type]["icon"] | |
419 lists.append(list_data) | |
420 | |
421 return lists | |
369 | 422 |
370 def _getTemplatesNames(self, language, profile): | 423 def _getTemplatesNames(self, language, profile): |
371 client = self.host.getClient(profile) | 424 client = self.host.getClient(profile) |
372 return data_format.serialise(self.getTemplatesNames(client, language)) | 425 return data_format.serialise(self.getTemplatesNames(client, language)) |
373 | 426 |