crast  committed 126d7aa

ext.sqlalchemy: remove deprecated properties.

  • Participants
  • Parent commits e25714a

Comments (0)

Files changed (2)

File tests/

 from unittest import TestCase
-from wtforms.ext.sqlalchemy.fields import ModelSelectField, QuerySelectField, QuerySelectMultipleField
+from wtforms.ext.sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField
 from wtforms.form import Form
         self.assertEqual(form.a(), [(u'1', 'apple', False), (u'2', 'banana', True)])
-class ModelSelectFieldTest(TestBase):
-    def setUp(self):
-        from sqlalchemy.orm import mapper as sqla_mapper
-        engine = create_engine('sqlite:///:memory:', echo=False)
-        self.Session = session = scoped_session(sessionmaker(autoflush=False, autocommit=False, bind=engine))
-        def mapper(cls, *arg, **kw):
-            cls.query = session.query_property()
-            return sqla_mapper(cls, *arg, **kw)
-        self._do_tables(mapper, engine)
-    def test(self):
-        sess = self.Session
-        self._fill(sess)
-        class F(Form):
-            a = ModelSelectField(get_label='name', model=self.Test, widget=LazySelect())
-        form = F()
-        self.assertEqual(form.a(), [(u'1', 'apple', False), (u'2', 'banana', False)])
 if __name__ == '__main__':
     from unittest import main

File wtforms/ext/sqlalchemy/

 Useful form fields for use with SQLAlchemy ORM.
 import operator
-import warnings
 from wtforms import widgets
 from wtforms.fields import SelectFieldBase
 __all__ = (
-    'QuerySelectField', 'QuerySelectMultipleField', 'ModelSelectField',
+    'QuerySelectField', 'QuerySelectMultipleField',
     top of the list. Selecting this choice will result in the `data` property
     being `None`. The label for this blank choice can be set by specifying the
     `blank_text` parameter.
-    The `pk_attr` and `label_attr` parameters are deprecated and will be
-    removed in a future release.
     widget = widgets.Select()
     def __init__(self, label=u'', validators=None, query_factory=None,
-                 get_pk=None, get_label=None, allow_blank=False, blank_text=u'',
-                 pk_attr=None, label_attr=None, **kwargs):
+                 get_pk=None, get_label=None, allow_blank=False,
+                 blank_text=u'', **kwargs):
         super(QuerySelectField, self).__init__(label, validators, **kwargs)
         self.query_factory = query_factory
-        if pk_attr is not None:
-            warnings.warn('pk_attr= will be removed in WTForms 0.7, use get_pk= instead.', DeprecationWarning)
-            self.get_pk = operator.attrgetter(pk_attr)
-        elif get_pk is None:
+        if get_pk is None:
             if not has_identity_key:
                 raise Exception('The sqlalchemy identity_key function could not be imported.')
             self.get_pk = get_pk_from_identity
             self.get_pk = get_pk
-        if label_attr is not None:
-            warnings.warn('label_attr= will be removed in WTForms 0.7, use get_label= instead.', DeprecationWarning)
-            self.get_label = operator.attrgetter(label_attr)
-        elif get_label is None:
+        if get_label is None:
             self.get_label = lambda x: x
         elif isinstance(get_label, basestring):
             self.get_label = operator.attrgetter(get_label)
                     raise ValidationError(self.gettext('Not a valid choice'))
-class ModelSelectField(QuerySelectField):
-    """
-    Similar to QuerySelectField, only for model classes.
-    Using this field is only meaningful when using scoped sessions in
-    SQLAlchemy, because otherwise model instances do not know how to make
-    queries of themselves. This field is simply a convenience for using
-    `Model.query` as the factory for QuerySelectField.
-    **Note**: This field is deprecated and will be removed in a future release
-    of WTForms.
-    """
-    def __init__(self, label=u'', validators=None, model=None, **kwargs):
-        warnings.warn(
-            'Session-aware mappers are deprecated as of SQLAlchemy 0.5.5; '
-            'this field will be removed by WTForms 0.7',
-            DeprecationWarning
-        )
-        assert model is not None, "Must specify a model."
-        query_factory = lambda: model.query
-        super(ModelSelectField, self).__init__(label, validators, query_factory=query_factory, **kwargs)
 def get_pk_from_identity(obj):
     cls, key = identity_key(instance=obj)
     return u':'.join(unicode(x) for x in key)