Mercurial > libervia-backend
annotate src/plugins/plugin_misc_tickets.py @ 2427:07478106a10d
plugin identity: fixed jid.userhostJID call + capitalize user when jid is used.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 11 Nov 2017 18:35:28 +0100 |
parents | 03da3ef5fb5b |
children | 3faf18111d61 |
rev | line source |
---|---|
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for Pubsub Schemas |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009-2017 Jérôme Poisson (goffi@goffi.org) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _ |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.protocols.jabber import jid |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.internet import defer |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
24 from wokkel import generic |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.tools import utils |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
26 from sat.tools.common import uri |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from sat.core.log import getLogger |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
28 import shortuuid |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 log = getLogger(__name__) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 NS_TICKETS = 'org.salut-a-toi.tickets:0' |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 PLUGIN_INFO = { |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_NAME: _("Tickets management"), |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 C.PI_IMPORT_NAME: "TICKETS", |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 C.PI_TYPE: "EXP", |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_PROTOCOLS: [], |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
38 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277"], |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_MAIN: "Tickets", |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_HANDLER: "no", |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_DESCRIPTION: _("""Tickets management plugin""") |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 class Tickets(object): |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 def __init__(self, host): |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 log.info(_(u"Tickets plugin initialization")) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 self.host = host |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self._p = self.host.plugins["XEP-0060"] |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 self._s = self.host.plugins["PUBSUB_SCHEMA"] |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
52 self._m = self.host.plugins["XEP-0277"] |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 host.bridge.addMethod("ticketsGet", ".plugin", |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 in_sign='ssiassa{ss}s', out_sign='(asa{ss})', |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 method=self._get, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 async=True |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 ) |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
58 host.bridge.addMethod("ticketsSet", ".plugin", |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
59 in_sign='ssa{sas}ssa{ss}s', out_sign='s', |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
60 method=self._set, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
61 async=True) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
62 host.bridge.addMethod("ticketsSchemaGet", ".plugin", |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
63 in_sign='sss', out_sign='s', |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
64 method=self._getSchema, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
65 async=True) |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def _labelsFilter(self, widget_type, args, kwargs): |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 if widget_type != u'textbox': |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 return widget_type, args, kwargs |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 widget_type = u'list' |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 options = [o for o in args.pop(0).split(u'\n') if o] |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 kwargs = {'options': options, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 'name': kwargs.get('name'), |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 'styles': (u'noselect', u'extensible', u'reducible')} |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 return widget_type, args, kwargs |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 def _dateFilter(self, widget_type, args, kwargs): |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 if widget_type != u'string': |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 return widget_type, args, kwargs |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 # we convert XMPP date to timestamp |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 args[0] = unicode(utils.date_parse(args[0])) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 return widget_type, args, kwargs |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 client = self.host.getClient(profile_key) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 service = jid.JID(service) if service else None |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 max_items = None if max_items == C.NO_LIMIT else max_items |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 extra = self._p.parseExtra(extra_dict) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 d = self.get(client, service, node or None, max_items, item_ids, sub_id or None, extra.rsm_request, extra.extra) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 d.addCallback(self._p.serItemsData) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 return d |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 @defer.inlineCallbacks |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 def get(self, client, service=None, node=None, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None): |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 """Retrieve tickets and convert them to XMLUI |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 @param node(unicode, None): PubSub node to use |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 if None, default ticket node will be used |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 other parameters as the same as for [XEP_0060.getItems] |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 @return (list[unicode]): XMLUI of the tickets |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 """ |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 if not node: |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 node = NS_TICKETS |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 filters = {u'labels': self._labelsFilter, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 u'created': self._dateFilter, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 u'updated': self._dateFilter, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 } |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 tickets, metadata = yield self._s.getDataFormItems( |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 client, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 NS_TICKETS, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 service, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 node, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 max_items = max_items, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 item_ids = item_ids, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 sub_id = sub_id, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 rsm_request = rsm_request, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 extra = extra, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 filters = filters, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 ) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 defer.returnValue((tickets, metadata)) |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
122 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
123 def _set(self, service, node, values, schema=None, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE): |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
124 client = self.host.getClient(profile_key) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
125 service = None if not service else jid.JID(service) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
126 if schema: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
127 schema = generic.parseXml(schema.encode('utf-8')) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
128 else: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
129 schema = None |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
130 d = self.set(client, service, node or None, values, schema, item_id or None, extra, deserialise=True) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
131 d.addCallback(lambda ret: ret or u'') |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
132 return d |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
133 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
134 @defer.inlineCallbacks |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
135 def set(self, client, service, node, values, schema=None, item_id=None, extra=None, deserialise=False): |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
136 """Publish a tickets |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
137 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
138 @param node(unicode, None): Pubsub node to use |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
139 None to use default tickets node |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
140 @param values(dict[key(unicode), [iterable[object], object]]): values of the ticket |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
141 if not iterable, will be put in a list |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
142 'created' and 'updated' will be forced to current time: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
143 - 'created' is set if item_id is None, i.e. if it's a new ticket |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
144 - 'updated' is set everytime |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
145 other arguments are same as for [self._s.sendDataFormItem] |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
146 @return (unicode): id of the created item |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
147 """ |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
148 if not node: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
149 node = NS_TICKETS |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
150 now = utils.xmpp_date() |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
151 if not item_id: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
152 values['created'] = now |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
153 comments_service = self._m.getCommentsService(client) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
154 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
155 # we need to use uuid for comments node, because we don't know item id in advance |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
156 # (we don't want to set it ourselves to let the server choose, so we can have |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
157 # a nicer id if serial ids is activated) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
158 comments_node = self._m.getCommentsNode(node + u'_' + unicode(shortuuid.uuid())) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
159 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
160 self._p.OPT_PERSIST_ITEMS: 1, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
161 self._p.OPT_MAX_ITEMS: -1, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
162 self._p.OPT_DELIVER_PAYLOADS: 1, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
163 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
164 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
165 } |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
166 yield self._p.createNode(client, comments_service, comments_node, options) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
167 values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
168 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
169 values['updated'] = now |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
170 item_id = yield self._s.sendDataFormItem(client, service, node, values, schema, item_id, extra, deserialise) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
171 defer.returnValue(item_id) |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
172 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
173 def _getSchema(self, service, node, profile_key=C.PROF_KEY_NONE): |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
174 if not node: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
175 node = NS_TICKETS |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
176 return self._s._getUISchema(service, node, profile_key) |