On Thursday 07 February 2008 14:32:09 Oleg Broytmann wrote:
> I very much hope you understand that .count() does a separate query which
> could be very expensive, and you call .count() two times!

Thank you very much for the suggestion; it's easy to change to 
len(list(selectResults)).

Any ideas for how to improve the class definition syntax for my DynamicState/ 
DynamicSQLObject?  To see the problem, below are some subclasses showing how 
they're used.  I'm trying to represent the US federal employers' tax.  These 
rules change every year, so they are well represented by DynamicState/ 
DynamicSQLObject.

As you can see, it's pretty unfortunate to keep cutting&pasting all those 
parent/stateClass/states attributes.  If anybody's got any ideas for how to 
make this syntax tighter, I'd be very much obliged.

TIA,
cs

===
class TaxRule(sqlobjectextensions.DynamicState):
    parent = sqlobject.ForeignKey('Tax', notNone=True)
    signature = ('date',)
    dontCreateTable = True
   
class Tax(sqlobjectextensions.DynamicSQLObject):
    stateClass = TaxRule
    states = sqlobject.MultipleJoin('TaxRule', joinColumn='parent_id')
    dontCreateTable = True

class FlatRateTaxRule(TaxRule):
    parent = sqlobject.ForeignKey('Tax', notNone=True)
    rate = DecimalCol(size=6, precision=5, notNone=True)
    dontCreateTable = True

class FlatRateTax(sqlobjectextensions.DynamicSQLObject):
    stateClass = FlatRateTaxRule
    states = sqlobject.MultipleJoin('FlatRateTaxRule', joinColumn='parent_id')
    dontCreateTable = True

class MedicareRule(FlatRateTaxRule):
    parent = sqlobject.ForeignKey('Medicare', notNone=True)
    
class Medicare(FlatRateTax):
    stateClass = MedicareRule
    states = sqlobject.MultipleJoin('MedicareRule', joinColumn='parent_id')

class FlatRateTaxWithCeilingRule(FlatRateTaxRule):
    ceiling = CurrencyCol(notNone=True)
    ceilingPeriod = ForeignKey('Periodicity', notNone=True)
    dontCreateTable = True

class FlatRateTaxWithCeiling(FlatRateTax):
    stateClass = FlatRateTaxWithCeilingRule
    states = sqlobject.MultipleJoin('FlatRateTaxWithCeilingRule', 
joinColumn='parent_id')
    dontCreateTable = True

class SocialSecurityRule(FlatRateTaxWithCeilingRule):
    parent = sqlobject.ForeignKey('SocialSecurity', notNone=True)

class SocialSecurity(FlatRateTax):
    stateClass = SocialSecurityRule
    states = sqlobject.MultipleJoin('SocialSecurityRule', 
joinColumn='parent_id')
    
class FutaRule(FlatRateTaxWithCeilingRule):
    parent = sqlobject.ForeignKey('Futa', notNone=True)

class Futa(FlatRateTaxWithCeiling):
    stateClass = FutaRule
    states = sqlobject.MultipleJoin('FutaRule', joinColumn='parent_id')
    
class EmployeeIncomeTaxRule(TaxRule):
    parent = sqlobject.ForeignKey('EmployeeIncomeTax', notNone=True)
    married = BoolCol(notNone=True)
    payrollPeriod = ForeignKey('Periodicity', notNone=True)
    minWage = CurrencyCol(notNone=True)
    maxWage = CurrencyCol(notNone=True)
    baseWithholding = CurrencyCol(notNone=True)
    excessRate = DecimalCol(size=5, precision=4, notNone=True)
    signature = ('married', 'payrollPeriod', 'date')
    dontCreateTable = True

class EmployeeIncomeTax(Tax):
    stateClass = EmployeeIncomeTaxRule
    states = sqlobject.MultipleJoin('EmployeeIncomeTaxRule', 
joinColumn='parent_id')
    dontCreateTable = True

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to