Commits

Gael Pasgrimaud committed 4514bf3

small fixes

  • Participants
  • Parent commits 2d9951e

Comments (0)

Files changed (2)

formalchemy/base.py

         if args:
             for field in args:
                 if isinstance(field, basestring):
-                    field = getattr(_fields, field)
-                assert isinstance(field, fields.AbstractField)
+                    if field in _fields:
+                        field = _fields.get(field)
+                    else:
+                        raise AttributeError('%r as not field named %s' % (self, field))
+                assert isinstance(field, fields.AbstractField), field
                 field.bind(mr)
                 _new_fields.append(field)
             mr._render_fields = OrderedDict([(field.key, field) for field in _new_fields])

formalchemy/ext/pylons/controller.py

         else:
             data = request.POST
 
-        fs = fs.bind(self.get_model(), data=data, session=self.Session())
+        try:
+            fs = fs.bind(data=data, session=self.Session())
+        except:
+            # non SA forms
+            fs = fs.bind(self.get_model(), data=data, session=self.Session())
         if fs.validate():
             fs.sync()
             self.sync(fs)
                     return ''
                 redirect(model_url(self.collection_name))
             else:
-                fs = self.get_fieldset(_pk(fs.model))
+                fs.rebind(fs.model, data=None)
                 return self.render(format=format, fs=fs)
         return self.render(format=format, fs=fs, action='new', id=None)