'Private function used to save the locations to gis.location'

@staticmethod
def importLocations(location_dict):

    import csv
    import os
    last_loc_widget = None
    code_list = ['STD-L0', 'STD-L1', 'STD-L2', 'STD-L3', 'STD-L4']
    heading_list = ['Country', 'ADM1_NAME', 'ADM2_NAME', 'ADM3_NAME', 'ADM4_NAME']
    answer = []
    headings = []
    aappend = answer.append
    happend = headings.append
    for (position, location) in enumerate(code_list):
        if (location in location_dict):
            aappend(location_dict[location].repr())
            last_loc_widget = location_dict[location]
            happend(heading_list[position])
    if (last_loc_widget is None):
        return
    code_list = ['STD-P-Code', 'STD-Lat', 'STD-Lon']
    for loc in code_list:
        if (loc in location_dict):
            aappend(location_dict[loc].repr())
        else:
            aappend('')
    from tempfile import TemporaryFile
    csvfile = TemporaryFile()
    writer = csv.writer(csvfile)
    headings += ['Code2', 'Lat', 'Lon']
    writer.writerow(headings)
    writer.writerow(answer)
    csvfile.seek(0)
    xsl = os.path.join('applications', current.request.application, 'static', 'formats', 's3csv', 'gis', 'location.xsl')
    resource = current.s3db.resource('gis_location')
    resource.import_xml(csvfile, stylesheet=xsl, format='csv')
