comparison sat/plugins/plugin_misc_tickets.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 5d4ac5415b40
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
22 from twisted.internet import defer 22 from twisted.internet import defer
23 from sat.tools.common import uri 23 from sat.tools.common import uri
24 from sat.tools import utils 24 from sat.tools import utils
25 import shortuuid 25 import shortuuid
26 from sat.core.log import getLogger 26 from sat.core.log import getLogger
27
27 log = getLogger(__name__) 28 log = getLogger(__name__)
28 29
29 NS_TICKETS = 'org.salut-a-toi.tickets:0' 30 NS_TICKETS = "org.salut-a-toi.tickets:0"
30 31
31 PLUGIN_INFO = { 32 PLUGIN_INFO = {
32 C.PI_NAME: _("Tickets management"), 33 C.PI_NAME: _("Tickets management"),
33 C.PI_IMPORT_NAME: "TICKETS", 34 C.PI_IMPORT_NAME: "TICKETS",
34 C.PI_TYPE: "EXP", 35 C.PI_TYPE: "EXP",
35 C.PI_PROTOCOLS: [], 36 C.PI_PROTOCOLS: [],
36 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"], 37 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"],
37 C.PI_MAIN: "Tickets", 38 C.PI_MAIN: "Tickets",
38 C.PI_HANDLER: "no", 39 C.PI_HANDLER: "no",
39 C.PI_DESCRIPTION: _("""Tickets management plugin""") 40 C.PI_DESCRIPTION: _("""Tickets management plugin"""),
40 } 41 }
41 42
42 43
43 class Tickets(object): 44 class Tickets(object):
44
45 def __init__(self, host): 45 def __init__(self, host):
46 log.info(_(u"Tickets plugin initialization")) 46 log.info(_(u"Tickets plugin initialization"))
47 self.host = host 47 self.host = host
48 host.registerNamespace('tickets', NS_TICKETS) 48 host.registerNamespace("tickets", NS_TICKETS)
49 self._p = self.host.plugins["XEP-0060"] 49 self._p = self.host.plugins["XEP-0060"]
50 self._s = self.host.plugins["PUBSUB_SCHEMA"] 50 self._s = self.host.plugins["PUBSUB_SCHEMA"]
51 self._m = self.host.plugins["XEP-0277"] 51 self._m = self.host.plugins["XEP-0277"]
52 host.bridge.addMethod("ticketsGet", ".plugin", 52 host.bridge.addMethod(
53 in_sign='ssiassa{ss}s', out_sign='(asa{ss})', 53 "ticketsGet",
54 method=utils.partial( 54 ".plugin",
55 self._s._get, 55 in_sign="ssiassa{ss}s",
56 default_node=NS_TICKETS, 56 out_sign="(asa{ss})",
57 form_ns=NS_TICKETS, 57 method=utils.partial(
58 filters = {u'author': self._s.valueOrPublisherFilter, 58 self._s._get,
59 u'created': self._s.dateFilter, 59 default_node=NS_TICKETS,
60 u'updated': self._s.dateFilter, 60 form_ns=NS_TICKETS,
61 }), 61 filters={
62 u"author": self._s.valueOrPublisherFilter,
63 u"created": self._s.dateFilter,
64 u"updated": self._s.dateFilter,
65 },
66 ),
67 async=True,
68 )
69 host.bridge.addMethod(
70 "ticketSet",
71 ".plugin",
72 in_sign="ssa{sas}ssa{ss}s",
73 out_sign="s",
74 method=self._set,
75 async=True,
76 )
77 host.bridge.addMethod(
78 "ticketsSchemaGet",
79 ".plugin",
80 in_sign="sss",
81 out_sign="s",
82 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS),
83 async=True,
84 )
62 85
63 async=True 86 def _set(
64 ) 87 self,
65 host.bridge.addMethod("ticketSet", ".plugin", 88 service,
66 in_sign='ssa{sas}ssa{ss}s', out_sign='s', 89 node,
67 method=self._set, 90 values,
68 async=True) 91 schema=None,
69 host.bridge.addMethod("ticketsSchemaGet", ".plugin", 92 item_id=None,
70 in_sign='sss', out_sign='s', 93 extra=None,
71 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS), 94 profile_key=C.PROF_KEY_NONE,
72 async=True) 95 ):
73 96 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
74 def _set(self, service, node, values, schema=None, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE): 97 service, node, schema, item_id, extra, profile_key
75 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(service, node, schema, item_id, extra, profile_key) 98 )
76 d = self.set(client, service, node, values, schema, item_id, extra, deserialise=True) 99 d = self.set(
77 d.addCallback(lambda ret: ret or u'') 100 client, service, node, values, schema, item_id, extra, deserialise=True
101 )
102 d.addCallback(lambda ret: ret or u"")
78 return d 103 return d
79 104
80 @defer.inlineCallbacks 105 @defer.inlineCallbacks
81 def set(self, client, service, node, values, schema=None, item_id=None, extra=None, deserialise=False, form_ns=NS_TICKETS): 106 def set(
107 self,
108 client,
109 service,
110 node,
111 values,
112 schema=None,
113 item_id=None,
114 extra=None,
115 deserialise=False,
116 form_ns=NS_TICKETS,
117 ):
82 """Publish a tickets 118 """Publish a tickets
83 119
84 @param node(unicode, None): Pubsub node to use 120 @param node(unicode, None): Pubsub node to use
85 None to use default tickets node 121 None to use default tickets node
86 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket 122 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket
100 comments_service = yield self._m.getCommentsService(client, service) 136 comments_service = yield self._m.getCommentsService(client, service)
101 137
102 # we need to use uuid for comments node, because we don't know item id in advance 138 # we need to use uuid for comments node, because we don't know item id in advance
103 # (we don't want to set it ourselves to let the server choose, so we can have 139 # (we don't want to set it ourselves to let the server choose, so we can have
104 # a nicer id if serial ids is activated) 140 # a nicer id if serial ids is activated)
105 comments_node = self._m.getCommentsNode(node + u'_' + unicode(shortuuid.uuid())) 141 comments_node = self._m.getCommentsNode(
106 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, 142 node + u"_" + unicode(shortuuid.uuid())
107 self._p.OPT_PERSIST_ITEMS: 1, 143 )
108 self._p.OPT_MAX_ITEMS: -1, 144 options = {
109 self._p.OPT_DELIVER_PAYLOADS: 1, 145 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
110 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, 146 self._p.OPT_PERSIST_ITEMS: 1,
111 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, 147 self._p.OPT_MAX_ITEMS: -1,
112 } 148 self._p.OPT_DELIVER_PAYLOADS: 1,
149 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
150 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
151 }
113 yield self._p.createNode(client, comments_service, comments_node, options) 152 yield self._p.createNode(client, comments_service, comments_node, options)
114 values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node) 153 values["comments_uri"] = uri.buildXMPPUri(
115 item_id = yield self._s.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns) 154 u"pubsub",
155 subtype="microblog",
156 path=comments_service.full(),
157 node=comments_node,
158 )
159 item_id = yield self._s.set(
160 client, service, node, values, schema, item_id, extra, deserialise, form_ns
161 )
116 defer.returnValue(item_id) 162 defer.returnValue(item_id)