[data import] allow a request to be given as argument, ease use from web ui stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 15 May 2012 10:36:02 +0200
branchstable
changeset 8403 a6ee3cd783e1
parent 8402 efafa1261477
child 8405 e83725261adf
[data import] allow a request to be given as argument, ease use from web ui
dataimport.py
--- a/dataimport.py	Tue May 15 10:34:34 2012 +0200
+++ b/dataimport.py	Tue May 15 10:36:02 2012 +0200
@@ -446,9 +446,12 @@
         if session is None:
             sys.exit('please provide a session of run this script with cubicweb-ctl shell and pass cnx as session')
         if not hasattr(session, 'set_cnxset'):
-            # connection
-            cnx = session
-            session = session.request()
+            if hasattr(session, 'request'):
+                # connection object
+                cnx = session
+                session = session.request()
+            else: # object is already a request
+                cnx = session.cnx
             session.set_cnxset = lambda : None
             commit = commit or cnx.commit
         else: