Example #1
0
    def __init__(self, *args, **kwargs):
        """
        If we're in a recognised faceting engine, display and allow faceting.
        """
        super(PreSelectedModelSearchForm, self).__init__(*args, **kwargs)
        if 'models' in self.fields:
            self.fields['models'].initial = [x[0] for x in model_choices()]
            self.fields['models'].label = _("Only models")
        self.haystack_config = HaystackConfig()

        self.fields['content_field'].choices = content_field_choices()

        self.version = self.haystack_config.version
        if self.should_allow_faceting():
            possible_facets = self.configure_faceting()
            self.fields['possible_facets'].choices = possible_facets
            self.fields['selected_facets'] = SelectedFacetsField(
                choices=(), required=False, possible_facets=possible_facets)

        if self.has_multiple_connections():
            wtf = self.get_possible_connections()
            self.fields['connection'].choices = tuple(wtf)  # noqa
            self.fields['connection'].initial = 'default'
        else:
            self.fields['connection'].widget = HiddenInput()
Example #2
0
def test_get_valid_filters_version2():
    conf = HaystackConfig()
    filters = tuple((x, force_text(y)) for x, y in conf.get_valid_filters())
    assert filters == (('exact', 'exact'), ('gt', 'greater than'),
                       ('gte', 'greater than or equal to'), ('in', 'in'),
                       ('lt', 'less than'), ('lte', 'less than or equal to'),
                       ('range', 'range (inclusive)'), ('startswith',
                                                        'starts with'))