def get(self, request): page_requested = request.GET.get('page') # no need to validate, pagination does this for us results_requested = request.GET.get('results') if results_requested == None or not is_positive_integer(results_requested): results_requested = 5 # Get all projects from the db project_list = Project.objects.order_by('deployment_date') open_project_count = project_list.exclude(is_complete = True).count() closed_project_count = project_list.exclude(is_complete = False).count() # Store show_all config in the session so the app remembers it's value when the user navigates away request.session['show_all'] = get_show_all(request, closed_project_count) # If show_all has been set to false (default option), filter those records out if request.session['show_all'] == False: project_list = project_list.exclude(is_complete = True) # Now we have a list of projects, get associated pagination pagination = Paginator(project_list, results_requested) try: projects = pagination.page(page_requested) except PageNotAnInteger: projects = pagination.page(1) except EmptyPage: projects = pagination.page(pagination.num_pages) pagination.query_string = get_paging_params(request) pagination.display_pages = get_pages_to_display(pagination, projects, 3) return render(request, 'projects/list.html', { 'projects': projects, 'pagination': pagination, 'open_project_count': open_project_count, 'closed_project_count': closed_project_count, 'show_all': request.session['show_all'] })