annotate sat/plugins/plugin_misc_lists.py @ 3460:d4a71a1dac88

plugin misc lists: templates: Templates are a way to create lists with pre-filled schemas.
author Goffi <goffi@goffi.org>
date Fri, 19 Feb 2021 15:49:58 +0100
parents 8dc26e5edcd3
children 02a8d227d5bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
2
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
4
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # This program is free software: you can redistribute it and/or modify
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # it under the terms of the GNU Affero General Public License as published by
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # the Free Software Foundation, either version 3 of the License, or
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # (at your option) any later version.
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
9
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # GNU Affero General Public License for more details.
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
14
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # You should have received a copy of the GNU Affero General Public License
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
17
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
18 import shortuuid
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
19 from typing import Tuple
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
20 from twisted.internet import defer
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
21 from twisted.words.xish import domish
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
22 from twisted.words.protocols.jabber import jid
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
23 from wokkel import data_form
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
24 from sat.core.i18n import _, D_
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.constants import Const as C
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.tools.common import uri
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
27 from sat.tools.common import data_format
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from sat.core.log import getLogger
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
29
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log = getLogger(__name__)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
31
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
32 # XXX: this plugin was formely named "tickets", thus the namespace keeps this
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
33 # name
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
34 APP_NS_TICKETS = "org.salut-a-toi.tickets:0"
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
35 NS_TICKETS_TYPE = "org.salut-a-toi.tickets#type:0"
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
36
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
37 PLUGIN_INFO = {
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
38 C.PI_NAME: _("Pubsub Lists"),
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
39 C.PI_IMPORT_NAME: "LISTS",
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_TYPE: "EXP",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_PROTOCOLS: [],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY"],
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
43 C.PI_MAIN: "PubsubLists",
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_HANDLER: "no",
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
45 C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""),
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
46 }
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
47
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
48 TEMPLATES = {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
49 "todo": {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
50 "name": D_("TODO List"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
51 "icon": "check",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
52 "fields": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
53 {"name": "title"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
54 {"name": "author"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
55 {"name": "created"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
56 {"name": "updated"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
57 {"name": "time_limit"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
58 {"name": "labels", "type": "text-multi"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
59 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
60 "name": "status",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
61 "label": D_("status"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
62 "type": "list-single",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
63 "options": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
64 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
65 "label": D_("to do"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
66 "value": "todo"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
67 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
68 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
69 "label": D_("in progress"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
70 "value": "in_progress"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
71 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
72 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
73 "label": D_("done"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
74 "value": "done"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
75 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
76 ],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
77 "value": "todo"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
78 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
79 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
80 "name": "priority",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
81 "label": D_("priority"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
82 "type": "list-single",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
83 "options": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
84 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
85 "label": D_("major"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
86 "value": "major"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
87 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
88 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
89 "label": D_("normal"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
90 "value": "normal"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
91 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
92 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
93 "label": D_("minor"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
94 "value": "minor"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
95 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
96 ],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
97 "value": "normal"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
98 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
99 {"name": "body", "type": "xhtml"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
100 {"name": "comments_uri"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
101 ]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
102 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
103 "shopping": {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
104 "name": D_("Shopping List"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
105 "icon": "basket",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
106 "fields": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
107 {"name": "name", "label": D_("name")},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
108 {"name": "quantity", "label": D_("quantity")},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
109 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
110 "name": "status",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
111 "label": D_("status"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
112 "type": "list-single",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
113 "options": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
114 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
115 "label": D_("to buy"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
116 "value": "to_buy"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
117 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
118 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
119 "label": D_("bought"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
120 "value": "bought"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
121 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
122 ],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
123 "value": "to_buy"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
124 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
125 ]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
126 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
127 "tickets": {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
128 "name": D_("Tickets"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
129 "icon": "clipboard",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
130 "fields": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
131 {"name": "title"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
132 {"name": "author"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
133 {"name": "created"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
134 {"name": "updated"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
135 {"name": "labels", "type": "text-multi"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
136 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
137 "name": "type",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
138 "label": D_("type"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
139 "type": "list-single",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
140 "options": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
141 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
142 "label": D_("bug"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
143 "value": "bug"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
144 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
145 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
146 "label": D_("feature request"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
147 "value": "feature"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
148 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
149 ],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
150 "value": "bug"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
151 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
152 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
153 "name": "status",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
154 "label": D_("status"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
155 "type": "list-single",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
156 "options": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
157 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
158 "label": D_("queued"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
159 "value": "queued"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
160 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
161 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
162 "label": D_("started"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
163 "value": "started"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
164 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
165 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
166 "label": D_("review"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
167 "value": "review"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
168 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
169 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
170 "label": D_("closed"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
171 "value": "closed"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
172 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
173 ],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
174 "value": "queued"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
175 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
176 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
177 "name": "priority",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
178 "label": D_("priority"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
179 "type": "list-single",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
180 "options": [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
181 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
182 "label": D_("major"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
183 "value": "major"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
184 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
185 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
186 "label": D_("normal"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
187 "value": "normal"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
188 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
189 {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
190 "label": D_("minor"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
191 "value": "minor"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
192 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
193 ],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
194 "value": "normal"
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
195 },
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
196 {"name": "body", "type": "xhtml"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
197 {"name": "comments_uri"},
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
198 ]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
199 }
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
200 }
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
201
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
202
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
203 class PubsubLists:
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
204
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
205 def __init__(self, host):
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
206 log.info(_("Pubsub lists plugin initialization"))
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self.host = host
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
208 self._s = self.host.plugins["XEP-0346"]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
209 self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
210 host.registerNamespace("tickets", self.namespace)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
211 self._p = self.host.plugins["XEP-0060"]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
212 self._m = self.host.plugins["XEP-0277"]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
213 host.bridge.addMethod(
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
214 "listGet",
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
215 ".plugin",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
216 in_sign="ssiassa{ss}s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
217 out_sign="s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
218 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
219 self._s._get(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
220 service,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
221 node,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
222 max_items,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
223 items_ids,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
224 sub_id,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
225 extra,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
226 default_node=self.namespace,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
227 form_ns=APP_NS_TICKETS,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
228 filters={
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
229 "author": self._s.valueOrPublisherFilter,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
230 "created": self._s.dateFilter,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
231 "updated": self._s.dateFilter,
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
232 "time_limit": self._s.dateFilter,
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
233 },
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
234 profile_key=profile_key),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
235 async_=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
236 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
237 host.bridge.addMethod(
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
238 "listSet",
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
239 ".plugin",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
240 in_sign="ssa{sas}ssss",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
241 out_sign="s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
242 method=self._set,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
243 async_=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
244 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
245 host.bridge.addMethod(
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
246 "listSchemaGet",
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
247 ".plugin",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
248 in_sign="sss",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
249 out_sign="s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
250 method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
251 service, nodeIdentifier, default_node=self.namespace,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
252 profile_key=profile_key),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
253 async_=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
254 )
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
255 host.bridge.addMethod(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
256 "listTemplatesNamesGet",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
257 ".plugin",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
258 in_sign="ss",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
259 out_sign="s",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
260 method=self._getTemplatesNames,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
261 )
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
262 host.bridge.addMethod(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
263 "listTemplateGet",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
264 ".plugin",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
265 in_sign="sss",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
266 out_sign="s",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
267 method=self._getTemplate,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
268 )
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
269 host.bridge.addMethod(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
270 "listTemplateCreate",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
271 ".plugin",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
272 in_sign="ssss",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
273 out_sign="(ss)",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
274 method=self._createTemplate,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
275 async_=True,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
276 )
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
277
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
278 def _set(self, service, node, values, schema=None, item_id=None, extra='',
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
279 profile_key=C.PROF_KEY_NONE):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
280 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
281 service, node, schema, item_id, extra, profile_key
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
282 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
283 d = defer.ensureDeferred(self.set(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
284 client, service, node, values, schema, item_id, extra, deserialise=True
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
285 ))
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
286 d.addCallback(lambda ret: ret or "")
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
287 return d
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
288
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
289 async def set(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
290 self, client, service, node, values, schema=None, item_id=None, extra=None,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
291 deserialise=False, form_ns=APP_NS_TICKETS
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
292 ):
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
293 """Publish a tickets
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
294
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
295 @param node(unicode, None): Pubsub node to use
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
296 None to use default tickets node
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
297 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
298
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
299 if value is not iterable, it will be put in a list
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
300 'created' and 'updated' will be forced to current time:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
301 - 'created' is set if item_id is None, i.e. if it's a new ticket
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
302 - 'updated' is set everytime
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
303 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
304 - update(bool): if True, get previous item data to merge with current one
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
305 if True, item_id must be None
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
306 other arguments are same as for [self._s.sendDataFormItem]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
307 @return (unicode): id of the created item
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
308 """
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
309 if not node:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
310 node = self.namespace
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
311
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
312 if not item_id:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
313 comments_service = await self._m.getCommentsService(client, service)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
314
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
315 # we need to use uuid for comments node, because we don't know item id in
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
316 # advance (we don't want to set it ourselves to let the server choose, so we
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
317 # can have a nicer id if serial ids is activated)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
318 comments_node = self._m.getCommentsNode(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
319 node + "_" + str(shortuuid.uuid())
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
320 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
321 options = {
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
322 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
323 self._p.OPT_PERSIST_ITEMS: 1,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
324 self._p.OPT_MAX_ITEMS: -1,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
325 self._p.OPT_DELIVER_PAYLOADS: 1,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
326 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
327 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
328 }
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
329 await self._p.createNode(client, comments_service, comments_node, options)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
330 values["comments_uri"] = uri.buildXMPPUri(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
331 "pubsub",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
332 subtype="microblog",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
333 path=comments_service.full(),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
334 node=comments_node,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
335 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
336
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
337 return await self._s.set(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
338 client, service, node, values, schema, item_id, extra, deserialise, form_ns
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
339 )
3460
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
340
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
341 def _getTemplatesNames(self, language, profile):
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
342 client = self.host.getClient(profile)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
343 return data_format.serialise(self.getTemplatesNames(client, language))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
344
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
345 def getTemplatesNames(self, client, language: str) -> list:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
346 """Retrieve well known list templates"""
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
347
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
348 templates = [{"id": tpl_id, "name": d["name"], "icon": d["icon"]}
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
349 for tpl_id, d in TEMPLATES.items()]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
350 return templates
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
351
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
352 def _getTemplate(self, name, language, profile):
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
353 client = self.host.getClient(profile)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
354 return data_format.serialise(self.getTemplate(client, name, language))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
355
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
356 def getTemplate(self, client, name: str, language: str) -> dict:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
357 """Retrieve a well known template"""
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
358 return TEMPLATES[name]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
359
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
360 def _createTemplate(self, template_id, name, access_model, profile):
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
361 client = self.host.getClient(profile)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
362 d = defer.ensureDeferred(self.createTemplate(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
363 client, template_id, name, access_model
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
364 ))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
365 d.addCallback(lambda node_data: (node_data[0].full(), node_data[1]))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
366 return d
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
367
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
368 async def createTemplate(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
369 self, client, template_id: str, name: str, access_model: str
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
370 ) -> Tuple[jid.JID, str]:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
371 """Create a list from a template"""
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
372 name = name.strip()
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
373 if not name:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
374 name = shortuuid.uuid()
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
375 template = TEMPLATES[template_id]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
376
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
377 fields = [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
378 data_form.Field(fieldType="hidden", var=NS_TICKETS_TYPE, value=template_id)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
379 ]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
380 for field_data in template['fields']:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
381 field_type = field_data.get('type', 'text-single')
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
382 kwargs = {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
383 "fieldType": field_type,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
384 "var": field_data["name"],
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
385 "label": field_data.get('label'),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
386 "value": field_data.get("value"),
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
387 }
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
388 if field_type == "xhtml":
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
389 kwargs.update({
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
390 "fieldType": None,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
391 "ext_type": "xml",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
392 })
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
393 if kwargs["value"] is None:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
394 kwargs["value"] = domish.Element((C.NS_XHTML, "div"))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
395 elif "options" in field_data:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
396 kwargs["options"] = [
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
397 data_form.Option(o["value"], o.get("label"))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
398 for o in field_data["options"]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
399 ]
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
400 field = data_form.Field(**kwargs)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
401 fields.append(field)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
402
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
403 schema = data_form.Form(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
404 "form",
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
405 formNamespace=APP_NS_TICKETS,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
406 fields=fields
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
407 ).toElement()
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
408
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
409 service = client.jid.userhostJID()
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
410 node = self._s.getSubmittedNS(f"{APP_NS_TICKETS}_{name}")
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
411 options = {
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
412 self._p.OPT_ACCESS_MODEL: access_model
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
413 }
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
414 await self._p.createNode(client, service, node, options)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
415 await self._s.setSchema(client, service, node, schema)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
416 list_elt = domish.Element((APP_NS_TICKETS, "list"))
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
417 list_elt["type"] = template_id
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
418 try:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
419 await self.host.plugins['LIST_INTEREST'].registerPubsub(
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
420 client, APP_NS_TICKETS, service, node, creator=True,
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
421 name=name, element=list_elt)
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
422 except Exception as e:
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
423 log.warning(f"Can't add list to interests: {e}")
d4a71a1dac88 plugin misc lists: templates:
Goffi <goffi@goffi.org>
parents: 3459
diff changeset
424 return service, node