comparison sat/plugins/plugin_misc_forums.py @ 2959:989b622faff6

plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
author Goffi <goffi@goffi.org>
date Fri, 14 Jun 2019 12:37:34 +0200
parents 003b8b4b56a7
children ab2696e34d29
comparison
equal deleted inserted replaced
2958:e2cb04b381bb 2959:989b622faff6
1 #!/usr/bin/env python2 1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT plugin for Pubsub Schemas 4 # SAT plugin for pubsub forums
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
7 # This program is free software: you can redistribute it and/or modify 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 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 9 # the Free Software Foundation, either version 3 of the License, or
81 method=self._createTopic, 81 method=self._createTopic,
82 async=True) 82 async=True)
83 83
84 @defer.inlineCallbacks 84 @defer.inlineCallbacks
85 def _createForums(self, client, forums, service, node, forums_elt=None, names=None): 85 def _createForums(self, client, forums, service, node, forums_elt=None, names=None):
86 """recursively create <forums> element(s) 86 """Recursively create <forums> element(s)
87 87
88 @param forums(list): forums which may have subforums 88 @param forums(list): forums which may have subforums
89 @param service(jid.JID): service where the new nodes will be created 89 @param service(jid.JID): service where the new nodes will be created
90 @param node(unicode): node of the forums 90 @param node(unicode): node of the forums
91 will be used as basis for the newly created nodes 91 will be used as basis for the newly created nodes
137 if not forum_elt.getAttribute(u'uri') and not forum_elt.children: 137 if not forum_elt.getAttribute(u'uri') and not forum_elt.children:
138 raise ValueError(_(u"forum need uri or sub-forums")) 138 raise ValueError(_(u"forum need uri or sub-forums"))
139 defer.returnValue(forums_elt) 139 defer.returnValue(forums_elt)
140 140
141 def _parseForums(self, parent_elt=None, forums=None): 141 def _parseForums(self, parent_elt=None, forums=None):
142 """recursivly parse a <forums> elements and return corresponding forums data 142 """Recursivly parse a <forums> elements and return corresponding forums data
143 143
144 @param item(domish.Element): item with <forums> element 144 @param item(domish.Element): item with <forums> element
145 @param parent_elt(domish.Element, None): element to parse 145 @param parent_elt(domish.Element, None): element to parse
146 @return (list): parsed data 146 @return (list): parsed data
147 @raise ValueError: item is invalid 147 @raise ValueError: item is invalid
218 node = None 218 node = None
219 return self.set(client, forums, service, node, forums_key or None) 219 return self.set(client, forums, service, node, forums_key or None)
220 220
221 @defer.inlineCallbacks 221 @defer.inlineCallbacks
222 def set(self, client, forums, service=None, node=None, forums_key=None): 222 def set(self, client, forums, service=None, node=None, forums_key=None):
223 """create or replace forums structure 223 """Create or replace forums structure
224 224
225 @param forums(list): list of dictionary as follow: 225 @param forums(list): list of dictionary as follow:
226 a dictionary represent a forum metadata, with the following keys: 226 a dictionary represent a forum metadata, with the following keys:
227 - title: title of the forum 227 - title: title of the forum
228 - name: short name (unique in those forums) for the forum 228 - name: short name (unique in those forums) for the forum
252 d.addCallback(lambda(topics, metadata): (topics, {k: unicode(v) for k,v in metadata.iteritems()})) 252 d.addCallback(lambda(topics, metadata): (topics, {k: unicode(v) for k,v in metadata.iteritems()}))
253 return d 253 return d
254 254
255 @defer.inlineCallbacks 255 @defer.inlineCallbacks
256 def getTopics(self, client, service, node, rsm_request=None, extra=None): 256 def getTopics(self, client, service, node, rsm_request=None, extra=None):
257 """retrieve topics data 257 """Retrieve topics data
258 258
259 Topics are simple microblog URIs with some metadata duplicated from first post 259 Topics are simple microblog URIs with some metadata duplicated from first post
260 """ 260 """
261 topics_data = yield self._p.getItems(client, service, node, rsm_request=rsm_request, extra=extra) 261 topics_data = yield self._p.getItems(client, service, node, rsm_request=rsm_request, extra=extra)
262 topics = [] 262 topics = []