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

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

Checking in initial codebase for ndgUtils restructure.

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        logging.debug("Deployment created")
33
34       
35    def __processDeploymentLink(self, deploymentLink):
36        '''
37        Given a Link object, add the data to the correct collection
38        @param deploymentLink: a Link object with deployment data
39        '''
40        logging.debug("Adding deployment link info")
41        deploymentType = None
42        # first, determine type of deployment - NB, ignore the data if it is
43        # not an activity/observation station/deployment tool
44        if deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.ACTIVITY_TERM].vocabURL):
45            deploymentType = self.activities
46        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.OBS_TERM].vocabURL):
47            deploymentType = self.obs
48        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.DPT_TERM].vocabURL):
49            deploymentType = self.dpts
50        else:
51            logging.debug("Not a valid deployment type (%s) - ignoring" \
52                          %deploymentLink.vocabUrl)
53            return
54
55        # Now check if this has already been added; return if so
56        for link in deploymentType:
57            if link == deploymentLink:
58                logging.debug("- info already included - ignoring")
59                return
60
61        deploymentType.append(deploymentLink)
62        logging.debug("- deployment link info added")
63
64   
65    def getAllLinks(self):
66        '''
67        Utility method to return all link data in one call
68        @return list: with all activity, obs and dpt links
69        '''
70        data = []
71        data.extend(self.activities)
72        data.extend(self.obs)
73        data.extend(self.dpts)
74        return data
75       
Note: See TracBrowser for help on using the repository browser.