@unique_session_or_json_redirect
def get_splits(request, planid, otherid, othertype):
    """
    Find all splits between this plan and another plan

    Parameters:
        request -- An HttpRequest optionally containing version and/or otherversion
        planid -- The plan ID
        otherid -- The plan ID or geolevel ID to find splits with
        othertype -- One of: 'plan' or 'geolevel'. For specifying otherid

    Returns:
        A JSON HttpResponse that contains an array of splits, given as arrays,
        where the first item is the district_id of the district in this plan
        which causes the split, and the second item is the district_id of the
        district in the other plan or geolevel. When a geolevel is specified,
        the portable_id will be used, rather than the district_id.
    """

    otherid = int(otherid)
    status = { 'success': False }

    try:
        plan = Plan.objects.get(pk=planid)
    except:
        status['message'] = _('No plan with the given id')
        return HttpResponse(json.dumps(status),mimetype='application/json')

    if not can_view(request.user, plan):
        status['message'] = _("User can't view the given plan")
        return HttpResponse(json.dumps(status),mimetype='application/json')

    version = int(request.REQUEST['version'] if 'version' in request.REQUEST else plan.version)
    try:
        if othertype == 'plan':
            try:
                otherplan = Plan.objects.get(pk=otherid)
            except:
                status['message'] = _('No other plan with the given id')
                return HttpResponse(json.dumps(status),mimetype='application/json')
            if not can_view(request.user, otherplan):
                status['message'] = _("User can't view the given plan")
                return HttpResponse(json.dumps(status),mimetype='application/json')
                
            otherversion = int(request.REQUEST['otherversion'] if request.REQUEST in 'otherversion' else otherplan.version)
            splits = plan.find_plan_splits(otherplan, version, otherversion)
        elif othertype == 'geolevel':
            splits = plan.find_geolevel_splits(otherid, version)
        else:
            status['message'] = _('othertype not supported: %(other)s') % { 'other': othertype }
            return HttpResponse(json.dumps(status),mimetype='application/json')

        split_word = _('split') if len(splits) == 1 else inflect.engine().plural(_('split'))

        status['success'] = True
        status['message'] = _('Found %(num_splits)d %(split_word)s') % \
                {'num_splits': len(splits), 'split_word': split_word}
        status['splits'] = splits
        status['above_ids'] = list(set([i[0] for i in splits]))
        status['below_ids'] = list(set([i[1] for i in splits]))
    except Exception, ex:
        status['message'] = _('Could not query for splits')
        status['exception'] = traceback.format_exc()
        logger.warn('Could not query for splits')
        logger.debug('Reason: %s', ex)
    return HttpResponse(json.dumps(status),mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/get_splits/swapped operands of `in`