source: ndgCommon/trunk/ndg/common/src/models/vocablist.py @ 5058

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

Extend vocabserver client, providing a method to retrieve a vocab list
+ add new data models to handle the returned info + update interface
details and usage + add new file utility method for creating
directories + extend tests.

Line 
1'''
2 Class representing vocab list data - with access methods for the different records
3 
4 @author: C Byrom, Tessella Feb 2009
5'''
6from xml.etree import cElementTree as ET
7import logging 
8from ndg.common.src.lib.utilities import escapeSpecialCharacters
9from ndg.common.src.models.ndgObject import ndgObject
10from ndg.common.src.models.codetablerecord import CodeTableRecord
11from ndg.common.src.lib.utilities import httpify
12
13class VocabList(object):
14   
15    def __init__(self, et = None):
16        '''
17        Constructor - initialise the atom variables
18        '''
19        logging.info("Initialising VocabList")
20
21        # an array of CodeTableRecord objects
22        self.records = []
23
24        # error messages associated with the list retrieval
25        self.error = None
26       
27        self.url = None
28       
29        self.name = None
30       
31        # these are the users who can edit this list
32        self.userIDs = []
33
34        if et:
35            self.fromET(et)
36        logging.info("VocabList initialised")     
37
38
39    def fromET(self, tree):
40        '''
41        Initialise VocabList data using an elementtree
42        @param tree: ElementTree with vocab list data
43        '''
44        logging.info("Ingesting data from ElementTree object")
45        recordElements = tree.findall('{%s}codeTableRecord' %ndgObject.VOCAB_NS)
46       
47        self.records = []
48        for record in recordElements:
49            self.records.append(CodeTableRecord(et = record))
50
51        self.error = tree.findtext('{%s}error' %ndgObject.VOCAB_NS)
52        logging.info("Data ingested from tree")
53
54
55    def setData(self, url, name, userIDs):
56        '''
57        Set data on the vocab list data model
58        @param url: the url corresponding to the vocab term list
59        @param name: the name of the list
60        @param userIDs: a list of userIDs - mapping to the users that can
61        edit entries in this list 
62        '''
63        logging.debug("Setting data on VocabList:\nurl = %s \nname = %s \nuserIDs = %s"
64                      %(url, name, userIDs))
65        self.url = httpify(url)
66        self.name = name
67        self.userIDs = userIDs
68        logging.debug("Finished setting data on VocabList")
Note: See TracBrowser for help on using the repository browser.