def get_shared_districts(request, planid):
    """
    Get the shared districts in a given plan and return the
    data in a format readable by the jqgrid
    """
    note_session_activity(request)

    if not using_unique_session(request.user):
        return HttpResponseForbidden()

    if request.method == 'POST':
        page = int(request.POST.get('page', 1))
        rows = int(request.POST.get('rows', 10))
    else:
        return HttpResponseForbidden()

    end = page * rows
    start = end - rows
    
    try:
        plan = Plan.objects.get(pk=planid)
        if not can_copy(request.user, plan):
            return HttpResponseForbidden()

        all_districts = plan.get_districts_at_version(plan.version, include_geom=False)
    except:
        plan = None
        all_districts = () 

    if len(all_districts) > 0:
        total_pages = math.ceil(len(all_districts) / float(rows))
    else:
        total_pages = 1

    districts = all_districts[start:end]
    # Create the objects that will be serialized for presentation in the plan chooser
    districts_list = list()
    for district in districts:
        if not district.is_unassigned:
            districts_list.append({
                'pk': district.id, 
                'fields': { 
                    'short_label': district.short_label,
                    'long_label': district.long_label,
                    'district_id': district.district_id,
                }
            })

    json_response = "{ \"total\":\"%d\", \"page\":\"%d\", \"records\":\"%d\", \"rows\":%s }" % (total_pages, page, len(all_districts), json.dumps(districts_list))
    return HttpResponse(json_response,mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/get_shared_districts/original