Exemplo n.º 1
0
def __target_properties(target, elt):
    # each target is a dict. prepend the ifcb namespace to each dict key and make subtags
    for tag in order_keys(target.info, [column for column,type in ADC_SCHEMA]):
         if tag != PID:
            # emit <ifcb:{tag}>{target.tag}</ifcb:{tag}>
            property = SubElement(elt, ifcb_term(tag))
            property.text = str(target.info[tag])
Exemplo n.º 2
0
def bin2html(bin,out=sys.stdout,detail=DETAIL_SHORT):
    """Output HTML representing a given bin.
    
    Parameters:
    bin - instance of Bin
    out - where to write the representation (default: stdout)
    detail - level of detail (default: DETAIL_SHORT)
    """
    # emit
    # <html>
    #   <head>
    #     <title>{bin_title(bin)}</title>
    #   </head>
    #   <body>
    #     <div class="title">{bin_title(bin)}</div>
    #     <div class="properties">
    #       ...
    (html, body) = __html(bin_title(bin))
    properties = Sub(body, 'div', 'properties')
    for k in order_keys(bin.properties(), [column for column,type in HDR_SCHEMA]):
        # emit
        # <div class="property">
        #   <div class="label">{pretty_property_name(k)}</div>
        #   <div class="value">{bin.properties()[k]}</div>
        # </div>
        prop = Sub(properties, 'div', 'property')
        Sub(prop, 'div', 'label').text = pretty_property_name(k)
        Sub(prop, 'div', 'value').text = str(bin.properties()[k])
    if detail != DETAIL_HEAD:
        # emit
        # <div class="targets">
        #   <ul class="targets">
        #     ...
        targets = Sub(body, 'div', 'targets')
        ul = Sub(targets,'ul','targets')
        for target in bin:
            # emit
            # <li class="target">
            #   <a href="{href(target.pid)}">{target_title(target)} {target area}B</a>
            # </li>
            li = Sub(ul, 'li', 'target')
            a = SubElement(li, 'a', href=href(target.pid))
            a.text = target_title(target)
            a.tail = ' %dB' % (target.height * target.width)
    ElementTree(html).write(out, pretty_print=True)
Exemplo n.º 3
0
def target2html(target,out=sys.stdout):
    """Output HTML representing a given target
    
    Parameters:
    target - instance of Target
    out - where to write the representation (default: stdout)
    """
    (html, body) = __html(target_title(target))
    # emit
    # <div class="image">
    #   <img src="{target.pid}.png" class="image">
    # </div>
    id = Sub(body, 'div', 'image')
    img = SubElement(id, 'img', src=href(target.pid,'png'))
    img.set('class','image')
    # emit
    # <div class="properties">
    #   <div class="property">
    #     <div class="label">bin</div>
    #     <div class="bin value">
    #       <a href="{target.bin.pid}">{bin_title(target.bin)}</a>
    #     </div>
    #     ...
    properties = Sub(body, 'div', 'properties')
    parent_link = Sub(properties, 'div', 'property')
    Sub(parent_link, 'div', 'label').text = 'bin'
    link = Sub(parent_link, 'div', 'bin value')
    SubElement(link, 'a', href=href(target.bin.pid)).text = bin_title(target.bin)
    for k in order_keys(target.info, [column for column,type in ADC_SCHEMA]):
        # emit
        # <div class="property">
        #   <div class="label">{pretty_property_name(k)}</div>
        #   <div class="value">{target.info[k]}</div>
        # </div>
        prop = Sub(properties, 'div', 'property')
        Sub(prop, 'div', 'label').text = pretty_property_name(k)
        Sub(prop, 'div', 'value').text = str(target.info[k])
    ElementTree(html).write(out, pretty_print=True)