def simple_district_versioned(request, planid, district_ids=None):
    """
    Emulate a WFS service for versioned districts.

    This function retrieves one version of the districts in a plan, with
    the value of the subject attached to the feature. This function is
    necessary because a traditional view could not be used to get the
    districts in a versioned fashion.

    This method accepts 'version__eq' and 'subjects__eq' URL parameters.

    This method accepts an optional 'district_ids__eq' parameter, which is
    a comma-separated list of district_ids to filter by

    Parameters:
        request -- An HttpRequest, with the current user.
        planid -- The plan ID from which to get the districts.

    Returns:
        A GeoJSON HttpResponse, describing the districts in the plan.
    """
    note_session_activity(request)

    status = {'type':'FeatureCollection'}

    plan = Plan.objects.filter(id=planid)
    if plan.count() == 1:
        plan = plan[0]
        if 'version__eq' in request.REQUEST:
            version = request.REQUEST['version__eq']
        else:
            version = plan.version

        subject_id = None
        if 'subject__eq' in request.REQUEST:
            subject_id = request.REQUEST['subject__eq']
        elif plan.legislative_body.get_default_subject():
            subject_id = plan.legislative_body.get_default_subject().id

        geolevel = plan.legislative_body.get_geolevels()[0].id
        if 'level__eq' in request.REQUEST:
            geolevel = int(request.REQUEST['level__eq'])

        if 'district_ids__eq' in request.REQUEST:
            district_ids = request.REQUEST['district_ids__eq']
            if len(district_ids) > 0:
                district_ids = district_ids.split(',')
            else:
                district_ids = []

        if subject_id:
            bbox = None
            if 'bbox' in request.REQUEST:
                bbox = request.REQUEST['bbox']
                # convert the request string into a tuple full of floats
                bbox = tuple( map( lambda x: float(x), bbox.split(',')))
            else:
                bbox = plan.district_set.all().extent(field_name='simple')

            status['features'] = plan.get_wfs_districts(version, subject_id, bbox, geolevel, district_ids)
        else:
            status['features'] = []
            status['message'] = _('Subject for districts is required.')
    else:
        status['features'] = []
        status['message'] = _('Query failed.')

    return HttpResponse(json.dumps(status),mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/simple_district_versioned/original