Ignore:
Timestamp:
22/09/08 11:29:49 (11 years ago)
Author:
cbyrom
Message:

Add cmp method to DeploymentLink? to allow for object equality tests +
add new method to MolesEntity? to ensure that only unique deployment
links are added to the helper arrays + add new constructor input to
Atom to allow the content to be defined at creation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/models/MolesEntity.py

    r4209 r4214  
    4444        logging.info("ElementTree version of Deployment element link created") 
    4545        return link 
    46              
    47  
     46 
     47    def __cmp__(self, link): 
     48        logging.debug("Comparing link objects") 
     49        if isinstance(link, DeploymentLink): 
     50            if link.url == self.url and \ 
     51                link.vocabUrl == self.vocabUrl and \ 
     52                link.title == self.title: 
     53                logging.debug("- links are equal") 
     54                return 0 
     55 
     56        logging.debug("- links are not equal") 
     57        return 1 
     58     
    4859class Deployments(object): 
    4960     
     
    166177 
    167178        logging.info(VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL) 
    168         if vocabURL.startswith(VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL) and \ 
    169             vocabURL not in self.activities: 
    170             self.activities.append(deploymentLink) 
    171         elif vocabURL.startswith(VTD.TERM_DATA[VTD.OBS_TERM].vocabURL) and \ 
    172             vocabURL not in self.obs: 
    173             self.obs.append(deploymentLink) 
    174         elif vocabURL.startswith(VTD.TERM_DATA[VTD.DPT_TERM].vocabURL) and \ 
    175             vocabURL not in self.dpts: 
    176             self.dpts.append(deploymentLink) 
     179        self._addDeploymentDetails(deploymentLink) 
    177180 
    178181        if deploymentID not in self.deployments: 
     
    185188 
    186189        logging.info("New deployment link data added to moles entity") 
    187          
     190 
     191         
     192    def _addDeploymentDetails(self, deploymentLink): 
     193        ''' 
     194        Add deployment details to local arrays for easy access by templates 
     195        ''' 
     196        deploymentType = None 
     197        # first, determine type of deployment 
     198        if deploymentLink.vocabUrl.startswith(VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL): 
     199            deploymentType = self.activities 
     200        elif deploymentLink.vocabUrl.startswith(VTD.TERM_DATA[VTD.OBS_TERM].vocabURL): 
     201            deploymentType = self.obs 
     202        elif deploymentLink.vocabUrl.startswith(VTD.TERM_DATA[VTD.DPT_TERM].vocabURL): 
     203            deploymentType = self.dpts 
     204        else: 
     205            return 
     206 
     207        # Now check if this has already been added; return if so 
     208        for link in deploymentType: 
     209            if link == deploymentLink: 
     210                return 
     211 
     212        deploymentType.append(deploymentLink) 
     213 
    188214         
    189215    def toXML(self): 
Note: See TracChangeset for help on using the changeset viewer.