Example #1
0
def process_select_search_haystack(request, select_key):
    try:
        data = get_select_data(request, select_key)
    except KeyError:
        return _cant_get_key(request)

    form = FacetedSearchForm(request.GET)
    if not form.is_valid():  # do not think this can happen
        raise ValueError
    cd = form.cleaned_data
    if cd['q']:
        context = {'select_key': select_key}
        allowed_selects = []
        for select in ['publisher', 'series', 'issue', 'story']:
            if data.get(select, False):
                allowed_selects.append(select)
        context['allowed_selects'] = allowed_selects
        sqs = GcdSearchQuerySet().facet('facet_model_name')
        return PaginatedFacetedSearchView(searchqueryset=sqs)(request,
                                                              context=context)
    else:
        return HttpResponseRedirect(
          urlresolvers.reverse('select_object',
                               kwargs={'select_key': select_key})
          + '?' + request.META['QUERY_STRING'])
Example #2
0
def process_select_search_haystack(request, select_key):
    try:
        data = get_select_data(request, select_key)
    except KeyError:
        return _cant_get_key(request)

    form = FacetedSearchForm(request.GET)
    if not form.is_valid():  # do not think this can happen
        raise ValueError
    cd = form.cleaned_data
    if cd['q']:
        context = {'select_key': select_key}
        allowed_selects = []
        for select in ['publisher', 'series', 'issue', 'story']:
            if data.get(select, False):
                allowed_selects.append(select)
        context['allowed_selects'] = allowed_selects
        sqs = GcdSearchQuerySet().facet('facet_model_name')
        return PaginatedFacetedSearchView(searchqueryset=sqs)(request,
                                                              context=context)
    else:
        return HttpResponseRedirect(
            urlresolvers.reverse('select_object',
                                 kwargs={'select_key': select_key}) + '?' +
            request.META['QUERY_STRING'])
Example #3
0
def process_select_search_haystack(request, select_key):
    try:
        data = get_select_data(request, select_key)
    except KeyError:
        return _cant_get_key(request)

    form = FacetedSearchForm(request.GET)
    if not form.is_valid():  # do not think this can happen
        raise ValueError
    cd = form.cleaned_data
    if cd["q"]:
        context = {"select_key": select_key}
        allowed_selects = []
        for select in ["publisher", "series", "issue", "story"]:
            if data.get(select, False):
                allowed_selects.append(select)
        context["allowed_selects"] = allowed_selects
        sqs = GcdSearchQuerySet().facet("facet_model_name")
        return PaginatedFacetedSearchView(searchqueryset=sqs)(request, context=context)
    else:
        return HttpResponseRedirect(
            urlresolvers.reverse("select_object", kwargs={"select_key": select_key})
            + "?"
            + request.META["QUERY_STRING"]
        )
Example #4
0
class FacetedSearchFormTestCase(TestCase):
    def setUp(self):
        super(FacetedSearchFormTestCase, self).setUp()
        self.sqs = SearchQuerySet(query=DummySearchQuery(backend=DummySearchBackend()), site=None)
        
        self.target = FacetedSearchForm(data={'selected_facets': 'foo, bar'},
                                        searchqueryset=self.sqs)
    
    def test_selected_facets(self):
        self.assertTrue(self.target.is_valid())
        result = self.target.search()
        self.assertEquals(result.query.narrow_queries, set(['foo', 'bar']))
        
Example #5
0
    def test_search(self):
        sf = FacetedSearchForm(
            {"q": "test"}, selected_facets=[], searchqueryset=self.sqs
        )
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries, set())

        # Test the "skip no-colon" bits.
        sf = FacetedSearchForm(
            {"q": "test"}, selected_facets=["authordaniel"], searchqueryset=self.sqs
        )
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries, set())

        sf = FacetedSearchForm(
            {"q": "test"}, selected_facets=["author:daniel"], searchqueryset=self.sqs
        )
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries, set(['author:"daniel"']))

        sf = FacetedSearchForm(
            {"q": "test"},
            selected_facets=["author:daniel", "author:chris"],
            searchqueryset=self.sqs,
        )
        sqs = sf.search()
        self.assertEqual(
            sqs.query.narrow_queries, set(['author:"daniel"', 'author:"chris"'])
        )
