Пример #1
0
def make_links(links, value, inst):
    """
    Make new link for provided query links and passed value.
    """
    if  isinstance(value, list):
        values = value
    else:
        values = [value]
    for link in links:
        for val in values:
            if  'query' in link:
                dasquery = link['query'] % val
                uinput = urllib.quote(dasquery)
                url = '/das/request?input=%s&instance=%s&idx=0&limit=10' \
                            % (uinput, inst)
                if  link['name']:
                    key = link['name']
                else:
                    key = val
                url = """<a href="%s">%s</a>""" % (quote(url), key)
                yield url
            elif 'link' in link:
                if  link['name']:
                    key = link['name']
                else:
                    key = val
                url = link['link'] % val
                url = """<a href="%s">%s</a>""" % (quote(url), key)
                yield url
Пример #2
0
def make_links(links, value, inst):
    """
    Make new link for provided query links and passed value.
    """
    if  isinstance(value, list):
        values = value
    else:
        values = [value]
    for link in links:
        for val in values:
            if  'query' in link:
                dasquery = link['query'] % val
                uinput = urllib.quote(dasquery)
                url = '/das/request?input=%s&instance=%s&idx=0&limit=10' \
                            % (uinput, inst)
                if  link['name']:
                    key = link['name']
                else:
                    key = val
                url = """<a href="%s">%s</a>""" % (quote(url), key)
                yield url
            elif 'link' in link:
                if  link['name']:
                    key = link['name']
                else:
                    key = val
                url = link['link'] % val
                url = """<a href="%s">%s</a>""" % (quote(url), key)
                yield url
Пример #3
0
 def tableview(self, head, data):
     """
     Represent data in tabular view.
     """
     kwargs   = head.get('args')
     total    = head.get('nresults', 0)
     dasquery = kwargs['dasquery']
     filters  = dasquery.filters
     titles   = []
     apilist  = head.get('apilist')
     page     = self.pagination(head)
     if  filters:
         for flt in filters:
             if  flt.find('=') != -1 or flt.find('>') != -1 or \
                 flt.find('<') != -1:
                 continue
             titles.append(flt)
     style  = 1
     tpage  = ""
     pkey   = None
     status = head.get('status', None)
     if  status == 'fail':
         reason = head.get('reason', '')
         if  reason:
             page += '<br/><span class="box_red">%s</span>' % reason
     for row in data:
         rec  = []
         if  not pkey and 'das' in row and 'primary_key' in row['das']:
             pkey = row['das']['primary_key'].split('.')[0]
         if  dasquery.filters:
             for flt in dasquery.filters:
                 rec.append(DotDict(row).get(flt))
         else:
             titles = []
             for key, val in row.iteritems():
                 skip = 0
                 if  not filters:
                     if  key in titles:
                         skip = 1
                     else:
                         titles.append(key)
                 if  not skip:
                     rec.append(val)
         if  style:
             style = 0
         else:
             style = 1
         link = '<a href="/das/records/%s?collection=merge">link</a>' \
                     % quote(str(row['_id'])) # cgi.escape the id
         tpage += self.templatepage('das_table_row', rec=rec, tag='td', \
                     style=style, encode=1, record=link)
     theads = list(titles) + ['Record']
     thead = self.templatepage('das_table_row', rec=theads, tag='th', \
                     style=0, encode=0, record=0)
     page += '<br />'
     page += '<table class="das_table">' + thead + tpage + '</table>'
     page += '<br />'
     page += '<div align="right">DAS cache server time: %5.3f sec</div>' \
             % head['ctime']
     return page
