'Represent a single Row
- assumes that Path & Lx have been populated correctly by
gis.update_location_tree()
@param row: the gis_location Row'

def represent_row(self, row):

    sep = self.sep
    translate = self.translate
    ids = self.paths.get(row.id)
    if translate:
        l10n = self.l10n
        loc = l10n.get(row.id)
        if loc:
            name = loc['name_l10n']
        else:
            name = (row.name or '')
    else:
        name = (row.name or '')
    level = row.level
    if sep:
        if (level == 'L0'):
            return name
        ids.pop()
        if (self.show_name or (level is not None)):
            locations = [name]
        else:
            locations = []
        lappend = locations.append
        L5 = row.L5
        if (L5 and (level != 'L5')):
            if translate:
                loc = l10n.get(int(ids.pop()), None)
                if loc:
                    L5 = loc['name_l10n']
            lappend(L5)
        L4 = row.L4
        if (L4 and (level != 'L4')):
            if translate:
                loc = l10n.get(int(ids.pop()), None)
                if loc:
                    L4 = loc['name_l10n']
            lappend(L4)
        L3 = row.L3
        if (L3 and (level != 'L3')):
            if translate:
                loc = l10n.get(int(ids.pop()), None)
                if loc:
                    L3 = loc['name_l10n']
            lappend(L3)
        L2 = row.L2
        if (L2 and (level != 'L2')):
            if translate:
                loc = l10n.get(int(ids.pop()), None)
                if loc:
                    L2 = loc['name_l10n']
            lappend(L2)
        L1 = row.L1
        if (L1 and (level != 'L1')):
            if translate:
                loc = l10n.get(int(ids.pop()), None)
                if loc:
                    L1 = loc['name_l10n']
            lappend(L1)
        if self.multi_country:
            L0 = row.L0
            if L0:
                if translate:
                    loc = l10n.get(int(ids.pop()), None)
                    if loc:
                        L0 = loc['name_l10n']
                lappend(L0)
        if locations:
            represent = sep.join(locations)
        else:
            represent = name
    elif (level == 'L0'):
        represent = ('%s    (%s)' % (name, current.messages.COUNTRY))
    elif (level in ('L1', 'L2', 'L3', 'L4', 'L5')):
        s3db = current.s3db
        htable = s3db.gis_hierarchy
        L0_name = row.L0
        if L0_name:
            if row.path:
                path = row.path
            else:
                path = current.gis.update_location_tree(row)
            path = path.split('/')
            L0_id = path[0]
            level_name = current.gis.get_location_hierarchy(level, L0_id)
        else:
            level_name = current.gis.get_location_hierarchy(level)
        represent = name
        if level_name:
            represent = ('%s    (%s)' % (represent, level_name))
        if row.parent:
            parent_level = ('L%s' % (int(level[1]) - 1))
            parent_name = row[parent_level]
            if parent_name:
                represent = ('%s,    %s' % (represent, parent_name))
    else:
        has_lat_lon = ((row.get('lat') is not None) and (row.get('lon') is not None))
        represent = ''
        if row.addr_street:
            represent = row.addr_street.splitlines()[0]
        if row.addr_postcode:
            represent = ('%s,    %s' % (represent, row.addr_postcode))
        if ((not represent) and (not self.address_only) and (row.inherited == False) and has_lat_lon):
            represent = self.lat_lon_represent(row)
        if row.parent:
            if row.path:
                path = row.path
            else:
                path = current.gis.update_location_tree(row)
            path = path.split('/')
            path_len = len(path)
            if (path_len > 1):
                parent_level = ('L%s' % (path_len - 2))
                parent_name = row[parent_level]
                if parent_name:
                    if represent:
                        represent = ('%s,    %s' % (represent, parent_name))
                    else:
                        represent = parent_name
        if (not represent):
            represent = (name or ('ID:    %s' % row.id))
        if (has_lat_lon and self.show_marker_icon):
            if (not self.show_link):
                popup = current.deployment_settings.get_gis_popup_location_link()
                script = ("s3_viewMap(%i,%i,'%s');return    false" % (row.id, self.iheight, popup))
            else:
                script = None
            represent = SPAN(s3_unicode(represent), ICON('map-marker', _title=self.lat_lon_represent(row), _onclick=script), _class='gis-display-feature')
            return represent
    return s3_str(represent)
