@user_passes_test(using_unique_session)
def editplan(request, planid):
    """
    Edit a plan. 
    
    This template enables editing tools and functionality.
    
    Parameters:
        request -- An HttpRequest, which includes the current user.
        planid -- The plan to edit.

    Returns:
        A rendered HTML page for editing a plan.
    """
    if request.user.is_anonymous() or not is_session_available(request) or not is_plan_ready(planid):
        return HttpResponseRedirect('/')

    cfg = commonplan(request, planid)
    if cfg['is_editable'] == False:
        return HttpResponseRedirect('/districtmapping/plan/%s/view/' % planid)
    plan = Plan.objects.get(id=planid,owner=request.user)
    cfg['dists_maxed'] = len(cfg['districts']) > plan.legislative_body.max_districts
    cfg['available_districts'] = plan.get_available_districts()

    # Cleanup old versions
    if settings.MAX_UNDOS_AFTER_EDIT > 0:
        plan.purge_beyond_nth_step(settings.MAX_UNDOS_AFTER_EDIT)

    return render_to_response('editplan.html', cfg)
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/editplan/original