Пример #4
0
 def tableview(self, head, data):
     """
     Represent data in tabular view.
     """
     kwargs = head.get('args')
     total = head.get('nresults', 0)
     dasquery = kwargs['dasquery']
     filters = dasquery.filters
     titles = []
     apilist = head.get('apilist')
     page = self.pagination(head)
     if filters:
         for flt in filters:
             if  flt.find('=') != -1 or flt.find('>') != -1 or \
                 flt.find('<') != -1:
                 continue
             titles.append(flt)
     style = 1
     tpage = ""
     pkey = None
     status = head.get('status', None)
     if status == 'fail':
         reason = head.get('reason', '')
         if reason:
             page += '<br/><span class="box_red">%s</span>' % reason
     for row in data:
         rec = []
         if not pkey and 'das' in row and 'primary_key' in row['das']:
             pkey = row['das']['primary_key'].split('.')[0]
         if dasquery.filters:
             for flt in dasquery.filters:
                 rec.append(DotDict(row).get(flt))
         else:
             titles = []
             for key, val in row.items():
                 skip = 0
                 if not filters:
                     if key in titles:
                         skip = 1
                     else:
                         titles.append(key)
                 if not skip:
                     rec.append(val)
         if style:
             style = 0
         else:
             style = 1
         link = '<a href="/das/records/%s?collection=merge">link</a>' \
                     % quote(str(row['_id'])) # cgi.escape the id
         tpage += self.templatepage('das_table_row', rec=rec, tag='td', \
                     style=style, encode=1, record=link)
     theads = list(titles) + ['Record']
     thead = self.templatepage('das_table_row', rec=theads, tag='th', \
                     style=0, encode=0, record=0)
     page += '<br />'
     page += '<table class="das_table">' + thead + tpage + '</table>'
     page += '<br />'
     page += '<div align="right">DAS cache server time: %5.3f sec</div>' \
             % head['ctime']
     return page
Пример #5
0
    def testDASXML(self):
        """test quote function"""
        data = 1
        result = quote(data)
        expect = "1"
        self.assertEqual(expect, result)

        data = "1"
        result = quote(data)
        expect = "1"
        self.assertEqual(expect, result)

        data = "vk test"
        result = quote(data)
        expect = "vk%20test"
        self.assertEqual(expect, result)
Пример #6
0
 def tableview(self, head, data):
     """
     Represent data in tabular view.
     """
     kwargs   = head.get('args')
     total    = head.get('nresults', 0)
     apilist  = head.get('apilist')
     dasquery = head.get('dasquery')
     filters  = dasquery.filters
     sdir     = getarg(kwargs, 'dir', '')
     titles   = []
     page     = self.pagination(head)
     fltbar   = self.filter_bar(dasquery)
     if  filters:
         for flt in filters:
             if  flt.find('=') != -1 or flt.find('>') != -1 or \
                 flt.find('<') != -1:
                 continue
             titles.append(flt)
     style   = 1
     tpage   = ""
     pkey    = None
     status  = head.get('status', None)
     if  status == 'fail':
         reason = head.get('reason', '')
         if  reason:
             page += '<br/><span class="box_red">%s</span>' % reason
     for row in data:
         if  not fltbar:
             fltbar = self.fltpage(row)
         try: # we don't need to show qhash in table view
             del row['qhash']
         except:
             pass
         rec  = []
         if  not pkey and 'das' in row and 'primary_key' in row['das']:
             pkey = row['das']['primary_key'].split('.')[0]
         if  filters:
             for flt in filters:
                 rec.append(DotDict(row).get(flt))
         else:
             gen = self.convert2ui(row)
             titles = []
             for uikey, val, _link, _desc, _examples in gen:
                 skip = 0
                 if  not filters:
                     if  uikey in titles:
                         skip = 1
                     else:
                         titles.append(uikey)
                 if  not skip:
                     rec.append(val)
         if  style:
             style = 0
         else:
             style = 1
         link = '<a href="/das/records/%s?collection=merge">link</a>' \
                     % quote(str(row['_id'])) # cgi.escape the id
         tpage += self.templatepage('das_table_row', rec=rec, tag='td', \
                     style=style, encode=1, record=link)
     if  sdir == 'asc':
         sdir = 'desc'
     elif sdir == 'desc':
         sdir = 'asc'
     else: # default sort direction
         sdir = 'asc' 
     theads = []
     for title in titles:
         theads.append(title)
     theads.append('Record')
     thead = self.templatepage('das_table_row', rec=theads, tag='th', \
                     style=0, encode=0, record=0)
     page += fltbar
     page += '<br />'
     page += '<table class="das_table">' + thead + tpage + '</table>'
     page += '<br />'
     page += '<div align="right">DAS cache server time: %5.3f sec</div>' \
             % head['ctime']
     return page
