cleanup 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 16 Sep 2009 14:32:56 +0200
branch3.5
changeset 3245 7ef021ac8dec
parent 3244 1fc804b2c5ba
child 3246 9e4adca73a95
cleanup
entity.py
server/sources/ldapuser.py
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
web/views/forms.py
--- a/entity.py	Wed Sep 16 14:32:13 2009 +0200
+++ b/entity.py	Wed Sep 16 14:32:56 2009 +0200
@@ -84,6 +84,7 @@
             except AttributeError:
                 continue
 
+
 class _metaentity(type):
     """this metaclass sets the relation tags on the entity class
     and deals with the `widgets` attribute
@@ -721,20 +722,6 @@
 
     # generic vocabulary methods ##############################################
 
-    @deprecated('see new form api')
-    def vocabulary(self, rtype, role='subject', limit=None):
-        """vocabulary functions must return a list of couples
-        (label, eid) that will typically be used to fill the
-        edition view's combobox.
-
-        If `eid` is None in one of these couples, it should be
-        interpreted as a separator in case vocabulary results are grouped
-        """
-        from logilab.common.testlib import mock_object
-        form = self.vreg.select('forms', 'edition', self.req, entity=self)
-        field = mock_object(name=rtype, role=role)
-        return form.form_field_vocabulary(field, limit)
-
     def unrelated_rql(self, rtype, targettype, role, ordermethod=None,
                       vocabconstraints=True):
         """build a rql to fetch `targettype` entities unrelated to this entity
@@ -803,7 +790,7 @@
         if limit is not None:
             before, after = rql.split(' WHERE ', 1)
             rql = '%s LIMIT %s WHERE %s' % (before, limit, after)
-        return self.req.execute(rql, args, tuple(args.keys()))
+        return self.req.execute(rql, args, tuple(args))
 
     # relations cache handling ################################################
 
@@ -959,6 +946,20 @@
                     words += entity.get_words()
         return words
 
+    @deprecated('[3.2] see new form api')
+    def vocabulary(self, rtype, role='subject', limit=None):
+        """vocabulary functions must return a list of couples
+        (label, eid) that will typically be used to fill the
+        edition view's combobox.
+
+        If `eid` is None in one of these couples, it should be
+        interpreted as a separator in case vocabulary results are grouped
+        """
+        from logilab.common.testlib import mock_object
+        form = self.vreg.select('forms', 'edition', self.req, entity=self)
+        field = mock_object(name=rtype, role=role)
+        return form.form_field_vocabulary(field, limit)
+
 
 # attribute and relation descriptors ##########################################
 
--- a/server/sources/ldapuser.py	Wed Sep 16 14:32:13 2009 +0200
+++ b/server/sources/ldapuser.py	Wed Sep 16 14:32:56 2009 +0200
@@ -336,7 +336,7 @@
                 if sol[varname] == 'CWUser':
                     mainvars.append(varname)
                     break
-        assert mainvars
+        assert mainvars, rqlst
         columns, globtransforms = self.prepare_columns(mainvars, rqlst)
         eidfilters = []
         allresults = []
--- a/server/sources/rql2sql.py	Wed Sep 16 14:32:13 2009 +0200
+++ b/server/sources/rql2sql.py	Wed Sep 16 14:32:56 2009 +0200
@@ -656,10 +656,6 @@
                 sql = self._visit_outer_join_relation(relation, rschema)
             elif rschema.inlined:
                 sql = self._visit_inlined_relation(relation)
-#             elif isinstance(relation.parent, Not):
-#                 self._state.done.add(relation.parent)
-#                 # NOT relation
-#                 sql = self._visit_not_relation(relation, rschema)
             else:
                 # regular (non final) relation
                 sql = self._visit_relation(relation, rschema)
@@ -1104,7 +1100,8 @@
                 raise BadRQLQuery(var.stmt.root)
             table = var.name
             sql = '%s.%seid' % (table, SQL_PREFIX)
-            self.add_table('%s%s AS %s' % (SQL_PREFIX, etype, table), table, scope=scope)
+            self.add_table('%s%s AS %s' % (SQL_PREFIX, etype, table), table,
+                           scope=scope)
         return sql, table
 
     def _inlined_var_sql(self, var, rtype):
--- a/server/test/unittest_rql2sql.py	Wed Sep 16 14:32:13 2009 +0200
+++ b/server/test/unittest_rql2sql.py	Wed Sep 16 14:32:56 2009 +0200
@@ -163,7 +163,6 @@
 ]
 
 ADVANCED= [
-
     ("Societe S WHERE S nom 'Logilab' OR S nom 'Caesium'",
      '''SELECT S.cw_eid
 FROM cw_Societe AS S
--- a/web/views/forms.py	Wed Sep 16 14:32:13 2009 +0200
+++ b/web/views/forms.py	Wed Sep 16 14:32:56 2009 +0200
@@ -486,6 +486,7 @@
         #       cases, it doesn't make sense to sort results afterwards.
         return vocabfunc(rtype, limit)
 
+    # XXX should be on the field, no?
     def subject_relation_vocabulary(self, rtype, limit=None):
         """defaut vocabulary method for the given relation, looking for
         relation's object entities (i.e. self is the subject)
@@ -529,25 +530,6 @@
                 break
         return result
 
-    # def subject_in_state_vocabulary(self, rtype, limit=None):
-    #     """vocabulary method for the in_state relation, looking for relation's
-    #     object entities (i.e. self is the subject) according to initial_state,
-    #     state_of and next_state relation
-    #     """
-    #     entity = self.edited_entity
-    #     if not entity.has_eid() or not entity.in_state:
-    #         # get the initial state
-    #         rql = 'Any S where S state_of ET, ET name %(etype)s, ET initial_state S'
-    #         rset = self.req.execute(rql, {'etype': str(entity.e_schema)})
-    #         if rset:
-    #             return [(rset.get_entity(0, 0).view('combobox'), rset[0][0])]
-    #         return []
-    #     results = []
-    #     for tr in entity.in_state[0].transitions(entity):
-    #         state = tr.destination_state[0]
-    #         results.append((state.view('combobox'), state.eid))
-    #     return sorted(results)
-
     def srelations_by_category(self, categories=None, permission=None):
         return ()