@unique_session_or_json_redirect
@login_required
def setdistrictlock(request, planid, district_id):
    """
    Set whether this district is locked for editing.

    Parameters:
        request -- An HttpRequest, with a boolean that indicates whether the district
        should be locked or unlocked
        planid -- The plan ID that contains the district.
        district_id -- The district_id to lock or unlock

    Returns:
        A JSON HttpResponse that contains a boolean of whether the district is locked.
    """
    note_session_activity(request)

    status = {'success':False}

    if request.method != 'POST':
        return HttpResponseForbidden()
    
    lock = request.POST.get('lock').lower() == 'true'
    version = request.POST.get('version')
    if lock == None:
        status['message'] = _('Must include lock parameter.')
    elif version == None:
        status['message'] = _('Must include version parameter.')

    try:
        plan = Plan.objects.get(pk=planid)
        district = plan.district_set.filter(district_id=district_id,version__lte=version).order_by('version').reverse()[0]
    except __HOLE__:
        status['message'] = _('Plan or district does not exist.')
        return HttpResponse(json.dumps(status), mimetype='application/json')

    if plan.owner != request.user:
        return HttpResponseForbidden()
    
    district.is_locked = lock
    district.save()
    status['success'] = True
    status['message'] = _('District successfully %(locked_state)s') % \
            {'locked_state': _('locked') if lock else _('unlocked')}
  
    return HttpResponse(json.dumps(status), mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/setdistrictlock