Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_pubsub_schema.py @ 3309:71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
those methods now return data serialised with `data_format.serialise`
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Jul 2020 09:07:26 +0200 |
parents | abca25af06d7 |
children |
comparison
equal
deleted
inserted
replaced
3308:384283adcce1 | 3309:71761e9fb984 |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | |
3 | 2 |
4 # SAT plugin for Pubsub Schemas | 3 # SAT plugin for Pubsub Schemas |
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) | 4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
6 | 5 |
7 # This program is free software: you can redistribute it and/or modify | 6 # This program is free software: you can redistribute it and/or modify |
533 default_node=default_node, | 532 default_node=default_node, |
534 form_ns=form_ns, | 533 form_ns=form_ns, |
535 filters=filters, | 534 filters=filters, |
536 ) | 535 ) |
537 d.addCallback(self._p.transItemsData) | 536 d.addCallback(self._p.transItemsData) |
537 d.addCallback(lambda data: data_format.serialise(data)) | |
538 return d | 538 return d |
539 | 539 |
540 def prepareBridgeSet(self, service, node, schema, item_id, extra, profile_key): | 540 def prepareBridgeSet(self, service, node, schema, item_id, extra, profile_key): |
541 """Parse arguments received from bridge *Set methods and return higher level data | 541 """Parse arguments received from bridge *Set methods and return higher level data |
542 | 542 |
599 when adding *Set methods | 599 when adding *Set methods |
600 """ | 600 """ |
601 client, service, node, schema, item_id, extra = self.prepareBridgeSet( | 601 client, service, node, schema, item_id, extra = self.prepareBridgeSet( |
602 service, node, schema, item_id, extra | 602 service, node, schema, item_id, extra |
603 ) | 603 ) |
604 d = self.set( | 604 d = defer.ensureDeferred(self.set( |
605 client, | 605 client, |
606 service, | 606 service, |
607 node, | 607 node, |
608 values, | 608 values, |
609 schema, | 609 schema, |
611 extra, | 611 extra, |
612 deserialise=True, | 612 deserialise=True, |
613 form_ns=form_ns, | 613 form_ns=form_ns, |
614 default_node=default_node, | 614 default_node=default_node, |
615 fill_author=fill_author, | 615 fill_author=fill_author, |
616 ) | 616 )) |
617 d.addCallback(lambda ret: ret or "") | 617 d.addCallback(lambda ret: ret or "") |
618 return d | 618 return d |
619 | 619 |
620 @defer.inlineCallbacks | 620 async def set( |
621 def set(self, client, service, node, values, schema, item_id, extra, deserialise, | 621 self, client, service, node, values, schema, item_id, extra, deserialise, |
622 form_ns, default_node=None, fill_author=True): | 622 form_ns, default_node=None, fill_author=True): |
623 """Set an item in a node with a schema | 623 """Set an item in a node with a schema |
624 | 624 |
625 This method can be used directly by *Set methods added by dependant plugin | 625 This method can be used directly by *Set methods added by dependant plugin |
626 @param values(dict[key(unicode), [iterable[object]|object]]): values of the items | 626 @param values(dict[key(unicode), [iterable[object]|object]]): values of the items |
649 elif extra.get("update", False): | 649 elif extra.get("update", False): |
650 if item_id is None: | 650 if item_id is None: |
651 raise exceptions.DataError( | 651 raise exceptions.DataError( |
652 _('if extra["update"] is set, item_id must be set too') | 652 _('if extra["update"] is set, item_id must be set too') |
653 ) | 653 ) |
654 yield self.copyMissingValues(client, service, node, item_id, form_ns, values) | 654 await self.copyMissingValues(client, service, node, item_id, form_ns, values) |
655 | 655 |
656 values["updated"] = now | 656 values["updated"] = now |
657 if fill_author: | 657 if fill_author: |
658 if not values.get("author"): | 658 if not values.get("author"): |
659 id_data = yield self._i.getIdentity(client, None, ["nicknames"]) | 659 id_data = await self._i.getIdentity(client, None, ["nicknames"]) |
660 values["author"] = id_data['nicknames'][0] | 660 values["author"] = id_data['nicknames'][0] |
661 if not values.get("author_jid"): | 661 if not values.get("author_jid"): |
662 values["author_jid"] = client.jid.full() | 662 values["author_jid"] = client.jid.full() |
663 item_id = yield self.sendDataFormItem( | 663 item_id = await self.sendDataFormItem( |
664 client, service, node, values, schema, item_id, extra, deserialise | 664 client, service, node, values, schema, item_id, extra, deserialise |
665 ) | 665 ) |
666 defer.returnValue(item_id) | 666 return item_id |
667 | 667 |
668 | 668 |
669 @implementer(iwokkel.IDisco) | 669 @implementer(iwokkel.IDisco) |
670 class SchemaHandler(XMPPHandler): | 670 class SchemaHandler(XMPPHandler): |
671 | 671 |