예제 #1
0
def main(request):
    # TODO: show number of unmerged entries for each region
    left = []
    for name, title, region_id in REGIONS:
        merged_data = get_merge_data(name)
        merged_tvds = [tik_merged['tvd'] for tik_merged in merged_data]

        results_lst = filter(lambda result_tik: result_tik['tvd'] not in merged_tvds, get_regions_data(name))

        count = len(results_lst) # float(len(merged_data))/(len(merged_data)+len(results_lst)+0.01)*100
        if not os.path.exists(os.path.join(DATA_PATH, 'regions', name+'-center.json')):
            count += 1
        left.append((name, title, count)) 

    return render_to_response('main.html', {'REGIONS': left})
예제 #2
0
def region(request, name):
    region = (filter(lambda region: region[0]==name, REGIONS) or [None])[0]
    if not region:
        return None

    if request.method == 'POST':
        if 'result_tik' not in request.POST:
            return HttpResponse(u'Выбирите округ в правой таблице')
        tvd, root = request.POST['result_tik'].split('_')
        vrnorg, vrnkomis = request.POST['info_tik'].split('_')

        if 'add_geo' in request.POST:
            try:
                x_coord, y_coord = float(request.POST['x_coord']), float(request.POST['y_coord'])
            except ValueError:
                return HttpResponse(u'Вы забыли найти координаты ТИКа')
        else:
            x_coord, y_coord = None, None

        try:
            int(request.POST['postcode'])
        except ValueError:
            return HttpResponse(u'Не введен почтовый код (не обрабатывайте этот ТИК)')

        merge_data(name, tvd, root, vrnorg, vrnkomis, request.POST['new_name'], x_coord, y_coord,
                int(request.POST['postcode']), request.POST['address'])

        return redirect('region', name)

    merged_data = get_merge_data(name)

    merged_vrnorgs = [tik_merged['vrnorg'] for tik_merged in merged_data]
    merged_tvds = [tik_merged['tvd'] for tik_merged in merged_data]

    results_lst = filter(lambda result_tik: result_tik['tvd'] not in merged_tvds, get_regions_data(name))

    info_data_path = os.path.join(DATA_PATH, 'regions', name+'-info.json')
    info_tiks = json.loads(open(info_data_path).read().decode('windows-1251'))

    info_tiks = filter(lambda info_tik: info_tik['vrnorg'] not in merged_vrnorgs, info_tiks)

    for info_tik in info_tiks:
        info_tik.update(parse_address(info_tik['address']))

        for ending in (u'ого района', u'ого округа'):
            index = info_tik['name'].find(ending)
            if index != -1:
                suffix = info_tik['name'][index+len(ending):]
                if any(word in suffix for word in (u'края', u'области', u'города')):
                    info_tik['name'] = info_tik['name'][:index+len(ending)]

        info_tik['name'] = info_tik['name'] \
                .replace(u'муниципального ', '') \
                .replace(u'ная районная', u'ный район').replace(u'кая районная', u'кий район') \
                .replace(u'кого района', u'кий район').replace(u'ного района', u'ный район') \
                .replace(u'г.', '').replace(u'города', '')

    # special processing for central regional TIKs
    center_data_path = os.path.join(DATA_PATH, 'regions', name+'-center.json')
    try:
        center_data = json.loads(open(center_data_path).read().decode('utf8'))
    except IOError:
        results_lst.append({'name': region[1], 'tvd': 0, 'root': 0})
    else:
        info_tiks = filter(lambda info_tik: info_tik['vrnorg']!=center_data['vrnorg'], info_tiks)

    context = {
        'name': region[0],
        'title': region[1],
        'region_id': region[2],
        'result_tiks': results_lst,
        'info_tiks': info_tiks,
        'merged_tiks': merged_data,
    }
    return render_to_response('region.html', context_instance=RequestContext(request, context))
예제 #3
0
def main(request):
    # TODO: show number of unmerged entries for each region
    left = []
    for name, title, region_id in REGIONS:
        merged_data = get_merge_data(name)
        merged_tvds = [tik_merged['tvd'] for tik_merged in merged_data]

        results_lst = filter(lambda result_tik: result_tik['tvd'] not in merged_tvds, get_regions_data(name))

        left.append((name, title, float(len(merged_data))/(len(merged_data)+len(results_lst)+0.01)*100))

    return render_to_response('main.html', {'REGIONS': left})