Changeset 5082 for ndgCommon/trunk


Ignore:
Timestamp:
09/03/09 10:15:10 (11 years ago)
Author:
cbyrom
Message:

Add new method to VocabList? model to retrieve specified vocab terms
from list + add additional fields for editors and newsgroup emails - to
group related info for the vocab term editor + add new test class to
exercise the data model.

Location:
ndgCommon/trunk/ndg/common
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/models/vocablist.py

    r5058 r5082  
    55''' 
    66from xml.etree import cElementTree as ET 
    7 import logging  
     7import logging 
    88from ndg.common.src.lib.utilities import escapeSpecialCharacters 
    99from ndg.common.src.models.ndgObject import ndgObject 
     
    1515    def __init__(self, et = None): 
    1616        ''' 
    17         Constructor - initialise the atom variables 
     17        Constructor - initialise the vocab list variables 
    1818        ''' 
    1919        logging.info("Initialising VocabList") 
     
    2626         
    2727        self.url = None 
    28          
    2928        self.name = None 
     29        self.newsgroupEmail = '' 
    3030         
    3131        # these are the users who can edit this list 
    32         self.userIDs = [] 
     32        self.editors = [] 
    3333 
    3434        if et: 
     
    4949            self.records.append(CodeTableRecord(et = record)) 
    5050 
     51        # NB, can get the list URL from one of its terms 
     52        if self.records: 
     53            self.url = self.records[0].listKey 
     54             
    5155        self.error = tree.findtext('{%s}error' %ndgObject.VOCAB_NS) 
    5256        logging.info("Data ingested from tree") 
    5357 
    5458 
    55     def setData(self, url, name, userIDs): 
     59    def setData(self, url, name, editors = [], newsgroupEmail = None): 
    5660        ''' 
    5761        Set data on the vocab list data model 
    5862        @param url: the url corresponding to the vocab term list 
    5963        @param name: the name of the list 
    60         @param userIDs: a list of userIDs - mapping to the users that can 
     64        @keyword editors: a list of editors - mapping to the users that can 
     65        @keyword newsgroupEmail: email of the news group associated with the vocab list 
    6166        edit entries in this list   
    6267        ''' 
    63         logging.debug("Setting data on VocabList:\nurl = %s \nname = %s \nuserIDs = %s" 
    64                       %(url, name, userIDs)) 
     68        logging.debug("Setting data on VocabList:\nurl = %s \nname = %s \neditors = %s" 
     69                      %(url, name, editors)) 
    6570        self.url = httpify(url) 
    6671        self.name = name 
    67         self.userIDs = userIDs 
     72        self.editors = editors 
     73        self.newsgroupEmail = newsgroupEmail 
    6874        logging.debug("Finished setting data on VocabList") 
     75         
     76         
     77    def getVocabTermDataByEntryKey(self, entryKey): 
     78        ''' 
     79        Retrieve vocab data in vocab list with matching entryKey.  If not 
     80        found, raise an exception - since we should be using the list as the 
     81        starting point for data retrieval 
     82        @param entryKey: entry key of vocab term - this is usually the URL 
     83        to the term - e.g. 'http://vocab.ndg.nerc.ac.uk/term/P021/37/CDTA' 
     84        @raise ValueError: if term not found 
     85        @return: CodeTableRecord relating to the vocab term data   
     86        ''' 
     87        logging.debug("Looking up vocab term, '%s'" %entryKey) 
     88        for record in self.records: 
     89            if record.entryKey == entryKey: 
     90                logging.debug("- returning vocab term details") 
     91                return record 
     92             
     93        raise ValueError("Vocab term, '%s' not found in vocab list" %entryKey) 
Note: See TracChangeset for help on using the changeset viewer.