Changeset 5169 for ndgCommon


Ignore:
Timestamp:
06/04/09 10:02:18 (10 years ago)
Author:
cbyrom
Message:

Override methods to check for object equality and inequality - for
records to improve comparisons of these.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/models/abstractrecord.py

    r5147 r5169  
    1616    CREATED_DATE = 'createdDate' 
    1717    ATTS_TO_SKIP = [CREATED_DATE, 'entryTermLastMod', 'listLastMod',  
    18                     'createdDate', 'fields'] 
     18                    'createdDate', 'fields', 'changeNote'] 
    1919     
    2020    def __init__(self, et = None, **inputs): 
     
    7676            return -1 
    7777        return 1 
     78 
     79 
     80    def __eq__(self, other): 
     81        ''' 
     82        Override object equals to check for equality.  NB, ignore the createdDate 
     83        as this is not usually important 
     84        @param other: other object with which to compare this object to 
     85        @return True if objects are equal, False otherwise 
     86        ''' 
     87        for att in self.__slots__: 
     88            if att in self.ATTS_TO_SKIP: 
     89                continue 
     90             
     91            if getattr(self, att) != getattr(other, att): 
     92                return False 
     93 
     94        return True 
     95 
     96 
     97    def __ne__(self, other): 
     98        ''' 
     99        Override object unequals to check for unequality.  NB, ignore the createdDate 
     100        as this is not usually important 
     101        @param other: other object with which to compare this object to 
     102        @return True if objects are equal, False otherwise 
     103        ''' 
     104        return not self.__eq__(other) 
     105 
    78106 
    79107    def __str__(self): 
     
    150178        logging.debug(" - returning type name, '%s'" %typeName) 
    151179        return typeName 
     180     
     181     
Note: See TracChangeset for help on using the changeset viewer.