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

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

A large number of small modifications to browse
dealing with a range of bugs ...

Line 
1from Utilities import wrapGetText
2from ETxmlView import nsdumb
3from htmlUtilities import *
4
5class Name:
6        ''' Handles the name type in MOLES '''
7        def __init__(self,element):
8                if element is None:
9                        self.name=''
10                        return
11                if wrapGetText(element,'nameOrder')=='L2R':
12                        o=('title','initials','familyName')
13                else:
14                        o=('title','familyName','personalName')
15                self.name=''
16                for i in o: self.name+=' '+ wrapGetText(element,i)
17        def __str__(self):
18                return self.name
19       
20       
21class contact:
22        ''' Handles the basic content for a person or organisation '''
23        def __init__(self):
24            ''' Instantiates a basic contact and html to represent it. Here, for
25            presentation purposes we assume that a contact consists of
26               personName (for a person can be a name or a role holder description or both)
27               personEmail addresss (for a person)
28               personPhone (number for a person)
29               searchlink (to search something on things by this contact)
30               orgName (organisation name)
31               orgURL
32                 ... for presentation we figure further org contacts can be found by following the link which ought to exist) '''
33            self.data={'personName':'','personEmail':'','personPhone':'','orgURL':'','orgName':'','searchlink':''}
34        def toHTML(self,prefix=''):
35            if self.elem is None: return ''
36            html=prefix #para start?
37            if self.data['personName']!='':
38                if self.data['personEmail']!='':
39                    html+=hyperlink(self.data['personName'],self.data['personEmail'])
40                if self.data['personPhone']!='': html+='<br/>Phone: %s'%self.data['personPhone']
41            br=''
42            if html!='': br='<br/>' #only need a linebreak if there is already content ... or '<p>
43            if self.data['orgName']!='':
44                html+=br+hyperlink(self.data['orgName'],self.data['orgURL'])
45            if self.data['searchlink']!='': html+='<br/>'+self.data['searchlink']
46            html+='' # para end?
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                contact.__init__(self)
58                if self.elem is None: return
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',helper=None):
71        if helper is None: helper=nsdumb()
72        self.elem=elem
73        contact.__init__(self)
74        if self.elem is None: return
75        if ctype=='centre':
76            self.data['orgName']=helper.getText(self.elem,'Data_Center_Name/Short_Name')
77            self.data['orgURL']=helper.getText(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.