annotate src/plugins/plugin_misc_tickets.py @ 2437:91bbad17fd53

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