[Checkins] SVN: z3c.dobbin/trunk/src/z3c/dobbin/ Ignore concrete
class properties.
Malthe Borch
mborch at gmail.com
Tue May 27 11:45:41 EDT 2008
Log message for revision 86988:
Ignore concrete class properties.
Changed:
U z3c.dobbin/trunk/src/z3c/dobbin/README.txt
U z3c.dobbin/trunk/src/z3c/dobbin/mapper.py
-=-
Modified: z3c.dobbin/trunk/src/z3c/dobbin/README.txt
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/README.txt 2008-05-27 14:52:35 UTC (rev 86987)
+++ z3c.dobbin/trunk/src/z3c/dobbin/README.txt 2008-05-27 15:45:40 UTC (rev 86988)
@@ -152,6 +152,23 @@
>>> repr(vinyl)
'<Vinyl Diana Ross and The Supremes: Taking Care of Business (@ 45 RPM)>'
+If we're mapping a concrete class, and run into class properties, we
+won't instrument them even if they're declared by the schema.
+
+ >>> class Experimental(Vinyl):
+ ... @property
+ ... def rpm(self):
+ ... return len(self.title+self.artist)
+
+ >>> experimental = create(Experimental)
+ >>> experimental.artist = vinyl.artist
+ >>> experimental.title = vinyl.title
+
+Let's see how fast this record should be played back.
+
+ >>> experimental.rpm
+ 50
+
Relations
---------
Modified: z3c.dobbin/trunk/src/z3c/dobbin/mapper.py
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/mapper.py 2008-05-27 14:52:35 UTC (rev 86987)
+++ z3c.dobbin/trunk/src/z3c/dobbin/mapper.py 2008-05-27 15:45:40 UTC (rev 86988)
@@ -262,6 +262,8 @@
engine = component.getUtility(IDatabaseEngine)
metadata = engine.metadata
+ ignore = ('__name__',)
+
# expand specification
if interface.interfaces.IInterface.providedBy(spec):
ifaces = set([spec.get(name).interface for name in schema.getFields(spec)])
@@ -275,8 +277,8 @@
# create joined table
soup_table = table = metadata.tables['soup']
properties = {}
-
- for (t, p) in (getTable(iface, metadata) for iface in ifaces):
+
+ for (t, p) in (getTable(iface, metadata, ignore) for iface in ifaces):
table = rdb.join(table, t, onclause=(t.c.id==soup_table.c.id))
properties.update(p)
@@ -306,8 +308,15 @@
del properties[name]
setattr(Mapper, name, prop)
- orm.mapper(Mapper, table, properties=properties)
+ exclude = ()
+
+ if not interface.interfaces.IInterface.providedBy(spec):
+ for name, value in spec.__dict__.items():
+ if isinstance(value, property):
+ exclude += (name,)
+ orm.mapper(Mapper, table, properties=properties, exclude_properties=exclude)
+
spec.__mapper__ = Mapper
interface.alsoProvides(spec, IMapped)
@@ -317,7 +326,7 @@
del spec.mapper
interface.noLongerProvides(spec, IMapped)
-def getTable(iface, metadata):
+def getTable(iface, metadata, ignore=()):
columns = []
properties = {}
@@ -325,7 +334,7 @@
property_factory = None
# ignores
- if field.__name__ in ('__name__',):
+ if field.__name__ in ignore:
continue
try:
More information about the Checkins
mailing list