changeset 2785:f18d8315929e

merge_requests: use XHTML for body
author Goffi <goffi@goffi.org>
date Sat, 19 Jan 2019 11:39:02 +0100
parents 76ebecdb9b1e
children be8405795e09
files sat/plugins/plugin_misc_merge_requests.py sat/plugins/plugin_misc_tickets.py
diffstat 2 files changed, 19 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_merge_requests.py	Sat Jan 19 11:39:02 2019 +0100
+++ b/sat/plugins/plugin_misc_merge_requests.py	Sat Jan 19 11:39:02 2019 +0100
@@ -34,7 +34,7 @@
     C.PI_IMPORT_NAME: "MERGE_REQUESTS",
     C.PI_TYPE: "EXP",
     C.PI_PROTOCOLS: [],
-    C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "TICKETS"],
+    C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "TICKETS", "TEXT_SYNTAXES"],
     C.PI_MAIN: "MergeRequests",
     C.PI_HANDLER: "no",
     C.PI_DESCRIPTION: _("""Merge requests management plugin""")
@@ -67,9 +67,9 @@
         log.info(_(u"Merge requests plugin initialization"))
         self.host = host
         host.registerNamespace('merge_requests', NS_MERGE_REQUESTS)
-        self._p = self.host.plugins["XEP-0060"]
-        self._s = self.host.plugins["PUBSUB_SCHEMA"]
-        self._t = self.host.plugins["TICKETS"]
+        self._p = self.host.plugins[u"XEP-0060"]
+        self._s = self.host.plugins[u"PUBSUB_SCHEMA"]
+        self._t = self.host.plugins[u"TICKETS"]
         self._handlers = {}
         self._handlers_list = []  # handlers sorted by priority
         self._type_handlers = {}  # data type => handler map
@@ -259,7 +259,14 @@
                 if not values.get(u'title'):
                     values[u'title'] = msg_lines[0]
                 if not values.get(u'body'):
-                    values[u'body'] = u'\n'.join(msg_lines[1:])
+                    ts = self.host.plugins['TEXT_SYNTAXES']
+                    xhtml = yield ts.convert(
+                        u'\n'.join(msg_lines[1:]),
+                        syntax_from = ts.SYNTAX_TEXT,
+                        syntax_to = ts.SYNTAX_XHTML,
+                        profile = client.profile)
+                    values[u'body'] = '<div xmlns="{ns}">{xhtml}</div>'.format(
+                        ns=C.NS_XHTML, xhtml=xhtml)
 
             values[FIELD_DATA] = data
 
--- a/sat/plugins/plugin_misc_tickets.py	Sat Jan 19 11:39:02 2019 +0100
+++ b/sat/plugins/plugin_misc_tickets.py	Sat Jan 19 11:39:02 2019 +0100
@@ -83,16 +83,8 @@
             async=True,
         )
 
-    def _set(
-        self,
-        service,
-        node,
-        values,
-        schema=None,
-        item_id=None,
-        extra=None,
-        profile_key=C.PROF_KEY_NONE,
-    ):
+    def _set(self, service, node, values, schema=None, item_id=None, extra=None,
+             profile_key=C.PROF_KEY_NONE):
         client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
             service, node, schema, item_id, extra, profile_key
         )
@@ -103,18 +95,8 @@
         return d
 
     @defer.inlineCallbacks
-    def set(
-        self,
-        client,
-        service,
-        node,
-        values,
-        schema=None,
-        item_id=None,
-        extra=None,
-        deserialise=False,
-        form_ns=NS_TICKETS,
-    ):
+    def set(self, client, service, node, values, schema=None, item_id=None, extra=None,
+            deserialise=False, form_ns=NS_TICKETS):
         """Publish a tickets
 
         @param node(unicode, None): Pubsub node to use
@@ -135,9 +117,9 @@
         if not item_id:
             comments_service = yield self._m.getCommentsService(client, service)
 
-            # we need to use uuid for comments node, because we don't know item id in advance
-            # (we don't want to set it ourselves to let the server choose, so we can have
-            #  a nicer id if serial ids is activated)
+            # we need to use uuid for comments node, because we don't know item id in
+            # advance (we don't want to set it ourselves to let the server choose, so we
+            # can have a nicer id if serial ids is activated)
             comments_node = self._m.getCommentsNode(
                 node + u"_" + unicode(shortuuid.uuid())
             )