Пример #7
0
def adjust_values(func, gen, links, pkey):
    """
    Helper function to adjust values in UI.
    It groups values for identical key, make links for provided mapped function,
    represent "Number of" keys as integers and represents size values in GB format.
    The mapped function is the one from das_mapping_db which convert
    UI key into triplet of das key, das access key and link, see 
    das_mapping_db:daskey_from_presentation
    """
    rdict = {}
    uidict = {}
    for uikey, value, uilink, uidesc, uiexamples in [k for k, _g in groupby(gen)]:
        val = quote(value)
        if  uikey in rdict:
            existing_val = rdict[uikey]
            if  not isinstance(existing_val, list):
                existing_val = [existing_val]
            if  val not in existing_val:
                rdict[uikey] = existing_val + [val]
        else:
            rdict[uikey] = val
        uidict[uikey] = (uilink, uidesc, uiexamples)
    page = ""
    to_show = []
    green = 'style="color:green"'
    red = 'style="color:red"'
    for key, val in rdict.iteritems():
        uilink, _uidesc, _uiexamples = uidict[key]
        if  uilink and val:
            if  not isinstance(val, list):
                val = [val]
            values = []
            for elem in val:
                for ilink in uilink:
                    dasquery = ilink['query'] % elem
                    val = '<a href="/das/request?input=%s">%s</a>' \
                            % (dasquery, elem)
                    values.append(val)
            to_show.append((key, ', '.join(values)))
            continue
        lookup = func(key)
        if  key.lower() == 'reason' or key.lower() == 'qhash':
            continue
        if  key.lower() == 'error':
            key = '<span %s>WARNING</span>' % red
            val = json.dumps(val) + ', click on show link to get more info<br/>'
        if  lookup:
            if  key.find('Member') != -1 and val:
                link = '/das/request?input=user%3D'
                if  isinstance(val, list):
                    val = ['<a href="%s%s">%s</a>' \
                    % (link, quote(v), quote(v)) for v in val]
                elif isinstance(val, basestring):
                    val = '<a href="%s%s">%s</a>' \
                        % (link, quote(val), quote(val))
            if  isinstance(val, list):
                value = ', '.join([str(v) for v in val])
                try:
                    length = len(set(val))
                except TypeError: # happens when val list contains a dict
                    length = len(val)
                if  length > 1 and \
                    (key.lower().find('number') != -1 or \
                        key.lower().find('size') != -1):
                    if  key not in ['Luminosity number', 'Run number']:
                        value = '<span %s>%s</span>' % (red, value)
            elif  key.lower().find('size') != -1 and val:
                value = size_format(val)
            elif  key.find('Number of ') != -1 and val and int(val) != 0:
                value = int(val)
            elif  key.find('Run number') != -1 and val:
                value = int(val)
            elif  key.find('Lumi') != -1 and val:
                value = int(val)
            elif  key.find('Tag') != -1 and val:
                if  isinstance(val, basestring) and val.lower() == 'unknown':
                    value = '<span %s>%s</span>' % (red, val)
                else:
                    value = val
            elif  key.find('Creation time') != -1 and val:
                try:
                    value = time.strftime('%d/%b/%Y %H:%M:%S GMT', \
                                time.gmtime(val))
                except:
                    value = val
            else:
                value = val
            if  isinstance(value, list) and isinstance(value[0], str):
                value = ', '.join(value)
            if  key == 'Open' or key == 'Custodial':
                if  value == 'n':
                    value = '<span %s>%s</span>' % (green, value)
                else:
                    value = '<span %s>%s</span>' % (red, value)
            if  key.lower().find('presence') != -1 or \
                key.lower().find('completion') != -1:
                if  not value:
                    continue
                else:
                    if  value == '100.00%':
                        value = '<span %s>100%%</span>' % green
                    else:
                        value = '<span %s>%s</span>' % (red, value)
                key = tooltip_helper(key)
            to_show.append((key, value))
        else:
            if  key == 'result' and isinstance(val, dict) and \
                'value' in val: # result of aggregation function
                if  'key' in rdict and rdict['key'].find('.size') != -1:
                    val = size_format(val['value'])
                elif isinstance(val['value'], float):
                    val = '%.2f' % val['value']
                else:
                    val = val['value']
            to_show.append((key, val))
    if  to_show:
        page += '<br />'
        tdict = {}
        for key, val in to_show:
            tdict[key] = val
        result_keys = ['function', 'result', 'key']
        if  set(tdict.keys()) & set(result_keys) == set(result_keys):
            page += '%s(%s)=%s' \
                % (tdict['function'], tdict['key'], tdict['result'])
        else:
            rlist = ["%s: %s" \
                % (k[0].capitalize()+k[1:], v) for k, v in to_show]
            rlist.sort()
            page += ', '.join(rlist)
            page  = page.replace('<br/>,', '<br/>')
    if  links:
        page += '<br />' + ', '.join(links)
    return page
