source: ndgCommon/trunk/ndg/common/src/models/People.py @ 4793

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

Checking in initial codebase for ndgUtils restructure.

Line 
1'''
2Handles the basic content for a person or organisation
3'''
4from ndg.common.src.lib.utilities import wrapGetText
5from ndg.common.src.lib.ETxmlView import nsdumb
6from ndg.common.src.lib.htmlUtilities import *
7
8class Name:
9        ''' Handles the name type in MOLES '''
10        def __init__(self,element):
11                if element is None:
12                        self.name=''
13                        return
14                if wrapGetText(element,'nameOrder')=='L2R':
15                        o=('title','initials','familyName')
16                else:
17                        o=('title','familyName','personalName')
18                self.name=''
19                for i in o: self.name+=' '+ wrapGetText(element,i)
20        def __str__(self):
21                return self.name
22       
23       
24class contact:
25        ''' Handles the basic content for a person or organisation '''
26        def __init__(self):
27            ''' Instantiates a basic contact and html to represent it. Here, for
28            presentation purposes we assume that a contact consists of
29               personName (for a person can be a name or a role holder description or both)
30               personEmail addresss (for a person)
31               personPhone (number for a person)
32               searchlink (to search something on things by this contact)
33               orgName (organisation name)
34               orgURL
35                 ... for presentation we figure further org contacts can be found by following the link which ought to exist) '''
36            self.data={'personName':Name(None),'personEmail':'','personPhone':'','orgURL':'','orgName':'','searchlink':''}
37        def toHTML(self,prefix=''):
38            #print self.data
39            if self.elem is None: return 'Unknown'
40            html=prefix #para start?
41            if self.data['personName'].name!='':
42                if self.data['personEmail']!='':
43                    html+=hyperlink(self.data['personName'].name,self.data['personEmail'])
44                else:
45                    html+=self.data['personName'].name
46            br=''
47            if html!='': br='<br/>' #only need a linebreak if there is already content ... or '<p>
48            if self.data['orgName']!='':
49                html+=br+hyperlink(self.data['orgName'],self.data['orgURL'])
50            if self.data['personPhone']!='': html+='<br/>Phone: %s'%self.data['personPhone']
51            if self.data['searchlink']!='': html+='<br/>'+self.data['searchlink']
52            html+='' # para end?
53            return html
54       
55       
56class dgContact(contact):
57        '''A simple summary of contact information for an organisation or a person '''
58        #want to contract organisations and people into one simple type here ...
59        #This is moles 1.2.3 ... hopefully we can improve this ...
60        def __init__(self,element,ctype='organisation'):
61                ''' Instantiate a MOLES contact element '''
62                self.elem=element
63                contact.__init__(self)
64                if self.elem is None: return
65                self.data['personName']=Name(self.elem.find('dgRoleHolder/dgPerson/name'))
66                if ctype=='organisation':
67                        base='dgRoleHolder/organisation/'
68                else:
69                        base='dgRoleHolder/dgPerson/'
70                self.data['orgName']=wrapGetText(self.elem,base+'name')
71                self.data['personEmail']=wrapGetText(self.elem,base+'contactDetails/eMail')
72                self.data['personPhone']=wrapGetText(self.elem,'contactDetails/telephone')
73                self.data['orgURL']=wrapGetText(self.elem,'contactDetails/URI')
74       
75class DIFcontact(contact):
76    def __init__(self,elem,ctype='centre',helper=None):
77        if helper is None: helper=nsdumb()
78        self.elem=elem
79        contact.__init__(self)
80        if self.elem is None: return
81        if ctype=='centre':
82            self.data['orgName']=helper.getText(self.elem,'Data_Center_Name/Short_Name')
83            self.data['orgURL']=helper.getText(self.elem,'Data_Center_URL')
84        else:
85            self.data['personName'].name='Placeholder'
86           
87           
88class DIFAuthors:
89    ''' Attempt to get dataset authorship information from a DIF '''
90    def __init__(self,elem,helper=None):
91        if helper is None: helper=nsdumb()
92        # first try for an investigator in the personnel section
93        authors=['Investigator','Dataset_Creator','Dataset_Author']
94        people=helper.findall(elem,'Personnel')
95        a,e='',''
96        people=helper.findall(elem,'Personnel')
97        for p in people:
98            role=helper.getText(p,'Role')
99            if role=='Investigator':
100                a+='%s, %s;'%(helper.getText(p,'Last_Name'),helper.getText(p,'First_Name'))
101                e=helper.getText(p,'Email')
102        if a!='':a=a[0:-1]
103        if a=='':
104            # carry on looking in the citation element instead
105            a=helper.getText(elem,'Data_Set_Citation/Dataset_Creator')
106        self.authors,self.email=a,e
107    def __str__(self):
108        return self.authors
109   
110           
111           
Note: See TracBrowser for help on using the repository browser.