@unique_session_or_json_redirect
def getdistricts(request, planid):
    """
    Get the districts in a plan at a specific version.

    Parameters:
        request - An HttpRequest, with the current user.
        planid - The plan id to query for the districts.
    Returns:
    """
    note_session_activity(request)

    status = {'success':False}

    plan = Plan.objects.filter(id=planid)
    if plan.count() == 1:
        plan = plan[0]

        if request.REQUEST in 'version':
            version = int(request.REQUEST['version'])
        else:
            version = plan.version

        districts = plan.get_districts_at_version(version,include_geom=False)

        status['districts'] = []

        # Same calculation as plan.get_available_districts, but
        # g_a_d fetches districts all over again -- skip that overhead
        status['available'] = plan.legislative_body.max_districts - len(districts) + 1

        # Find the maximum version in the returned districts
        max_version = max([d.version for d in districts])

        # Only allow undo if the max version being returned isn't
        # equal to the minimum stored version
        can_undo = max_version > plan.min_version

        for district in districts:
            status['districts'].append({
                'id':district.district_id,
                'short_label':' '.join(map(_, district.short_label.split(' '))),
                'long_label':' '.join(map(_, district.long_label.split(' '))),
                'version':district.version
            })
        status['canUndo'] = can_undo
        status['success'] = True

    else:
        status['message'] = _('No plan exists with that ID.')

    return HttpResponse(json.dumps(status), mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/getdistricts/swapped operands of `in`