source: ndgCommon/trunk/ndg/common/src/models/codetabletype.py @ 5083

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

Extend VocabServerClient? adding method to retrieve info on a specified
vocab list. Create new data model, CodeTableType? to model the
returned info + simplify setting up object from ET by iterating over object slots + update and add new tests for new functionality.

Line 
1'''
2 Class representing vocab list info - the individual terms in these lists are
3 represented as code table types
4 
5 @author: C Byrom, Tessella Feb 2009
6'''
7from xml.etree import cElementTree as ET
8import logging
9from ndg.common.src.models.ndgObject import ndgObject
10
11class CodeTableType(object):
12 
13    __slots__ = ['listKey', 'listLongName', 'listShortName', 'listDefinition',
14                 'listVersion', 'listLastMod']
15    def __init__(self, et = None):
16        '''
17        Constructor - initialise the code table type variables
18        '''
19        logging.info("Initialising CodeTableType")
20        for att in self.__slots__:
21            setattr(self, att, '')
22
23        if et:
24            self.fromET(et)
25        logging.info("CodeTableType initialised")     
26
27
28    def fromET(self, tree):
29        '''
30        Initialise CodeTableType data using an elementtree
31        @param tree: ElementTree with vocab list data
32        '''
33        logging.info("Ingesting data from ElementTree object")
34       
35        for att in self.__slots__:
36            setattr(self, att, tree.findtext('{%s}%s' %(ndgObject.VOCAB_NS, att)))
37        logging.info("Data ingested from tree")
38       
39       
Note: See TracBrowser for help on using the repository browser.