code style reformatting using black
This commit is contained in:
parent
4127bcffd0
commit
744cb0c503
1 changed files with 21394 additions and 10488 deletions
|
|
@ -21,6 +21,7 @@ from sat.core.i18n import _
|
|||
from sat.core.constants import Const as C
|
||||
from sat.core import exceptions
|
||||
from sat.core.log import getLogger
|
||||
|
||||
log = getLogger(__name__)
|
||||
from twisted.internet import defer
|
||||
from sat.tools.common import uri
|
||||
|
|
@ -34,15 +35,17 @@ PLUGIN_INFO = {
|
|||
C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "XEP-0277", "PUBSUB_SCHEMA"],
|
||||
C.PI_MAIN: "TicketsImportPlugin",
|
||||
C.PI_HANDLER: "no",
|
||||
C.PI_DESCRIPTION: _(u"""Tickets import management:
|
||||
This plugin manage the different tickets importers which can register to it, and handle generic importing tasks.""")
|
||||
C.PI_DESCRIPTION: _(
|
||||
u"""Tickets import management:
|
||||
This plugin manage the different tickets importers which can register to it, and handle generic importing tasks."""
|
||||
),
|
||||
}
|
||||
|
||||
OPT_MAPPING = 'mapping'
|
||||
FIELDS_LIST = (u'labels', u'cc_emails') # fields which must have a list as value
|
||||
FIELDS_DATE = (u'created', u'updated')
|
||||
OPT_MAPPING = "mapping"
|
||||
FIELDS_LIST = (u"labels", u"cc_emails") # fields which must have a list as value
|
||||
FIELDS_DATE = (u"created", u"updated")
|
||||
|
||||
NS_TICKETS = 'org.salut-a-toi.tickets:0'
|
||||
NS_TICKETS = "org.salut-a-toi.tickets:0"
|
||||
|
||||
|
||||
class TicketsImportPlugin(object):
|
||||
|
|
@ -54,13 +57,15 @@ class TicketsImportPlugin(object):
|
|||
log.info(_("plugin Tickets Import initialization"))
|
||||
self.host = host
|
||||
self._importers = {}
|
||||
self._p = host.plugins['XEP-0060']
|
||||
self._m = host.plugins['XEP-0277']
|
||||
self._s = host.plugins['PUBSUB_SCHEMA']
|
||||
host.plugins['IMPORT'].initialize(self, u'tickets')
|
||||
self._p = host.plugins["XEP-0060"]
|
||||
self._m = host.plugins["XEP-0277"]
|
||||
self._s = host.plugins["PUBSUB_SCHEMA"]
|
||||
host.plugins["IMPORT"].initialize(self, u"tickets")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def importItem(self, client, item_import_data, session, options, return_data, service, node):
|
||||
def importItem(
|
||||
self, client, item_import_data, session, options, return_data, service, node
|
||||
):
|
||||
"""
|
||||
|
||||
@param item_import_data(dict): no key is mandatory, but if a key doesn't exists in dest form, it will be ignored.
|
||||
|
|
@ -101,20 +106,24 @@ class TicketsImportPlugin(object):
|
|||
If you specify several import ticket key to the same dest key,
|
||||
the values will be joined with line feeds
|
||||
"""
|
||||
if 'comments_uri' in item_import_data:
|
||||
raise exceptions.DataError(_(u'comments_uri key will be generated and must not be used by importer'))
|
||||
if "comments_uri" in item_import_data:
|
||||
raise exceptions.DataError(
|
||||
_(u"comments_uri key will be generated and must not be used by importer")
|
||||
)
|
||||
for key in FIELDS_LIST:
|
||||
if not isinstance(item_import_data.get(key, []), list):
|
||||
raise exceptions.DataError(_(u'{key} must be a list').format(key=key))
|
||||
raise exceptions.DataError(_(u"{key} must be a list").format(key=key))
|
||||
for key in FIELDS_DATE:
|
||||
try:
|
||||
item_import_data[key] = utils.xmpp_date(item_import_data[key])
|
||||
except KeyError:
|
||||
continue
|
||||
if session[u'root_node'] is None:
|
||||
session[u'root_node'] = NS_TICKETS
|
||||
if not 'schema' in session:
|
||||
session['schema'] = yield self._s.getSchemaForm(client, service, node or session[u'root_node'])
|
||||
if session[u"root_node"] is None:
|
||||
session[u"root_node"] = NS_TICKETS
|
||||
if not "schema" in session:
|
||||
session["schema"] = yield self._s.getSchemaForm(
|
||||
client, service, node or session[u"root_node"]
|
||||
)
|
||||
defer.returnValue(item_import_data)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
|
@ -122,40 +131,53 @@ class TicketsImportPlugin(object):
|
|||
# TODO: force "open" permission (except if private, check below)
|
||||
# TODO: handle "private" metadata, to have non public access for node
|
||||
# TODO: node access/publish model should be customisable
|
||||
comments = ticket_data.get('comments', [])
|
||||
comments = ticket_data.get("comments", [])
|
||||
service = yield self._m.getCommentsService(client)
|
||||
node = self._m.getCommentsNode(session['root_node'] + u'_' + ticket_data['id'])
|
||||
node_options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
|
||||
self._p.OPT_PERSIST_ITEMS: 1,
|
||||
self._p.OPT_MAX_ITEMS: -1,
|
||||
self._p.OPT_DELIVER_PAYLOADS: 1,
|
||||
self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
|
||||
self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
|
||||
}
|
||||
node = self._m.getCommentsNode(session["root_node"] + u"_" + ticket_data["id"])
|
||||
node_options = {
|
||||
self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
|
||||
self._p.OPT_PERSIST_ITEMS: 1,
|
||||
self._p.OPT_MAX_ITEMS: -1,
|
||||
self._p.OPT_DELIVER_PAYLOADS: 1,
|
||||
self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
|
||||
self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
|
||||
}
|
||||
yield self._p.createIfNewNode(client, service, node, options=node_options)
|
||||
ticket_data['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=service.full(), node=node)
|
||||
ticket_data["comments_uri"] = uri.buildXMPPUri(
|
||||
u"pubsub", subtype="microblog", path=service.full(), node=node
|
||||
)
|
||||
for comment in comments:
|
||||
if 'updated' not in comment and 'published' in comment:
|
||||
if "updated" not in comment and "published" in comment:
|
||||
# we don't want an automatic update date
|
||||
comment['updated'] = comment['published']
|
||||
comment["updated"] = comment["published"]
|
||||
yield self._m.send(client, comment, service, node)
|
||||
|
||||
def publishItem(self, client, ticket_data, service, node, session):
|
||||
if node is None:
|
||||
node = NS_TICKETS
|
||||
id_ = ticket_data.pop('id', None)
|
||||
log.debug(u"uploading item [{id}]: {title}".format(id=id_, title=ticket_data.get('title','')))
|
||||
return self._s.sendDataFormItem(client, service, node, ticket_data, session['schema'], id_)
|
||||
id_ = ticket_data.pop("id", None)
|
||||
log.debug(
|
||||
u"uploading item [{id}]: {title}".format(
|
||||
id=id_, title=ticket_data.get("title", "")
|
||||
)
|
||||
)
|
||||
return self._s.sendDataFormItem(
|
||||
client, service, node, ticket_data, session["schema"], id_
|
||||
)
|
||||
|
||||
def itemFilters(self, client, ticket_data, session, options):
|
||||
mapping = options.get(OPT_MAPPING)
|
||||
if mapping is not None:
|
||||
if not isinstance(mapping, dict):
|
||||
raise exceptions.DataError(_(u'mapping option must be a dictionary'))
|
||||
raise exceptions.DataError(_(u"mapping option must be a dictionary"))
|
||||
|
||||
for source, dest in mapping.iteritems():
|
||||
if not isinstance(source, unicode) or not isinstance(dest, unicode):
|
||||
raise exceptions.DataError(_(u'keys and values of mapping must be sources and destinations ticket fields'))
|
||||
raise exceptions.DataError(
|
||||
_(
|
||||
u"keys and values of mapping must be sources and destinations ticket fields"
|
||||
)
|
||||
)
|
||||
if source in ticket_data:
|
||||
value = ticket_data.pop(source)
|
||||
if dest in FIELDS_LIST:
|
||||
|
|
@ -163,6 +185,6 @@ class TicketsImportPlugin(object):
|
|||
values.append(value)
|
||||
else:
|
||||
if dest in ticket_data:
|
||||
ticket_data[dest] = ticket_data[dest] + u'\n' + value
|
||||
ticket_data[dest] = ticket_data[dest] + u"\n" + value
|
||||
else:
|
||||
ticket_data[dest] = value
|
||||
|
|
|
|||
Loading…
Reference in a new issue