Пример #8
0
 def tableview(self, head, data):
     """
     Represent data in tabular view.
     """
     kwargs   = head.get('args')
     total    = head.get('nresults', 0)
     incache  = head.get('incache')
     dasquery = head.get('dasquery')
     uinput   = kwargs.get('input', dasquery.query)
     inst     = dasquery.instance
     filters  = dasquery.filters
     idx      = getarg(kwargs, 'idx', 0)
     limit    = getarg(kwargs, 'limit', 10)
     sdir     = getarg(kwargs, 'dir', '')
     titles   = []
     page     = self.pagination(total, incache, kwargs)
     fltbar   = self.filter_bar(dasquery)
     if  filters:
         for flt in filters:
             if  flt.find('=') != -1 or flt.find('>') != -1 or \
                 flt.find('<') != -1:
                 continue
             titles.append(flt)
     style   = 1
     tpage   = ""
     pkey    = None
     for row in data:
         if  not fltbar:
             fltbar = self.fltpage(row)
         try: # we don't need to show qhash in table view
             del row['qhash']
         except:
             pass
         rec  = []
         if  not pkey and row.has_key('das') and \
             row['das'].has_key('primary_key'):
             pkey = row['das']['primary_key'].split('.')[0]
         if  filters:
             for flt in filters:
                 rec.append(DotDict(row).get(flt))
         else:
             gen = self.convert2ui(row)
             titles = []
             for uikey, val in gen:
                 skip = 0
                 if  not filters:
                     if  uikey in titles:
                         skip = 1
                     else:
                         titles.append(uikey)
                 if  not skip:
                     rec.append(val)
         if  style:
             style = 0
         else:
             style = 1
         link = '<a href="/das/records/%s?collection=merge">link</a>' \
                     % quote(str(row['_id'])) # cgi.escape the id
         tpage += self.templatepage('das_table_row', rec=rec, tag='td', \
                     style=style, encode=1, record=link)
     sdict  = self.sort_dict(titles, pkey)
     if  sdir == 'asc':
         sdir = 'desc'
     elif sdir == 'desc':
         sdir = 'asc'
     else: # default sort direction
         sdir = 'asc' 
     args   = {'input':uinput, 'idx':idx, 'limit':limit, 'instance':inst, \
                      'view':'table'}
     theads = []
     for title in titles:
         theads.append(title)
     theads.append('Record')
     thead = self.templatepage('das_table_row', rec=theads, tag='th', \
                     style=0, encode=0, record=0)
     self.sort_dict(titles, pkey)
     page += fltbar
     page += '<br />'
     page += '<table class="das_table">' + thead + tpage + '</table>'
     page += '<br />'
     page += '<div align="right">DAS cache server time: %5.3f sec</div>' \
             % head['ctime']
     return page
