source: ndgCommon/trunk/ndg/common/src/models/Deployment.py @ 4935

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/src/models/Deployment.py@5136
Revision 4935, 2.6 KB checked in by cbyrom, 11 years ago (diff)

Update the models to use the new client suite + add new ndgObject var:
ASSOCIATED_ATOM_DOC_TYPE - to cope with the looking up of associated metadata.

Line 
1'''
2 Class representing data in  atom format - allowing moles data to be stored and accessed in a web feed compatible way
3 
4 @author: C Byrom, Tessella Jun 2008
5'''
6import logging
7from ndg.common.src.models.vocabtermdata import VocabTermData as VTD
8
9
10class Deployment(object):
11    '''
12    Class representing deployment data - used to simplify the display of
13    deployments data in the genshi templates
14    '''
15   
16    def __init__(self, deploymentAtom):
17        '''
18        Constructor - initialise the deployment object
19        '''
20        logging.debug("Creating Deployment object")
21        self.activities = []
22        self.obs = []
23        self.dpts = []
24       
25        # add the deployment info appropriately
26        for link in deploymentAtom.relatedLinks:
27            self.__processDeploymentLink(link)
28
29        self.startDate = deploymentAtom.t1
30        self.endDate = deploymentAtom.t2
31        self.browseURL = deploymentAtom.atomBrowseURL
32        self.title = deploymentAtom.title
33        logging.debug("Deployment created")
34
35       
36    def __processDeploymentLink(self, deploymentLink):
37        '''
38        Given a Link object, add the data to the correct collection
39        @param deploymentLink: a Link object with deployment data
40        '''
41        logging.debug("Adding deployment link info")
42        deploymentType = None
43        # first, determine type of deployment - NB, ignore the data if it is
44        # not an activity/observation station/deployment tool
45        if deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL):
46            deploymentType = self.activities
47        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.OBS_TERM].vocabURL):
48            deploymentType = self.obs
49        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.DPT_TERM].vocabURL):
50            deploymentType = self.dpts
51        else:
52            logging.debug("Not a valid deployment type (%s) - ignoring" \
53                          %deploymentLink.rel)
54            return
55
56        # Now check if this has already been added; return if so
57        for link in deploymentType:
58            if link == deploymentLink:
59                logging.debug("- info already included - ignoring")
60                return
61
62        deploymentType.append(deploymentLink)
63        logging.debug("- deployment link info added")
64
65   
66    def getAllLinks(self):
67        '''
68        Utility method to return all link data in one call
69        @return list: with all activity, obs and dpt links
70        '''
71        data = []
72        data.extend(self.activities)
73        data.extend(self.obs)
74        data.extend(self.dpts)
75        return data
76       
Note: See TracBrowser for help on using the repository browser.