diff sat_pubsub/pgsql_storage.py @ 317:34adc4a8aa64

new container module, with an ItemData container: this simplify item data manipulation and transmission between storage and backend, it's also better if new data need to be used.
author Goffi <goffi@goffi.org>
date Sun, 03 Jan 2016 18:33:22 +0100
parents 5d7c3787672e
children d13526c0eb32
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Sun Jan 03 18:33:22 2016 +0100
+++ b/sat_pubsub/pgsql_storage.py	Sun Jan 03 18:33:22 2016 +0100
@@ -61,7 +61,10 @@
 from wokkel import generic
 from wokkel.pubsub import Subscription
 
-from sat_pubsub import error, iidavoll, const
+from sat_pubsub import error
+from sat_pubsub import iidavoll
+from sat_pubsub import const
+from sat_pubsub import container
 import psycopg2
 import psycopg2.extensions
 # we wants psycopg2 to return us unicode, not str
@@ -689,7 +692,8 @@
         @param rsm_data: options for RSM feature handling (XEP-0059) as a
                          dictionnary of C{unicode} to C{unicode}.
 
-        @return: list of (item, access_model, id) if unrestricted is True, else list of items
+        @return: list of container.ItemData
+            if unrestricted is False, access_model and config will be None
         """
         if ext_data is None:
             ext_data = {}
@@ -778,10 +782,10 @@
                     cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,))
                     access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()]
 
-                ret.append((item, access_model, access_list))
+                ret.append(container.ItemData(item, access_model, access_list))
             return ret
-        items = [generic.stripNamespace(parseXml(r[0])) for r in result]
-        return items
+        items_data = [container.ItemData(generic.stripNamespace(parseXml(r[0])), None, None) for r in result]
+        return items_data
 
     def countItems(self, authorized_groups, unrestricted):
         """ Count the accessible items.
@@ -793,6 +797,7 @@
         return self.dbpool.runInteraction(self._countItems, authorized_groups, unrestricted)
 
     def _countItems(self, cursor, authorized_groups, unrestricted):
+        # FIXME: should not be a separate method, but should be an option of getItems instead
         self._checkNodeExists(cursor)
 
         if unrestricted:
@@ -862,8 +867,9 @@
         @param authorized_groups: we want to get items that these groups can access
         @param unrestricted: if true, don't check permissions
         @param itemIdentifiers: list of ids of the items we want to get
-        @return: list of (item, access_model, access_list) if unrestricted is True, else list of items
-            access_list is managed as a dictionnary with same key as for item_config
+        @return: list of container.ItemData
+            ItemData.config will contains access_list (managed as a dictionnary with same key as for item_config)
+            if unrestricted is False, access_model and config will be None
         """
         return self.dbpool.runInteraction(self._getItemsById, authorized_groups, unrestricted, itemIdentifiers)
 
@@ -890,7 +896,7 @@
                     cursor.execute('SELECT groupname FROM item_groups_authorized WHERE item_id=%s', (item_id,))
                     access_list[const.OPT_ROSTER_GROUPS_ALLOWED] = [r[0] for r in cursor.fetchall()]
 
-                ret.append((item, access_model, access_list))
+                ret.append(container.ItemData(item, access_model, access_list))
         else: #we check permission before returning items
             for itemIdentifier in itemIdentifiers:
                 args = [self.nodeDbId, itemIdentifier]
@@ -906,7 +912,7 @@
 
                 result = cursor.fetchone()
                 if result:
-                    ret.append(generic.stripNamespace(parseXml(result[0])))
+                    ret.append(container.ItemData(generic.stripNamespace(parseXml(result[0])), None, None))
 
         return ret