Пример #9
0
def adjust_values(func, gen, links):
    """
    Helper function to adjust values in UI.
    It groups values for identical key, make links for provided mapped function,
    represent "Number of" keys as integers and represents size values in GB format.
    The mapped function is the one from das_mapping_db which convert
    UI key into triplet of das key, das access key and link, see 
    das_mapping_db:daskey_from_presentation
    """
    rdict = {}
    for uikey, value in [k for k, _g in groupby(gen)]:
        val = quote(value)
        if  rdict.has_key(uikey):
            existing_val = rdict[uikey]
            if  not isinstance(existing_val, list):
                existing_val = [existing_val]
            if  val not in existing_val:
                rdict[uikey] = existing_val + [val]
        else:
            rdict[uikey] = val
    page = ""
    to_show = []
    error = 0
    green = 'style="color:green"'
    red = 'style="color:red"'
    for key, val in rdict.iteritems():
        lookup = func(key)
        if  key.lower() == 'reason' or key.lower() == 'qhash':
            continue
        if  key.lower() == 'error':
            key = '<span %s>WARNING</span>' % red
            error = 1
            if  val and isinstance(val, basestring):
                val += '<br/>'
        if  lookup:
            if  key.find('Member') != -1 and val:
                link = '/das/request?input=user%3D'
                if  isinstance(val, list):
                    val = ['<a href="%s%s">%s</a>' \
                    % (link, quote(v), quote(v)) for v in val]
                elif isinstance(val, basestring):
                    val = '<a href="%s%s">%s</a>' \
                        % (link, quote(val), quote(val))
            if  isinstance(val, list):
                value = ', '.join([str(v) for v in val])
                if  len(set(val)) > 1 and \
                    (key.lower().find('number') != -1 or \
                        key.lower().find('size') != -1):
                    value = '<span %s>%s</span>' % (red, value)
            elif  key.lower().find('size') != -1 and val:
                value = size_format(val)
            elif  key.find('Number of ') != -1 and val:
                value = int(val)
            elif  key.find('Run number') != -1 and val:
                value = int(val)
            elif  key.find('Lumi') != -1 and val:
                value = int(val)
            elif  key.find('Creation time') != -1 and val:
                try:
                    value = time.strftime('%d/%b/%Y %H:%M:%S GMT', \
                                time.gmtime(val))
                except:
                    value = val
            else:
                value = val
            if  isinstance(value, list) and isinstance(value[0], str):
                value = ', '.join(value)
            if  key == 'Open':
                if  value == 'n':
                    value = '<span %s>%s</span>' % (green, value)
                else:
                    value = '<span %s>%s</span>' % (red, value)
            if  key.find('Status') != -1:
                if  value == 'VALID':
                    value = '<span %s>%s</span>' % (green, value)
                else:
                    value = '<span %s>%s</span>' % (red, value)
            if  key.lower().find('presence') != -1 or \
                key.lower().find('completion') != -1:
                if  not value:
                    continue
                else:
                    if  value == '100.00%':
                        value = '<span %s>100%%</span>' % green
                    else:
                        value = '<span %s>%s</span>' % (red, value)
                key = tooltip_helper(key)
            to_show.append((key, value))
        else:
            if  key == 'result' and isinstance(val, dict) and \
                val.has_key('value'): # result of aggregation function
                if  rdict.has_key('key') and \
                    rdict['key'].find('.size') != -1:
                    val = size_format(val['value'])
                elif isinstance(val['value'], float):
                    val = '%.2f' % val['value']
                else:
                    val = val['value']
            to_show.append((key, val))
    if  to_show:
        page += '<br />'
        tdict = {}
        for key, val in to_show:
            tdict[key] = val
        if  set(tdict.keys()) == set(['function', 'result', 'key']):
            page += '%s(%s)=%s' \
                % (tdict['function'], tdict['key'], tdict['result'])
        else:
            rlist = ["%s: %s" \
                % (k[0].capitalize()+k[1:], v) for k, v in to_show]
            rlist.sort()
            page += ', '.join(rlist)
            page  = page.replace('<br/>,', '<br/>')
    if  links and not error:
        page += '<br />' + ', '.join(links)
    return page
