Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 377

Show
Ignore:
Timestamp:
01/06/07 20:31:55
Author:
fumanchu
Message:

Renamed Unit.adjust to Unit.update and made it safer. Also enhanced error messages in Unit.add.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/units.py

    r376 r377  
    666666    indices = classmethod(indices) 
    667667     
    668     def adjust(self, **values): 
    669         """Set UnitProperties by key, value kwargs.""" 
     668    def update(self, **values): 
     669        """Modify this Unit's property values (via keyword arguments). 
     670         
     671        The keyword arguments you supply will be checked against this 
     672        Unit's known properties; only known properties will be updated. 
     673        This keeps applications which accept arbitrary parameters safer. 
     674        """ 
    670675        for key, val in values.iteritems(): 
    671             setattr(self, key, val) 
     676            if key in self.properties: 
     677                setattr(self, key, val) 
    672678     
    673679     
     
    715721                ua = cls._associations[unit.__class__.__name__] 
    716722            except KeyError: 
    717                 msg = "'%s' is not associated with '%s'" % (cls, unit.__class__) 
     723                msg = "%r is not associated with %r" % (cls, unit.__class__) 
    718724                raise errors.AssociationError(msg) 
    719725             
     
    722728            if nearval is None: 
    723729                if farval is None: 
    724                     raise errors.AssociationError("At least one Unit key must be set.") 
     730                    msg = ("%r and %r could not be related, since neither " 
     731                           "has an ID yet. Memorize the parent Unit before " 
     732                           "calling unitA.add(unitB)." % (self, unit)) 
     733                    raise errors.AssociationError(msg) 
    725734                else: 
    726735                    setattr(self, ua.nearKey, farval)