Next / Previous / Contents / TCC Help System / NM Tech homepage

20. buildDevices(): Extract relevant device configurations

Given a reportInfo instance that specifies which devices we care about, and a clientConfig instance that specifies a given client configuration, this function builds an XHTML fragment containing a stack of div elements, one for each matching device. For the generated XHTML, see Section 3.2, “XHTML for the room page”.

hwscan3.py
# - - -   b u i l d D e v i c e s

def buildDevices ( reportInfo, clientConfig ):
    '''Build the contents of the "Devices" cell in the client table.

      [ (reportInfo is a ReportInfo) and
        (clientConfig is a ClientConfig) ->
          return a div containing divs for each device named
          in reportInfo that matches a device from clientConfig ]
    '''

We'll start by building a div element that will hold all the device div elements.

hwscan3.py
    #-- 1 --
    # [ result  :=  a new div et.Element ]
    result  =  E.div()

Next we'll step through the device types of interest from reportInfo. For each type, we will then look through the device list in clientConfig, and for each matching device type, we add another div to result. For the definitions of the constants, see Section 6.27, “CLASS and Section 6.28, “HANG_CLASS.

hwscan3.py
    #-- 2 --
    # [ result  +:=  div.hang elements containing device details
    #       from clientConfig.deviceList that match device types
    #       in reportInfo.deviceList, in order by the latter list ]
    for deviceType in reportInfo.deviceList:
        #-- 2 body --
        # [ result  +:=  div.hang elements containing device
        #       details from clientConfig.deviceList whose types
        #       match deviceType ]
        for configType, configDetail in clientConfig.deviceList:
            # [ if deviceType == configType ->
            #     result  +:=  a div.hang element containing
            #                  configDetail
            #   else -> I ]
            if deviceType == configType:
                text  =  "%s: %s" % (deviceType.capitalize(),
                                     configDetail)
                result.append ( E.div ( CLASS(HANG_CLASS), text ) )

    #-- 3 --
    return result