Пример #10
0
 def tableview(self, head, data):
     """
     Represent data in tabular view.
     """
     kwargs   = head.get('args')
     total    = head.get('nresults', 0)
     apilist  = head.get('apilist')
     dasquery = head.get('dasquery')
     filters  = dasquery.filters
     sdir     = getarg(kwargs, 'dir', '')
     titles   = []
     page     = self.pagination(head)
     fltbar   = self.filter_bar(dasquery)
     if  filters:
         for flt in filters:
             if  flt.find('=') != -1 or flt.find('>') != -1 or \
                 flt.find('<') != -1:
                 continue
             titles.append(flt)
     style   = 1
     tpage   = ""
     pkey    = None
     status  = head.get('status', None)
     if  status == 'fail':
         reason = head.get('reason', '')
         if  reason:
             page += '<br/><span class="box_red">%s</span>' % reason
     for row in data:
         if  not fltbar:
             fltbar = self.fltpage(dasquery)
         try: # we don't need to show qhash in table view
             del row['qhash']
         except:
             pass
         rec  = []
         if  not pkey and 'das' in row and 'primary_key' in row['das']:
             pkey = row['das']['primary_key'].split('.')[0]
         if  filters:
             for flt in filters:
                 rec.append(DotDict(row).get(flt))
         else:
             gen = self.convert2ui(row)
             titles = []
             for uikey, val, _link, _desc, _examples in gen:
                 skip = 0
                 if  not filters:
                     if  uikey in titles:
                         skip = 1
                     else:
                         titles.append(uikey)
                 if  not skip:
                     rec.append(val)
         if  style:
             style = 0
         else:
             style = 1
         link = '<a href="/das/records/%s?collection=merge">link</a>' \
                     % quote(str(row['_id'])) # cgi.escape the id
         tpage += self.templatepage('das_table_row', rec=rec, tag='td', \
                     style=style, encode=1, record=link)
     if  sdir == 'asc':
         sdir = 'desc'
     elif sdir == 'desc':
         sdir = 'asc'
     else: # default sort direction
         sdir = 'asc' 
     theads = []
     for title in titles:
         theads.append(title)
     theads.append('Record')
     thead = self.templatepage('das_table_row', rec=theads, tag='th', \
                     style=0, encode=0, record=0)
     page += fltbar
     page += '<br />'
     page += '<table class="das_table">' + thead + tpage + '</table>'
     page += '<br />'
     page += '<div align="right">DAS cache server time: %5.3f sec</div>' \
             % head['ctime']
     return page
