@login_required
def unloadplan(request, planid):
    """
    Unload a plan.

    This view is called anytime a plan is unloaded. Example: navigating
    away from the page, or selecting a new plan. This method allows
    for any required plan cleanup such as purging temporary versions.

    Parameters:
        request -- The HttpRequest, which includes the user.
        planid -- The plan to unload.

    Returns:
        A JSON HttpResponse which includes a status.
    """
    note_session_activity(request)
    status = { 'success': False }

    ps = Plan.objects.filter(pk=planid)
    if len(ps) > 0:
        p = ps[0]

        if not can_copy(request.user, p):
            status['message'] = _("User %(user)s doesn't have permission to unload this plan") % {'user':request.user.username}
            return HttpResponse(json.dumps(status),mimetype='application/json')

        # Purge temporary versions
        if settings.MAX_UNDOS_AFTER_EDIT > 0:
            p.purge_beyond_nth_step(settings.MAX_UNDOS_AFTER_EDIT)
    
    status['success'] = True
    return HttpResponse(json.dumps(status),mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/unloadplan/original