Torsten Irländer avatar Torsten Irländer committed ae22f37

Added todo and did some formatting.

Comments (0)

Files changed (1)

 from formencode import htmlfill
 
 from formbar.fahelpers import get_fieldset, get_data
-from formbar.renderer import FormRenderer, FieldRenderer, get_renderer
+from formbar.renderer import FormRenderer, get_renderer
 
 log = logging.getLogger(__name__)
 
         for prop in relation_properties:
             relation_names[prop.key] = prop
 
-        # related_classes = [prop.mapper.class_ for prop in relation_properties]
-        # related_tables = [prop.target for prop in relation_properties]
+        #related_classes = [prop.mapper.class_ for prop in relation_properties]
+        #related_tables = [prop.target for prop in relation_properties]
 
         for key, value in self.data.iteritems():
             relation = relation_names.get(key)
     def _load_relations(self, relation, values):
         loaded = []
         for value in values:
-            r = self._dbsession.query(relation).filter(relation.id == value).one()
+            db = self._dbsession
+            r = db.query(relation).filter(relation.id == value).one()
             loaded.append(r)
         return loaded
 
         user_defined_options = self._config.options
         if user_defined_options:
             return user_defined_options
-        else:
+        elif self._form._dbsession:
             # Get mapped clazz for the field
             options = []
             mapper = sa.orm.object_mapper(self._form._item)
                     items = self._form._dbsession.query(clazz)
                     options = [(item.id, item) for item in items]
                     break
+        else:
+            # TODO: Try to get the session from the item. Ther must be
+            # somewhere the already bound session. (torsten) <2013-07-23 00:27>
+            log.warning('No db connection configured for this form. Can '
+                        'not load options')
         return options
 
-
     def add_error(self, error):
         self._errors.append(error)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.