source: TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/htmlUtilities.py @ 3800

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/htmlUtilities.py@3800
Revision 3800, 1.5 KB checked in by cbyrom, 11 years ago (diff)

Upgraded version of ingest codebranch - including major refactoring of the ingest
scripts to make more OO - allowing re-use and simplification of code + removal of reliance
on eXist DB to store data; this will now all be stored and looked up from the Postgres DB

Line 
1#
2# This is a collection of template utilities for producing html
3#
4class selector:
5    ''' Provides a selection icon to add a dataset to a selector box '''
6    def __init__(self,baseURL,arg,icon):
7        self.baseURL=baseURL
8        self.argument=arg
9        self.icon=icon
10    def target(self,id,name=None):
11        url='%s&%s=%s'%(self.baseURL,self.argument,id)
12        if name is not None: url+='&name=%s'%name
13        return hyperlink(image(self.icon,self.argument),url)
14
15def span(x,id):
16    return '<span class="%s">%s</span>'%(id,x)
17
18def hyperlink(n,u,t=None):
19    ''' Make a hyperlink ... provided there is an address to jump to '''
20    if u !='':
21        if t is None:
22            return '<a href="%s">%s</a>'%(u,n)
23        else:
24            return '<a href="%s" title="%s">%s</a>'%(u,n,t)
25    else: return n
26   
27def image(l,a,t=None):
28    if t is None:
29        return '<img src="%s" alt="%s"/>'%(l,a)
30    else:
31        return '<img src="%s" alt="%s" title="%s"/>'%(l,a,t)
32
33def abbreviate(string,newlen):
34    ''' We want to ensure that a particular block of text does not exceed
35        a specific length - and finishes on a word boundary. '''
36    if len(string)< newlen:
37        return string
38    else:
39        r=''
40        for w in string[0:newlen].split(' ')[:-1]:r+='%s '%w
41        r+=' ...'
42        return r
43       
44def htmlTime(string):
45    ''' Take a yyyy-mm-dd and turn into two line html '''
46    if string in [None,'']: return ''
47    t=string.split('-')
48    return '%s<br/>%s-%s'%tuple(t)
49   
Note: See TracBrowser for help on using the repository browser.