changeset 2603:5d4ac5415b40

plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
author Goffi <goffi@goffi.org>
date Fri, 01 Jun 2018 12:21:23 +0200
parents 41db2f58c753
children 700327fa9281
files sat/plugins/plugin_exp_pubsub_schema.py sat/plugins/plugin_misc_merge_requests.py sat/plugins/plugin_misc_tickets.py
diffstat 3 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_pubsub_schema.py	Fri Jun 01 12:17:06 2018 +0200
+++ b/sat/plugins/plugin_exp_pubsub_schema.py	Fri Jun 01 12:21:23 2018 +0200
@@ -376,13 +376,25 @@
 
         return client, service, node, max_items, extra, sub_id
 
-    def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, default_node=None, form_ns=None, filters=None, profile_key=C.PROF_KEY_NONE):
+    def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra=None, default_node=None, form_ns=None, filters=None, profile_key=C.PROF_KEY_NONE):
         """Bridge method to retrieve data from node with schema
 
         this method is a helper so dependant plugins can use it directly
         when adding *Get methods
+        extra can have the key "labels_as_list" which is a hack to convert
+            labels from textbox to list in XMLUI, which usually render better
+            in final UI.
         """
-        client, service, node, max_items, extra, sub_id = self.prepareBridgeGet(service, node, max_items, sub_id, extra_dict, profile_key)
+        if filters is None:
+            filters = {}
+        if extra is None:
+            extra = {}
+        # XXX: Q&D way to get list for labels when displaying them, but text when we
+        #      have to modify them
+        if C.bool(extra.get('labels_as_list', C.BOOL_FALSE)):
+            filters = filters.copy()
+            filters[u'labels'] = self.textbox2ListFilter
+        client, service, node, max_items, extra, sub_id = self.prepareBridgeGet(service, node, max_items, sub_id, extra, profile_key)
         d = self.getDataFormItems(client, service, node or None,
             max_items=max_items,
             item_ids=item_ids,
--- a/sat/plugins/plugin_misc_merge_requests.py	Fri Jun 01 12:17:06 2018 +0200
+++ b/sat/plugins/plugin_misc_merge_requests.py	Fri Jun 01 12:21:23 2018 +0200
@@ -156,6 +156,14 @@
         """
         if not node:
             node = NS_MERGE_REQUESTS
+        if extra is None:
+            extra = {}
+        # XXX: Q&D way to get list for labels when displaying them, but text when we
+        #      have to modify them
+        if C.bool(extra.get('labels_as_list', C.BOOL_FALSE)):
+            filters = {u'labels': self._s.textbox2ListFilter}
+        else:
+            filters = {}
         tickets_xmlui, metadata = yield self._s.getDataFormItems(
             client,
             service,
@@ -166,7 +174,7 @@
             rsm_request=rsm_request,
             extra=extra,
             form_ns=NS_MERGE_REQUESTS,
-            filters = {u'labels': self._s.textbox2ListFilter})
+            filters = filters)
         parsed_patches = []
         if extra.get('parse', False):
             for ticket in tickets_xmlui:
--- a/sat/plugins/plugin_misc_tickets.py	Fri Jun 01 12:17:06 2018 +0200
+++ b/sat/plugins/plugin_misc_tickets.py	Fri Jun 01 12:21:23 2018 +0200
@@ -56,7 +56,6 @@
                                   default_node=NS_TICKETS,
                                   form_ns=NS_TICKETS,
                                   filters = {u'author': self._s.valueOrPublisherFilter,
-                                             u'labels': self._s.textbox2ListFilter,
                                              u'created': self._s.dateFilter,
                                              u'updated': self._s.dateFilter,
                                              }),