source: ndgCommon/trunk/ndg/common/src/models/AtomState.py @ 4935

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

Update the models to use the new client suite + add new ndgObject var:
ASSOCIATED_ATOM_DOC_TYPE - to cope with the looking up of associated metadata.

Line 
1'''
2 Class representing publication state of moles atom document
3 
4 @author: C Byrom, Tessella Jan 2009
5'''
6import logging
7import ndg.common.src.clients.xmldb.eXist.dbconstants as dc
8
9# flags to specify published state of atom
10OLD_STATE_FLAG = 1
11WORKING_STATE_FLAG = 2
12SMALL_P_PUBLISHED_STATE_FLAG = 4
13PUBLISHED_STATE_FLAG = 8
14EITHER_PUBLISHED = SMALL_P_PUBLISHED_STATE_FLAG + PUBLISHED_STATE_FLAG
15
16# dict to store all atomStates for easy access
17allStates = {}
18
19# array to store atomeStates in a format for easy use with setting up
20# drop down lists
21selectList = []
22
23def getAtomState(flag):
24    '''
25    Get the atom state object representing the state flag
26    @param flag: one of the STATE_FLAG variables
27    @return: AtomState object representing the specified state flag
28    '''
29    if isinstance(flag, str) or isinstance(flag, unicode):
30        # try to convert string into int - NB, flags may be translated into
31        # strings, e.g. by web interfaces passing these vals around
32        flag = int(flag)
33           
34    if allStates.has_key(flag):
35        return allStates[flag]
36   
37    raise ValueError("Unrecognised atom state flag, '%s'" %str(flag))
38
39class AtomState(object):
40
41    def __init__(self, stateFlag, title, collectionPath):
42        '''
43        Constructor - initialise the atom state variables
44        '''
45        logging.debug("Initialising atom state object")
46        self.stateFlag = stateFlag
47        self.title = title
48        self.collectionPath = collectionPath
49        allStates[self.stateFlag] = self
50        selectList.append([self.title, self.stateFlag])
51        logging.info("Atom state initialised")
52
53   
54    def isPublishedState(self):
55        '''
56        Check state - if published or Published return True,
57        otherwise return False
58        '''
59        if bool(self.stateFlag & EITHER_PUBLISHED):
60            return True
61        return False
62
63OLD_STATE = AtomState(OLD_STATE_FLAG, 'Old', dc.OLD_COLLECTION_PATH)
64WORKING_STATE = AtomState(WORKING_STATE_FLAG, 'Working', dc.WORKING_COLLECTION_PATH)
65SMALL_P_PUBLISHED_STATE = AtomState(SMALL_P_PUBLISHED_STATE_FLAG, 'published', 
66                                    dc.SMALL_P_PUBLISHED_COLLECTION_PATH)
67PUBLISHED_STATE = AtomState(PUBLISHED_STATE_FLAG, 'Published',
68                            dc.PUBLISHED_COLLECTION_PATH)
Note: See TracBrowser for help on using the repository browser.