annotate src/plugins/plugin_misc_tickets.py @ 2443:81a45e7886c9

core: added a mechanism to associate short names to namespaces: - new internal registerNamespace can be used by a plugin to associate a short name to a namespace - new NamespacesGet bridge method retrieve those associations
author Goffi <goffi@goffi.org>
date Sun, 19 Nov 2017 16:46:07 +0100
parents 7fa9456032e7
children 9e692f09f367
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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: [],
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
38 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"],
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
2443
81a45e7886c9 core: added a mechanism to associate short names to namespaces:
Goffi <goffi@goffi.org>
parents: 2434
diff changeset
50 host.registerNamespace('tickets', NS_TICKETS)
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self._p = self.host.plugins["XEP-0060"]
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self._s = self.host.plugins["PUBSUB_SCHEMA"]
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
53 self._m = self.host.plugins["XEP-0277"]
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
54 self._i = self.host.plugins["IDENTITY"]
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 host.bridge.addMethod("ticketsGet", ".plugin",
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 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
57 method=self._get,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 async=True
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 )
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
60 host.bridge.addMethod("ticketsSet", ".plugin",
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
61 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
62 method=self._set,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
63 async=True)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
64 host.bridge.addMethod("ticketsSchemaGet", ".plugin",
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
65 in_sign='sss', out_sign='s',
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
66 method=self._getSchema,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
67 async=True)
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
69 def _reporterFilter(self, client, form_xmlui, widget_type, args, kwargs):
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
70 if not args[0]:
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
71 # if reporter is not filled, we use user part of publisher
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
72 # (if we have it)
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
73 try:
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
74 publisher = jid.JID(form_xmlui.named_widgets['publisher'].value)
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
75 except (KeyError, RuntimeError):
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
76 pass
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
77 else:
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
78 args[0] = publisher.user.capitalize()
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
79 return widget_type, args, kwargs
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
80
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
81 def _labelsFilter(self, form_xmlui, widget_type, args, kwargs):
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 if widget_type != u'textbox':
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 return widget_type, args, kwargs
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 widget_type = u'list'
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 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
86 kwargs = {'options': options,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 'name': kwargs.get('name'),
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 'styles': (u'noselect', u'extensible', u'reducible')}
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 return widget_type, args, kwargs
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
91 def _dateFilter(self, form_xmlui, widget_type, args, kwargs):
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if widget_type != u'string':
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 return widget_type, args, kwargs
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 # we convert XMPP date to timestamp
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 args[0] = unicode(utils.date_parse(args[0]))
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 return widget_type, args, kwargs
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 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
99 client = self.host.getClient(profile_key)
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 service = jid.JID(service) if service else None
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 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
102 extra = self._p.parseExtra(extra_dict)
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 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
104 d.addCallback(self._p.serItemsData)
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 return d
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 @defer.inlineCallbacks
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 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
109 """Retrieve tickets and convert them to XMLUI
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 @param node(unicode, None): PubSub node to use
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if None, default ticket node will be used
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 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
114 @return (list[unicode]): XMLUI of the tickets
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 """
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if not node:
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 node = NS_TICKETS
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
118 filters = {u'reporter': lambda *args: self._reporterFilter(client, *args),
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
119 u'labels': self._labelsFilter,
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 u'created': self._dateFilter,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 u'updated': self._dateFilter,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 }
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 tickets, metadata = yield self._s.getDataFormItems(
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 client,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 NS_TICKETS,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 service,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 node,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 max_items = max_items,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 item_ids = item_ids,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 sub_id = sub_id,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 rsm_request = rsm_request,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 extra = extra,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 filters = filters,
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 )
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 defer.returnValue((tickets, metadata))
2420
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 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
139 client = self.host.getClient(profile_key)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
140 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
141 if schema:
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
142 schema = generic.parseXml(schema.encode('utf-8'))
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
143 else:
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
144 schema = None
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
145 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
146 d.addCallback(lambda ret: ret or u'')
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
147 return d
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
148
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
149 @defer.inlineCallbacks
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
150 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
151 """Publish a tickets
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
152
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
153 @param node(unicode, None): Pubsub node to use
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
154 None to use default tickets node
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
155 @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
156 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
157 '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
158 - '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
159 - 'updated' is set everytime
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
160 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
161 @return (unicode): id of the created item
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
162 """
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
163 if not node:
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
164 node = NS_TICKETS
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
165 now = utils.xmpp_date()
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
166 if not item_id:
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
167 values['created'] = now
2434
7fa9456032e7 plugin tickets: specify parent service when using getCommentsService + fill reporter_jid is missing (will be discarded later if not in the schema)
Goffi <goffi@goffi.org>
parents: 2430
diff changeset
168 comments_service = yield self._m.getCommentsService(client, service)
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
169
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
170 # 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
171 # (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
172 # a nicer id if serial ids is activated)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
173 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
174 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
175 self._p.OPT_PERSIST_ITEMS: 1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
176 self._p.OPT_MAX_ITEMS: -1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
177 self._p.OPT_DELIVER_PAYLOADS: 1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
178 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
179 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
180 }
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
181 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
182 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
183
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
184 values['updated'] = now
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
185 if not values.get('reporter'):
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
186 identity = yield self._i.getIdentity(client, client.jid)
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
187 values['reporter'] = identity['nick']
2434
7fa9456032e7 plugin tickets: specify parent service when using getCommentsService + fill reporter_jid is missing (will be discarded later if not in the schema)
Goffi <goffi@goffi.org>
parents: 2430
diff changeset
188 if not values.get('reporter_jid'):
7fa9456032e7 plugin tickets: specify parent service when using getCommentsService + fill reporter_jid is missing (will be discarded later if not in the schema)
Goffi <goffi@goffi.org>
parents: 2430
diff changeset
189 values['reporter_jid'] = client.jid.full()
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
190 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
191 defer.returnValue(item_id)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
192
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
193 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
194 if not node:
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
195 node = NS_TICKETS
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
196 return self._s._getUISchema(service, node, profile_key)