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

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

More discovery/browse convergence, starting support
for linking to services ...

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>'%(r,n)
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            html+='</p>'
48            return html
49       
50       
51class dgContact(contact):
52        '''A simple summary of contact information for an organisation or a person '''
53        #want to contract organisations and people into one simple type here ...
54        #This is moles 1.2.3 ... hopefully we can improve this ...
55        def __init__(self,element,ctype='organisation'):
56                ''' Instantiate a MOLES contact element '''
57                self.elem=element
58                contact.__init__(self)
59                if self.elem is None: return
60                self.data['personName']=Name(self.elem.find('dgRoleHolder/dgPerson/name'))
61                if ctype=='organisation':
62                        base='dgRoleHolder/dgOrganisation/'
63                else:
64                        base='dgRoleHolder/dgPerson/'
65                self.data['orgName']=wrapGetText(self.elem,base+'name')
66                self.data['personEmail']=wrapGetText(self.elem,base+'contactDetails/eMail')
67                self.data['personPhone']=wrapGetText(self.elem,'contactDetails/telephone')
68                self.data['orgURL']=wrapGetText(self.elem,'contactDetails/URI')
69       
70class DIFcontact(contact):
71    def __init__(self,elem,ctype='centre'):
72        self.elem=elem
73        contact.__init__(self)
74        if self.elem is None: return
75        if ctype=='centre':
76            self.data['orgName']=wrapGetText(self.elem,'Data_Center_Name/Short_Name')
77            self.data['orgURL']=wrapGetText(self.elem,'Data_Center_URL')
78        else:
79            self.data['personName']='placeholder for DIF contact'
Note: See TracBrowser for help on using the repository browser.