def getplans(request):
    """
    Get the plans for the given user and return the data in a format readable
    by the jqgrid
    """
    note_session_activity(request)

    if not using_unique_session(request.user):
        return HttpResponseForbidden()

    if request.method == 'POST':
        page = int(request.POST.get('page', 1))
        rows = int(request.POST.get('rows', 10))
        sidx = request.POST.get('sidx', 'id')
        sord = request.POST.get('sord', 'asc')
        owner_filter = request.POST.get('owner_filter');
        body_pk = request.POST.get('legislative_body');
        body_pk = int(body_pk) if body_pk else body_pk;
        search = request.POST.get('_search', False);
        search_string = request.POST.get('searchString', '');
        is_community = request.POST.get('is_community', False) == 'true';
    else:
        return HttpResponseForbidden()
    end = page * rows
    start = end - rows
    
    if owner_filter == 'template':
        available = Q(is_template=True)
    elif owner_filter == 'shared':
        available = Q(is_shared=True)
    elif owner_filter == 'mine':
        if request.user.is_anonymous():
            return HttpResponseForbidden()
        else:
            available = Q(owner__exact=request.user)
    elif owner_filter == 'all_available':
        available = Q(is_template=True) | Q(is_shared=True)
        if not request.user.is_anonymous():
            available = available | Q(owner__exact=request.user)
    else:
        return HttpResponseBadRequest(_("Unknown filter method."))
        
    not_creating = ~Q(processing_state=ProcessingState.CREATING) & ~Q(processing_state=ProcessingState.UNKNOWN)

    # Set up the order_by parameter from sidx and sord in the request
    if sidx.startswith('fields.'):
        sidx = sidx[len('fields.'):]
    if sidx == 'owner':
        sidx = 'owner__username'
    if sidx == 'plan_type':
        sidx = 'legislative_body__name'
    if sord == 'desc':
        sidx = '-' + sidx

    if search:
        search_filter = Q(name__icontains = search_string) | Q(description__icontains = search_string) | Q(owner__username__icontains = search_string)
    else:
        search_filter = None

    if body_pk:
        body_filter = Q(legislative_body=body_pk)
        all_plans = Plan.objects.filter(available, not_creating, body_filter, search_filter).order_by(sidx)
    else:
        community_filter = Q(legislative_body__is_community=is_community)
        all_plans = Plan.objects.filter(available, not_creating, search_filter, community_filter).order_by(sidx)

    if all_plans.count() > 0:
        total_pages = math.ceil(float(rows) / all_plans.count())
    else:
        total_pages = 1

    plans = all_plans[start:end]
    # Create the objects that will be serialized for presentation in the plan chooser
    plans_list = list()
    for plan in plans:
        plans_list.append({
            'pk': plan.id, 
            'fields': { 
                'name': plan.name, 
                'description': plan.description, 
                'edited': time.mktime(plan.edited.timetuple()), 
                'is_template': plan.is_template, 
                'is_shared': plan.is_shared, 
                'owner': plan.owner.username, 
                'districtCount': '--', # load dynamically -- this is a big performance hit
                'can_edit': can_edit(request.user, plan),
                'plan_type': plan.legislative_body.get_long_description(),
                'processing_state': plan.get_processing_state_display()
                }
            })

    json_response = "{ \"total\":\"%d\", \"page\":\"%d\", \"records\":\"%d\", \"rows\":%s }" % (total_pages, page, len(all_plans), json.dumps(plans_list))
    return HttpResponse(json_response,mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/getplans/swapped operands of `/`