source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browse/htmlUtilities.py @ 1173

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

Handling selection and browse history better ...

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):
19    return '<a href="%s">%s</a>'%(u,n)
20
21def image(l,a):
22    return '<img src="%s" alt="%s"/>'%(l,a)
23
24def abbreviate(string,newlen):
25    ''' We want to ensure that a particular block of text does not exceed
26        a specific length - and finishes on a word boundary. '''
27    if len(string)< newlen:
28        return string
29    else:
30        r=''
31        for w in string[0:newlen].split(' ')[:-1]:r+='%s '%w
32        r+=' ...'
33        return r
34       
35def htmlTime(string):
36    ''' Take a yyyy-mm-dd and turn into two line html '''
37    if string in [None,'']: return ''
38    t=string.split('-')
39    return '%s<br/>%s-%s'%tuple(t)
40   
Note: See TracBrowser for help on using the repository browser.