def test_filter_query_string(self): """ Test the filter query string definition. """ test_dict = {'test': '1'} query_dict = QueryDict('', mutable=True) query_dict.update(test_dict) new_query_string = filter_query_string(query_dict) self.assertEqual(new_query_string, '&test=1')
def directory(request): """The Organisation list view.""" qs = remove_empty_querydict_items(request.GET) # Set show_filters to "in" if any filter is selected filter_class = show_filter_class(qs, [ 'location', ]) # Yank Organisation collection all_organisations = _organisation_directory_coll(request) # Easter egg feature creator_organisations = request.GET.get('creator', False) if creator_organisations: all_organisations = all_organisations.filter(can_create_projects=True) f = OrganisationFilter(qs, queryset=all_organisations) # Change filter options further when on an Akvo Page if request.rsr_page: # Filter location filter list to only populated locations f.filters['location'].extra['choices'] = location_choices( all_organisations) # Build page page = request.GET.get('page') page, paginator, page_range = pagination(page, f.qs.distinct(), 10) # Get organisations to be displayed on the map if request.rsr_page and request.rsr_page.all_maps: map_orgs = all_organisations else: map_orgs = page.object_list map_orgs = map_orgs # Get related objects of page at once page.object_list = page.object_list.prefetch_related('locations') return render( request, 'organisation_directory.html', { 'orgs_count': f.qs.distinct().count(), 'filter': f, 'page': page, 'paginator': paginator, 'page_range': page_range, 'show_filters': filter_class, 'q': filter_query_string(qs), 'map_organisations': map_orgs, })
def directory(request): """The Organisation list view.""" qs = remove_empty_querydict_items(request.GET) # Set show_filters to "in" if any filter is selected filter_class = show_filter_class(qs, ['location', ]) # Yank Organisation collection all_organisations = _organisation_directory_coll(request) # Easter egg feature creator_organisations = request.GET.get('creator', False) if creator_organisations: all_organisations = all_organisations.filter(can_create_projects=True) f = OrganisationFilter(qs, queryset=all_organisations) # Change filter options further when on an Akvo Page if request.rsr_page: # Filter location filter list to only populated locations f.filters['location'].extra['choices'] = location_choices(all_organisations) # Build page page = request.GET.get('page') page, paginator, page_range = pagination(page, f.qs.distinct(), 10) # Get organisations to be displayed on the map if request.rsr_page and request.rsr_page.all_maps: map_orgs = all_organisations else: map_orgs = page.object_list map_orgs = map_orgs # Get related objects of page at once page.object_list = page.object_list.prefetch_related('locations') return render(request, 'organisation_directory.html', { 'orgs_count': f.qs.distinct().count(), 'filter': f, 'page': page, 'paginator': paginator, 'page_range': page_range, 'show_filters': filter_class, 'q': filter_query_string(qs), 'map_organisations': map_orgs, })