source: TI07-MOLES/trunk/PythonCode/wsgi/htmlUtilities.py @ 2386

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/PythonCode/wsgi/htmlUtilities.py@2522
Revision 2386, 1.5 KB checked in by lawrence, 13 years ago (diff)

Improvements in date and person handling.

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,'','Unknown']: return ''
47    t=string.split('-')
48    if len(t)==3:
49        return '%s<br/>%s-%s'%tuple(t)
50    else:
51        return t
Note: See TracBrowser for help on using the repository browser.