source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/People.py @ 938

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/People.py@938
Revision 938, 3.4 KB checked in by lawrence, 14 years ago (diff)

First code to support a GUI for python based searching through the
discovery WS interface. Includes some refactoring of the browse code
to support multiple entities (i.e. DIF etc). (NB: browse still
wont work properly until we get the security stuff working ok).

Line 
1from Utilities import wrapGetText
2class Name:
3        ''' Handles the name type in MOLES '''
4        def __init__(self,element):
5                if element is None:
6                        self.name=''
7                        return
8                if wrapGetText(element,'nameOrder')=='L2R':
9                        o=('title','initials','familyName')
10                else:
11                        o=('title','familyName','personalName')
12                self.name=''
13                for i in o: self.name+=' '+ wrapGetText(element,i)
14        def __str__(self):
15                return self.name
16       
17       
18class contact:
19        ''' Handles the basic content for a person or organisation '''
20        def __init__(self):
21            ''' Instantiates a basic contact and html to represent it. Here, for
22            presentation purposes we assume that a contact consists of
23               personName (for a person can be a name or a role holder description or both)
24               personEmail addresss (for a person)
25               personPhone (number for a person)
26               searchlink (to search something on things by this contact)
27               orgName (organisation name)
28               orgURL
29                 ... for presentation we figure further org contacts can be found by following the link which ought to exist) '''
30            self.data={'personName':'','personEmail':'','personPhone':'','orgURL':'','orgName':'','searchlink':''}
31        def tohtml(self,prefix=''):
32            if self.elem is None: return ''
33            def makelink(r,n):
34                if r!='':
35                    return '<a href="%s%>%s</a>'%(a,b)
36                else: return n
37            html='<p>'+prefix
38            if self.data['personName']!='':
39                if self.data['personEmail']!='':
40                    html+=makelink(self.data['personEmail'],self.data['personName'])
41                if self.data['personPhone']!='': html+='<br/>Phone: %s'%self.data['personPhone']
42            br=''
43            if html!='<p>': br='<br/>' #only need a linebreak if there is already content ...
44            if self.data['orgName']!='':
45                    html+=br+makelink(self.data['orgURL'],self.data['orgName'])
46            if self.data['searchlink']!='': html+='<br/>'+self.data['searchlink']
47            return html
48       
49       
50class dgContact(contact):
51        '''A simple summary of contact information for an organisation or a person '''
52        #want to contract organisations and people into one simple type here ...
53        #This is moles 1.2.3 ... hopefully we can improve this ...
54        def __init__(self,element,ctype='organisation'):
55                ''' Instantiate a MOLES contact element '''
56                self.elem=element
57                if self.elem is None: return
58                contact.__init__(self)
59                self.data['personName']=Name(self.elem.find('dgRoleHolder/dgPerson/name'))
60                if ctype=='organisation':
61                        base='dgRoleHolder/dgOrganisation/'
62                else:
63                        base='dgRoleHolder/dgPerson/'
64                self.data['orgName']=wrapGetText(self.elem,base+'name')
65                self.data['personEmail']=wrapGetText(self.elem,base+'contactDetails/eMail')
66                self.data['personPhone']=wrapGetText(self.elem,'contactDetails/telephone')
67                self.data['orgURL']=wrapGetText(self.elem,'contactDetails/URI')
68       
69class DIFcontact(contact):
70    def __init__(self,elem,ctype='centre'):
71        self.elem=elem
72        if self.elem is None: return
73        contact.__init__(self)
74        if ctype=='centre':
75            self.data['orgName']=wrapGetText(self.elem,'Data_Center_Name/Short_Name')
76            self.data['orgURL']=wrapGetText(self.elem,'Data_Center_URL')
77        else:
78            self.data['personName']='placeholder for DIF contact'
Note: See TracBrowser for help on using the repository browser.