diff sat_pubsub/pgsql_storage.py @ 244:3ecc94407e36

item access_model (not finished)
author Goffi <goffi@goffi.org>
date Wed, 30 May 2012 01:04:15 +0200
parents 42048e37699e
children e11e99246be5
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Sun May 27 15:55:25 2012 +0200
+++ b/sat_pubsub/pgsql_storage.py	Wed May 30 01:04:15 2012 +0200
@@ -61,9 +61,14 @@
 
 from wokkel.generic import parseXml, stripNamespace
 from wokkel.pubsub import Subscription
+from wokkel import data_form
 
 from sat_pubsub import error, iidavoll
 
+NS_ITEM_CONFIG = "http://jabber.org/protocol/pubsub#item-config"
+OPT_ACCESS_MODEL = 'pubsub#access_model'
+VAL_DEFAULT = 'default'
+
 class Storage:
 
     implements(iidavoll.IStorage)
@@ -510,7 +515,23 @@
 
 
     def _storeItem(self, cursor, item, publisher):
+        item_config = None
+        access_model = VAL_DEFAULT
+        for i in range(len(item.children)):
+            elt = item.children[i]
+            if not (elt.uri,elt.name)==(data_form.NS_X_DATA,'x'):
+                continue
+            form = data_form.Form.fromElement(elt)
+            if (form.formNamespace == NS_ITEM_CONFIG):
+                item_config = form
+                del item.children[i] #we need to remove the config from item
+                break
+
+        if item_config:
+            access_model = item_config.get("pubsub#access_model", VAL_DEFAULT)
+         
         data = item.toXml()
+        
         cursor.execute("""UPDATE items SET date=now(), publisher=%s, data=%s
                           FROM nodes
                           WHERE nodes.node_id = items.node_id AND
@@ -522,12 +543,13 @@
         if cursor.rowcount == 1:
             return
 
-        cursor.execute("""INSERT INTO items (node_id, item, publisher, data)
-                          SELECT node_id, %s, %s, %s FROM nodes
+        cursor.execute("""INSERT INTO items (node_id, item, publisher, data, access_model)
+                          SELECT node_id, %s, %s, %s, %s FROM nodes
                                                      WHERE node=%s""",
                        (item["id"],
                         publisher.full(),
                         data,
+                        access_model,
                         self.nodeIdentifier))