[Checkins] SVN: grokapps/rdbexample/trunk/src/rdbexample/app.py - whitespace

Christian Theune ct at gocept.com
Fri May 2 13:42:34 EDT 2008


Log message for revision 86111:
  - whitespace
  - a workaround for a sqlalchemy bug (in 0.4.5) that can't use mapped classes
    for referencing ForeignKey constraints
  - make the traverser convert the name to an int
  - make the department list the index view for faculties
  

Changed:
  U   grokapps/rdbexample/trunk/src/rdbexample/app.py

-=-
Modified: grokapps/rdbexample/trunk/src/rdbexample/app.py
===================================================================
--- grokapps/rdbexample/trunk/src/rdbexample/app.py	2008-05-02 17:41:27 UTC (rev 86110)
+++ grokapps/rdbexample/trunk/src/rdbexample/app.py	2008-05-02 17:42:33 UTC (rev 86111)
@@ -5,25 +5,34 @@
 from sqlalchemy.types import Integer, String
 from sqlalchemy.orm import relation
 
+
 class Database(rdb.Database):
+
     url = 'postgres:///rdbexample'
-    
+
+
 class RDBExample(grok.Application, grok.Model):
+
     def traverse(self, name):
-        return rdb.query(Faculty).get(name)
-    
+        return rdb.query(Faculty).get(int(name))
+
+
 class Index(grok.View):
-    pass
 
+    grok.context(RDBExample)
+
+
 class Departments(rdb.Container):
     pass
 
+
 class Faculty(rdb.Model):
+
     # rdb.table_name('faculty') is the default
     __tablename__ = 'faculty'
 
-    grok.traversable('departments')    
-    
+    grok.traversable('departments')
+
     id = Column('id', Integer, primary_key=True)
     title = Column('email', String(50))
 
@@ -31,16 +40,20 @@
                            backref='faculty',
                            collection_class=Departments)
 
+
 class Department(rdb.Model):
     __tablename__ = 'department'
 
     id = Column('id', Integer, primary_key=True)
-    faculty_id = Column('faculty_id', Integer, ForeignKey(Faculty.id))
-    
+    faculty_id = Column('faculty_id', Integer, ForeignKey('faculty.id'))
+
+
 class DepartmentList(grok.View):
+    grok.name('index')
     grok.context(Faculty)
+
     def render(self):
-        result = ""
+        result = "Faculty: %s - %s " % (self.context.id, self.context.title)
         for department in self.context.departments.values():
             result += department.title + '\n'
         return result



More information about the Checkins mailing list