source: exist/trunk/python/ndgUtils/models/Deployment.py @ 4440

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/python/ndgUtils/models/Deployment.py@4440
Revision 4440, 2.5 KB checked in by cbyrom, 13 years ago (diff)

Create new model, Deployment, to hold deployments info - for easy use
with templates. Delete the moles deployments code and implement code
with the new model + add containers in Atom - to allow deployments data
specified in links to be looked up.

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