Пример #11
0
def adjust_values(func, gen, links, pkey):
    """
    Helper function to adjust values in UI.
    It groups values for identical key, make links for provided mapped function,
    represent "Number of" keys as integers and represents size values in GB format.
    The mapped function is the one from das_mapping_db which convert
    UI key into triplet of das key, das access key and link, see 
    das_mapping_db:daskey_from_presentation
    """
    rdict = {}
    uidict = {}
    for uikey, value, uilink, uidesc, uiexamples in [k for k, _g in groupby(gen)]:
        val = quote(value)
        if  uikey in rdict:
            existing_val = rdict[uikey]
            if  not isinstance(existing_val, list):
                existing_val = [existing_val]
            if  val not in existing_val:
                rdict[uikey] = existing_val + [val]
        else:
            rdict[uikey] = val
        uidict[uikey] = (uilink, uidesc, uiexamples)
    page = ""
    to_show = []
    green = 'style="color:green"'
    red = 'style="color:red"'
    for key, val in rdict.items():
        uilink, _uidesc, _uiexamples = uidict[key]
        if  uilink and val:
            if  not isinstance(val, list):
                val = [val]
            values = []
            for elem in val:
                for ilink in uilink:
                    dasquery = ilink['query'] % elem
                    val = '<a href="/das/request?input=%s">%s</a>' \
                            % (dasquery, elem)
                    values.append(val)
            to_show.append((key, ', '.join(values)))
            continue
        lookup = func(key)
        if  key.lower() == 'reason' or key.lower() == 'qhash' or key.lower() == 'hints':
            continue
        if  key.lower() == 'error':
            key = '<span %s>WARNING</span>' % red
            val = json.dumps(val) + ', click on show link to get more info<br/>'
        if  lookup:
            if  key.find('Member') != -1 and val:
                link = '/das/request?input=user%3D'
                if  isinstance(val, list):
                    val = ['<a href="%s%s">%s</a>' \
                    % (link, quote(v), quote(v)) for v in val]
                elif isinstance(val, basestring):
                    val = '<a href="%s%s">%s</a>' \
                        % (link, quote(val), quote(val))
            if  key.find('Config urls') != -1 and val:
                if  isinstance(val, dict):
                    urls = []
                    for rtype, rurls in val.items():
                        for vdx in range(len(rurls)):
                            urls.append('<a href="%s">%s-config-%d</a>' % (rurls[vdx], rtype, vdx+1))
                    value = ', '.join(urls)
                else:
                    value = '<a href="%s">config</a>' % val
                key = tooltip_helper(key)
            elif  isinstance(val, list):
                value = ', '.join([str(v) for v in val])
                try:
                    length = len(set(val))
                except TypeError: # happens when val list contains a dict
                    length = len(val)
                if  length > 1 and \
                    (key.lower().find('number') != -1 or \
                        key.lower().find('size') != -1):
                    if  key not in ['Luminosity number', 'Run number']:
                        value = '<span %s>%s</span>' % (red, value)
            elif  key.lower().find('size') != -1 and val:
                value = size_format(val)
            elif  key.find('Number of ') != -1 and val and int(val) != 0:
                value = int(val)
            elif  key.find('Run number') != -1 and val:
                value = int(val)
            elif  key.find('Lumi') != -1 and val:
                value = int(val)
            elif  key.find('Site type') != -1 and val:
                if  isinstance(val, basestring) and val.lower() == 'disk':
                    value = val
                else:
                    value = '<span %s><b>TAPE</b></span> <b>no user access</b>' % red
            elif  key.find('Tag') != -1 and val:
                if  isinstance(val, basestring) and val.lower() == 'unknown':
                    value = '<span %s>%s</span>' % (red, val)
                else:
                    value = val
            elif  key.find('Creation time') != -1 and val:
                try:
                    value = time.strftime('%d/%b/%Y %H:%M:%S GMT', \
                                time.gmtime(val))
                except:
                    value = val
            else:
                value = val
            if  isinstance(value, list) and isinstance(value[0], str):
                value = ', '.join(value)
            if  key == 'Open' or key == 'Custodial':
                if  value == 'n':
                    value = '<span %s>%s</span>' % (green, value)
                else:
                    value = '<span %s>%s</span>' % (red, value)
            if  key.lower().find('presence') != -1 or \
                key.lower().find('completion') != -1:
                if  not value:
                    continue
                else:
                    if  value == '100.00%':
                        value = '<span %s>100%%</span>' % green
                    else:
                        value = '<span %s>%s</span>' % (red, value)
                key = tooltip_helper(key)
            to_show.append((key, value))
        else:
            if  key == 'result' and isinstance(val, dict) and \
                'value' in val: # result of aggregation function
                if  'key' in rdict and rdict['key'].find('.size') != -1:
                    val = size_format(val['value'])
                elif isinstance(val['value'], float):
                    val = '%.2f' % val['value']
                else:
                    val = val['value']
            to_show.append((key, val))
    if  to_show:
        to_show = list(set(to_show))
        page += '<br />'
        tdict = {}
        for key, val in to_show:
            tdict[key] = val
        result_keys = ['function', 'result', 'key']
        if  set(tdict.keys()) & set(result_keys) == set(result_keys):
            page += '%s(%s)=%s' \
                % (tdict['function'], tdict['key'], tdict['result'])
        elif sorted(tdict.keys()) == sorted(['Luminosity number', 'Run number']):
            page += 'Run number: %s, Luminosity ranges: %s' \
                    % (tdict['Run number'], convert2ranges(rdict['Luminosity number']))
        elif sorted(tdict.keys()) == sorted(['Events', 'Luminosity number', 'Run number']):
            page += 'Run number: %s, Luminosity ranges: %s' \
                    % (tdict['Run number'], convert2ranges(rdict['Luminosity number']))
            page += lumi_evts(rdict)
        elif sorted(tdict.keys()) == sorted(['Luminosity number']):
            page += 'Luminosity ranges: %s' \
                    % (convert2ranges(rdict['Luminosity number']))
        elif sorted(tdict.keys()) == sorted(['Events', 'Luminosity number']):
            page += 'Luminosity ranges: %s' \
                    % (convert2ranges(rdict['Luminosity number']))
            page += lumi_evts(rdict)
        else:
            rlist = ["%s: %s" \
                % (k[0].capitalize()+k[1:], v) for k, v in to_show]
            rlist.sort()
            page += ', '.join(rlist)
            page  = page.replace('<br/>,', '<br/>')
    if  links:
        page += '<br />' + ', '.join(links)
    return page