$def with (disk)

$code:
    def partinfo(p, ext=False):
        ret = '<span class="text">'
        if p.size > 1:
            ret += '%.0f%%' % p.size
            if p.filesystem:
                ret += '<span class="fs">('+p.filesystem+')</span>'
        ret += '</span>'
        if p.bootable:
            ret += '<div class="flag bootable" title="bootable"></div>'

        if ext:
            ret += '<div class="flag ext" title="extended"></div>'

        ret = '<div class="partition_border%s">%s</div>' % (' pext' if ext else '', ret)
        return ret

<div class="disk">
    $for partition in disk.get_partitions_with_free_spaces_and_extended():
        $if partition.type == "PRIMARY":
            <div class="partition $partition.filesystem" title="$partition.filesystem" style="width:$(partition.size)%;">
                $:partinfo(partition)
            </div>

        $elif partition.type == "EXTENDED":
            <div class="partition extended" style="width:$(partition.size)%;">
                <div class="partition_border">
                    $for logic in disk.get_partitions_inside_extended():
                        $if logic.type == "LOGIC":
                            <div class="partition $logic.filesystem" title="$logic.filesystem" style="width:$(100*logic.size/partition.size)%;">
                                $:partinfo(logic, True)
                            </div>
                        $elif logic.type == "FREE":
                            <div class="partition free" style="width:$(100*logic.size/partition.size)%;">
                                $:partinfo(logic, True)
                            </div>
                </div>
            </div>

        $elif partition.type == "FREE":
            <div class="partition free" style="width:$(partition.size)%;">
                $:partinfo(partition)
            </div>
</div>
<div class="clear"></div>
