backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 15 May 2012 14:43:30 +0200
changeset 8408 41461b2e9854
parent 8404 3dcb117fb3b0 (current diff)
parent 8407 6874eb7a08e8 (diff)
child 8409 79534887943e
backport stable
server/sources/datafeed.py
web/views/cwsources.py
--- a/dataimport.py	Tue May 15 10:57:14 2012 +0200
+++ b/dataimport.py	Tue May 15 14:43:30 2012 +0200
@@ -182,7 +182,10 @@
     assert isinstance(row, dict)
     assert isinstance(map, list)
     for src, dest, funcs in map:
-        res[dest] = row[src]
+        try:
+            res[dest] = row[src]
+        except KeyError:
+            continue
         try:
             for func in funcs:
                 res[dest] = func(res[dest])
@@ -446,9 +449,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:
--- a/server/sources/datafeed.py	Tue May 15 10:57:14 2012 +0200
+++ b/server/sources/datafeed.py	Tue May 15 14:43:30 2012 +0200
@@ -401,21 +401,30 @@
             self.import_log.record_error(str(ex))
             return True
         error = False
+        # Check whether self._cw is a session or a connection
+        if getattr(self._cw, 'commit', None) is not None:
+            commit = self._cw.commit
+            set_cnxset = self._cw.set_cnxset
+            rollback = self._cw.rollback
+        else:
+            commit = self._cw.cnx.commit
+            set_cnxset = lambda: None
+            rollback = self._cw.cnx.rollback
         for args in parsed:
             try:
                 self.process_item(*args)
                 if partialcommit:
                     # commit+set_cnxset instead of commit(free_cnxset=False) to let
                     # other a chance to get our connections set
-                    self._cw.commit()
-                    self._cw.set_cnxset()
+                    commit()
+                    set_cnxset()
             except ValidationError, exc:
                 if raise_on_error:
                     raise
                 if partialcommit:
                     self.source.error('Skipping %s because of validation error %s' % (args, exc))
-                    self._cw.rollback()
-                    self._cw.set_cnxset()
+                    rollback()
+                    set_cnxset()
                     error = True
                 else:
                     raise
--- a/web/views/cwsources.py	Tue May 15 10:57:14 2012 +0200
+++ b/web/views/cwsources.py	Tue May 15 14:43:30 2012 +0200
@@ -373,8 +373,9 @@
         w(u'<label>%s</label>' % self._cw._(u'Message threshold'))
         w(u'<select class="log_filter" onchange="filterLog(\'%s\', this.options[this.selectedIndex].value)">'
           % self.view.domid)
-        for level in ('Debug', 'Info', 'Warning', 'Error', 'Fatal'):
-            w('<option value="%s">%s</option>' % (level, self._cw._(level)))
+        for level in ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'FATAL'):
+            w('<option value="%s">%s</option>' % (level.capitalize(),
+                                                  self._cw._(level)))
         w(u'</select>')
         w(u'</fieldset></form>')
         super(LogTableLayout, self).render_table(w, actions, paginate)
@@ -421,7 +422,9 @@
     class URLRenderer(pyviews.PyValTableColRenderer):
         def render_cell(self, w, rownum):
             url = self.data[rownum][1]
-            w(url and tags.a(url, href=url) or u'&#160;')
+            if url and url.startswith('http'):
+                url = tags.a(url, href=url)
+            w(url or u'&#160;')
 
     class LineRenderer(pyviews.PyValTableColRenderer):
         def render_cell(self, w, rownum):