Author: phd
Date: 2007-01-17 07:57:43 -0700 (Wed, 17 Jan 2007)
New Revision: 2216
Removed:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_encapsulate_hiding.py
Modified:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
home/phd/SQLObject/paramstyles/sqlobject/versioning/test/test_version.py
Log:
Merged patches from the revisions 2213:2215 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2007-01-17 14:56:19 UTC (rev 2215)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2007-01-17 14:57:43 UTC (rev 2216)
@@ -1,6 +1,6 @@
from sqlobject import sqlbuilder
from sqlobject import classregistry
-from sqlobject.col import StringCol, ForeignKey, BoolCol
+from sqlobject.col import StringCol, ForeignKey
from sqlobject.main import sqlmeta, SQLObject, SelectResults, True, False, \
makeProperties, getterName, setterName
import iteration
@@ -63,12 +63,6 @@
parentClause.append(currentClass.q.id == parentClass.q.id)
currentClass = parentClass
tablesDict[currentClass.sqlmeta.table] = 1
-
- for (currentClass, minParentClass) in tableRegistry.items():
- if InheritableSQLObject in minParentClass.__bases__:
- parentClause.append(minParentClass.q.doneConstructing == True)
- break
-
clause = reduce(sqlbuilder.AND, parentClause, clause)
super(InheritableSelectResults, self).__init__(sourceClass,
@@ -198,7 +192,7 @@
currentClass = cls.sqlmeta.parentClass
while currentClass:
for column in currentClass.sqlmeta.columnDefinitions.values():
- if column.name == 'doneConstructing' or column.name == 'childName':
+ if column.name == 'childName':
continue
if type(column) == ForeignKey:
continue
@@ -296,12 +290,6 @@
sqlmeta.addColumn(StringCol(name='childName',
# limit string length to get VARCHAR and not CLOB
length=255, default=None))
-
- #only on top-level classes
- if InheritableSQLObject in cls.__bases__:
- #add the doneConstructing column to make half-constructed tasks invisible
- sqlmeta.addColumn(BoolCol(name='doneConstructing', default=False))
-
if not sqlmeta.columnList:
# There are no columns - call addColumn to propagate columns
# from parent classes to children
@@ -312,7 +300,7 @@
sqlmeta.addJoin(None)
_notifyFinishClassCreation = classmethod(_notifyFinishClassCreation)
- def _create(self, id, last_derived=False, **kw):
+ def _create(self, id, **kw):
#DSM: If we were called by a children class,
#DSM: we must retreive the properties dictionary.
@@ -343,7 +331,7 @@
raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, col.name)
parent_kw['childName'] = self.sqlmeta.childName
- self._parent = parentClass(last_derived=False, kw=parent_kw,
+ self._parent = parentClass(kw=parent_kw,
connection=self._connection)
id = self._parent.id
Deleted: home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_encapsulate_hiding.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_encapsulate_hiding.py 2007-01-17 14:56:19 UTC (rev 2215)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_encapsulate_hiding.py 2007-01-17 14:57:43 UTC (rev 2216)
@@ -1,48 +0,0 @@
-from py.test import raises
-from sqlobject import *
-from sqlobject.tests.dbtest import *
-from sqlobject.inheritance import InheritableSQLObject
-
-def first_position():
- employees = Employee.select()
- if employees.count():
- return employees[0].position
- else:
- return "Lackey"
-
-def first_floor():
- janitors = Janitor.select()
- if janitors.count():
- return janitors[0].floor
- else:
- return 0
-
-
-class InheritablePerson(InheritableSQLObject):
- firstName = StringCol()
- lastName = StringCol(alternateID=True, length=255)
-
-class Employee(InheritablePerson):
- position = StringCol(default=first_position)
-
-class Janitor(Employee):
- _inheritable = False
- floor = IntCol(default=first_floor)
-
-def setup():
- setupClass(InheritablePerson)
- setupClass(Employee)
- setupClass(Janitor)
-
-def test_liveness():
-
- setup()
- emp = Employee(firstName='Igor', lastName='Humpback')
- assert emp.position == "Lackey"
- emp.position = "Grunt"
-
- emp = Employee(firstName='Frank', lastName='Furter')
- assert emp.position == "Grunt"
-
- jan = Janitor(firstName="George", lastName="Bush")
- assert jan.floor == 0
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2007-01-17 14:56:19 UTC (rev 2215)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2007-01-17 14:57:43 UTC (rev 2216)
@@ -1203,7 +1203,7 @@
else:
return joinClass.get(id)
- def __init__(self, last_derived = True, **kw):
+ def __init__(self, **kw):
# We shadow the sqlmeta class with an instance of sqlmeta
# that points to us (our sqlmeta buddy object; where the
# sqlmeta class is our class's buddy class)
@@ -1231,15 +1231,12 @@
else:
id = None
- self._create(id, last_derived=False, **kw)
-
- if last_derived and hasattr(self, 'doneConstructing'):
- self.doneConstructing = True
-
+ self._create(id, **kw)
for func in post_funcs:
func(self)
- def _create(self, id, last_derived=False,**kw):
+ def _create(self, id, **kw):
+
self.sqlmeta._creating = True
self._SO_createValues = {}
self._SO_validatorState = SQLObjectState(self)
Modified: home/phd/SQLObject/paramstyles/sqlobject/versioning/test/test_version.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/versioning/test/test_version.py 2007-01-17 14:56:19 UTC (rev 2215)
+++ home/phd/SQLObject/paramstyles/sqlobject/versioning/test/test_version.py 2007-01-17 14:57:43 UTC (rev 2216)
@@ -48,7 +48,12 @@
def setup():
- for cls in [MyClass, Base, Child, Government, Monarchy, VChild, HasForeign, Extra]:
+ classes = [MyClass, Base, Child, Government, Monarchy, VChild, Extra]
+ if hasattr(HasForeign, "_connection"):
+ classes.insert(0, HasForeign)
+ else:
+ classes.append(HasForeign)
+ for cls in classes:
if hasattr(cls, 'versions') and hasattr(cls, "_connection") and \
cls._connection.tableExists(cls.sqlmeta.table):
setupClass(cls.versions.versionClass)
|