Beispiel #1
0
    def test_filters_list_field(self):

        filter_converter = CustomFilterConverter()
        filtes_list_field = (CustomFilterLike, CustomFilterNotLike, CustomFilterEmpty)

        result = filter_converter.convert('ListField', Journal.index_at, 'index_at')
        expected = [f(Journal.index_at, 'index_at') for f in filtes_list_field]

        self.assertListEqual([vars(i) for i in expected], [vars(i) for i in result])
    def test_filters_list_field(self):

        filter_converter = CustomFilterConverter()
        filtes_list_field = (CustomFilterLike, CustomFilterNotLike, CustomFilterEmpty)

        result = filter_converter.convert('ListField', Journal.index_at, 'index_at')
        expected = [f(Journal.index_at, 'index_at') for f in filtes_list_field]

        self.assertItemsEqual([vars(i) for i in expected], [vars(i) for i in result])
Beispiel #3
0
    def test_filters_reference_field(self):

        filter_converter = CustomFilterConverter()
        filtes_reference_field = (
            CustomFilterLike, CustomFilterNotLike, CustomFilterEqual,
            CustomFilterNotEqual, CustomFilterInList, CustomFilterNotInList)

        result = filter_converter.convert('ReferenceField', Issue.journal, 'journal')
        expected = [f(Issue.journal, 'journal') for f in filtes_reference_field]

        self.assertListEqual([vars(i) for i in expected], [vars(i) for i in result])
    def test_filters_reference_field(self):

        filter_converter = CustomFilterConverter()
        filtes_reference_field = (
            CustomFilterLike, CustomFilterNotLike, CustomFilterEqual,
            CustomFilterNotEqual, CustomFilterInList, CustomFilterNotInList)

        result = filter_converter.convert('ReferenceField', Issue.journal, 'journal')
        expected = [f(Issue.journal, 'journal') for f in filtes_reference_field]

        self.assertItemsEqual([vars(i) for i in expected], [vars(i) for i in result])
    def test_filters_embedded_field(self):

        filter_converter = CustomFilterConverter()
        filtes_embedded_field = (
            CustomFilterLike, CustomFilterNotLike, CustomFilterEqual,
            CustomFilterNotEqual, CustomFilterEmpty, CustomFilterInList,
            CustomFilterNotInList)

        result = filter_converter.convert('EmbeddedDocumentField', Journal.use_licenses, 'use_licenses')
        expected = [f(Journal.use_licenses, 'use_licenses') for f in filtes_embedded_field]

        self.assertItemsEqual([vars(i) for i in expected], [vars(i) for i in result])
Beispiel #6
0
class OpacBaseAdminView(mongoengine.ModelView):
    page_size = 20
    can_create = False
    can_edit = False
    can_delete = False
    create_modal = True
    edit_modal = True
    can_view_details = True
    allowed_search_types = (StringField, URLField, EmailField,
                            EmbeddedDocumentField, ReferenceField)
    filter_converter = CustomFilterConverter()
    object_id_converter = str

    def _search(self, query, search_term):
        op, term = parse_like_term(search_term)

        criteria = None

        for field in self._search_fields:
            flt = get_flt(field, term, op)

            if criteria is None:
                criteria = flt
            else:
                criteria |= flt
        return query.filter(criteria)

    def is_accessible(self):
        return login.current_user.is_authenticated