Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_tickets.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | src/plugins/plugin_misc_tickets.py@0062d3e79d12 |
children | 5d4ac5415b40 |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT plugin for Pubsub Schemas | |
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
21 from sat.core.constants import Const as C | |
22 from twisted.internet import defer | |
23 from sat.tools.common import uri | |
24 from sat.tools import utils | |
25 import shortuuid | |
26 from sat.core.log import getLogger | |
27 log = getLogger(__name__) | |
28 | |
29 NS_TICKETS = 'org.salut-a-toi.tickets:0' | |
30 | |
31 PLUGIN_INFO = { | |
32 C.PI_NAME: _("Tickets management"), | |
33 C.PI_IMPORT_NAME: "TICKETS", | |
34 C.PI_TYPE: "EXP", | |
35 C.PI_PROTOCOLS: [], | |
36 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"], | |
37 C.PI_MAIN: "Tickets", | |
38 C.PI_HANDLER: "no", | |
39 C.PI_DESCRIPTION: _("""Tickets management plugin""") | |
40 } | |
41 | |
42 | |
43 class Tickets(object): | |
44 | |
45 def __init__(self, host): | |
46 log.info(_(u"Tickets plugin initialization")) | |
47 self.host = host | |
48 host.registerNamespace('tickets', NS_TICKETS) | |
49 self._p = self.host.plugins["XEP-0060"] | |
50 self._s = self.host.plugins["PUBSUB_SCHEMA"] | |
51 self._m = self.host.plugins["XEP-0277"] | |
52 host.bridge.addMethod("ticketsGet", ".plugin", | |
53 in_sign='ssiassa{ss}s', out_sign='(asa{ss})', | |
54 method=utils.partial( | |
55 self._s._get, | |
56 default_node=NS_TICKETS, | |
57 form_ns=NS_TICKETS, | |
58 filters = {u'author': self._s.valueOrPublisherFilter, | |
59 u'labels': self._s.textbox2ListFilter, | |
60 u'created': self._s.dateFilter, | |
61 u'updated': self._s.dateFilter, | |
62 }), | |
63 | |
64 async=True | |
65 ) | |
66 host.bridge.addMethod("ticketSet", ".plugin", | |
67 in_sign='ssa{sas}ssa{ss}s', out_sign='s', | |
68 method=self._set, | |
69 async=True) | |
70 host.bridge.addMethod("ticketsSchemaGet", ".plugin", | |
71 in_sign='sss', out_sign='s', | |
72 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS), | |
73 async=True) | |
74 | |
75 def _set(self, service, node, values, schema=None, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE): | |
76 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(service, node, schema, item_id, extra, profile_key) | |
77 d = self.set(client, service, node, values, schema, item_id, extra, deserialise=True) | |
78 d.addCallback(lambda ret: ret or u'') | |
79 return d | |
80 | |
81 @defer.inlineCallbacks | |
82 def set(self, client, service, node, values, schema=None, item_id=None, extra=None, deserialise=False, form_ns=NS_TICKETS): | |
83 """Publish a tickets | |
84 | |
85 @param node(unicode, None): Pubsub node to use | |
86 None to use default tickets node | |
87 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket | |
88 if value is not iterable, it will be put in a list | |
89 'created' and 'updated' will be forced to current time: | |
90 - 'created' is set if item_id is None, i.e. if it's a new ticket | |
91 - 'updated' is set everytime | |
92 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys: | |
93 - update(bool): if True, get previous item data to merge with current one | |
94 if True, item_id must be None | |
95 other arguments are same as for [self._s.sendDataFormItem] | |
96 @return (unicode): id of the created item | |
97 """ | |
98 if not node: | |
99 node = NS_TICKETS | |
100 if not item_id: | |
101 comments_service = yield self._m.getCommentsService(client, service) | |
102 | |
103 # we need to use uuid for comments node, because we don't know item id in advance | |
104 # (we don't want to set it ourselves to let the server choose, so we can have | |
105 # a nicer id if serial ids is activated) | |
106 comments_node = self._m.getCommentsNode(node + u'_' + unicode(shortuuid.uuid())) | |
107 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, | |
108 self._p.OPT_PERSIST_ITEMS: 1, | |
109 self._p.OPT_MAX_ITEMS: -1, | |
110 self._p.OPT_DELIVER_PAYLOADS: 1, | |
111 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, | |
112 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, | |
113 } | |
114 yield self._p.createNode(client, comments_service, comments_node, options) | |
115 values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node) | |
116 item_id = yield self._s.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns) | |
117 defer.returnValue(item_id) |