source: TI03-DataExtractor/branches/old_stuff/dx-webservice/optionHandler.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx-webservice/optionHandler.py@793
Revision 793, 2.1 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

  • Property svn:executable set to *
Line 
1"""
2optionHandler.py
3================
4
5Holds the OptionHandler class that is used to generate available
6option lists to send to the user via whichever presentation layer
7is being used.
8
9"""
10
11# Import required modules
12import os
13import cdms
14import vcs
15import sys
16
17# Import package modules including global variables
18from common import *
19from config import *
20from datasetdb import *
21
22class OptionHandler(Datasetdb):
23    """
24    I think this should be a sub-class of Datasetdb so that you
25    wrap the functionality already in place but send it the allowed_groups
26    so that it can send back a list of everything available. Thereby taking
27    the logic out of the CGIInterface class.
28    All lists are sorted alphanumerically here before being exported to
29    other parts of the dx package.
30    """
31
32    def __init__(self, allowedGroups):
33        """
34        Method to initialise class. Calls __init__ method for parent class
35        and sets allowedGroups instance variable.
36        """
37        Datasetdb.__init__(self)
38        self.allowedGroups=allowedGroups
39   
40    def getDatasetGroupList(self):
41        """
42        Method returning a sorted list of all the dataset groups available
43        to the particular user.
44        """
45        allDatasetGroups=self.getDatasetGroups()
46        rtDatasetGroups=[]
47       
48        for dsg in allDatasetGroups.keys():
49             protectID=allDatasetGroups[dsg]
50             if protectID==None or protectID in allowedGroups: 
51                 rtDatasetGroups.append(dsg)
52                 
53        rtDatasetGroups.sort()
54        return rtDatasetGroups
55       
56    def getDatasetList(self, datasetGroup):
57        """
58        Method to return the available datasets within a given dataset group as
59        a sorted list.
60        """
61        rtDatasets=[]
62        datasetList=self.getDatasets(datasetGroup)
63        for ds in datasetList:
64            rtDatasets.append(ds[0])
65        rtDatasets.sort()
66        return rtDatasets
67       
68    def getVariableList(self, datasetGroup=None, dataset=None, datasetURI=None):
69        """
70        Method to return list of available variables for the given datasetGroup
71        and dataset/datasetURI.
72        """
73        rtVariables=self.getVariables(datasetGroup, dataset, datasetURI)
74        rtVariables.sort()
75        return rtVariables
76   
Note: See TracBrowser for help on using the repository browser.