Beispiel #1
0
def geoloc2location(gl, save=False):
    names = 'name,geonameid,coordinates_polygon,latitude,longitude,information'.split(
        ',')
    kw = dict([[n, getattr(gl, n)] for n in names])
    l = Location(**kw)
    l.location_type = LocationType.objects.get(name=gl.location_type.lower())
    l.location_status = LocationStatus.objects.get(name='non-fiction')
    l.location_precision = LocationPrecision.objects.get(name='exact')
    ul = gl.user_locs.all()
    l.active = True if ul.count() > 0 else False
    if save: l.save()
    return l
Beispiel #2
0
def handle_not_handled(nh):
    userlocs = []
    locs = []
    pks = []
    for line in nh:
        key, ul_info, field = line
        pk = int(ul_info[-3])
        instance = get_instance(*key.split(','))
        if pk not in pks:
            pks.append(pk)
            ul = UserLoc.objects.get(pk=pk)
            print(ul)
            try:
                l = Location.objects.get(geonameid=ul.name)
            except:
                l = Location(name=ul.name, geonameid=ul.name)
                l.location_type = LocationType.objects.get(
                    name=ul.loc_type.name)
                l.location_precision = LocationPrecision.objects.get(
                    name=ul.loc_precision)
                l.location_status = LocationStatus.objects.get(name=ul.status)
                l.active = True
                l.save()
                print('made', l)
            else:
                print(l, 'already made')
            for geonameid in ul_info[3].split('|'):
                print('geonameid', geonameid)
                if not geonameid: continue
                rl = Location.objects.get(geonameid=geonameid)
                if rl.pk == l.pk: continue
                print('adding location:', rl)
                l.relations.add(rl)
            userlocs.append(ul)
            locs.append(l)
            print('---')
        locations = [Location.objects.get(geonameid=ul_info[-2])]
        _set_location(instance, field, locations, key, ul_info)
    return (userlocs, locs)