Example #6
0
    def test_init_with_selected_facets(self):
        sf = FacetedSearchForm({}, searchqueryset=self.sqs)
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, [])

        sf = FacetedSearchForm({}, selected_facets=[], searchqueryset=self.sqs)
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, [])

        sf = FacetedSearchForm(
            {}, selected_facets=["author:daniel"], searchqueryset=self.sqs
        )
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, ["author:daniel"])

        sf = FacetedSearchForm(
            {},
            selected_facets=["author:daniel", "author:chris"],
            searchqueryset=self.sqs,
        )
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, ["author:daniel", "author:chris"])
    def test_search(self):
        sf = FacetedSearchForm({'q': 'test'},
                               selected_facets=[],
                               searchqueryset=self.sqs)
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries, set())

        # Test the "skip no-colon" bits.
        sf = FacetedSearchForm({'q': 'test'},
                               selected_facets=['authordaniel'],
                               searchqueryset=self.sqs)
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries, set())

        sf = FacetedSearchForm({'q': 'test'},
                               selected_facets=['author:daniel'],
                               searchqueryset=self.sqs)
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries, set(['author:"daniel"']))

        sf = FacetedSearchForm(
            {'q': 'test'},
            selected_facets=['author:daniel', 'author:chris'],
            searchqueryset=self.sqs)
        sqs = sf.search()
        self.assertEqual(sqs.query.narrow_queries,
                         set(['author:"daniel"', 'author:"chris"']))
    def test_init_with_selected_facets(self):
        sf = FacetedSearchForm({}, searchqueryset=self.sqs)
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, [])

        sf = FacetedSearchForm({}, selected_facets=[], searchqueryset=self.sqs)
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, [])

        sf = FacetedSearchForm({},
                               selected_facets=['author:daniel'],
                               searchqueryset=self.sqs)
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, ['author:daniel'])

        sf = FacetedSearchForm(
            {},
            selected_facets=['author:daniel', 'author:chris'],
            searchqueryset=self.sqs)
        self.assertEqual(sf.errors, {})
        self.assertEqual(sf.is_valid(), True)
        self.assertEqual(sf.selected_facets, ['author:daniel', 'author:chris'])
Example #9
0
def select_object(request, select_key):
    try:
        data = get_select_data(request, select_key)
    except KeyError:
        return _cant_get_key(request)
    if request.method == 'GET':
        if 'refine_search' in request.GET or 'search_issue' in request.GET:
            request_data = request.GET
        else:
            request_data = None
        initial = data.get('initial', {})
        initial['select_key'] = select_key
        publisher = data.get('publisher', False)
        series = data.get('series', False)
        issue = data.get('issue', False)
        story = data.get('story', False)
        search_form, cache_form = get_select_forms(request,
                                                   initial,
                                                   request_data,
                                                   publisher=publisher,
                                                   series=series,
                                                   issue=issue,
                                                   story=story)
        haystack_form = FacetedSearchForm()
        return render(
            request, 'oi/edit/select_object.html', {
                'heading': data['heading'],
                'select_key': select_key,
                'cache_form': cache_form,
                'search_form': search_form,
                'haystack_form': haystack_form,
                'publisher': publisher,
                'series': series,
                'issue': issue,
                'story': story,
                'target': data['target']
            })

    if 'cancel' in request.POST:
        return data['cancel']
    elif 'select_object' in request.POST:
        try:
            choice = request.POST['object_choice']
            object_type, selected_id = choice.split('_')
            if object_type == 'cover':
                object_type = 'story'
        except MultiValueDictKeyError:
            return render_error(request, 'You did not select a cached object. '
                                'Please use the back button to return.',
                                redirect=False)
    elif 'search_select' in request.POST:
        choice = request.POST['object_choice']
        object_type, selected_id = choice.split('_')
    elif 'entered_issue_id' in request.POST:
        object_type = 'issue'
        try:
            selected_id = int(request.POST['entered_issue_id'])
        except ValueError:
            return render_error(request,
                                'Entered Id must be an integer number. '
                                'Please use the back button to return.',
                                redirect=False)
    elif 'entered_story_id' in request.POST:
        object_type = 'story'
        try:
            selected_id = int(request.POST['entered_story_id'])
        except ValueError:
            return render_error(request,
                                'Entered Id must be an integer number. '
                                'Please use the back button to return.',
                                redirect=False)
    else:
        raise ValueError
    return data['return'](request, data, object_type, selected_id)
Example #10
0
 def setUp(self):
     super(FacetedSearchFormTestCase, self).setUp()
     self.sqs = SearchQuerySet(query=DummySearchQuery(backend=DummySearchBackend()), site=None)
     
     self.target = FacetedSearchForm(data={'selected_facets': 'foo, bar'},
                                     searchqueryset=self.sqs)