1 6
from django_elasticsearch_dsl_drf.constants import (
2
    LOOKUP_FILTER_REGEXP,
3
    LOOKUP_FILTER_TERM,
4
    LOOKUP_FILTER_WILDCARD
5
)
6 6
from django_elasticsearch_dsl_drf.filter_backends import (
7
    FilteringFilterBackend,
8
    OrderingFilterBackend,
9
    DefaultOrderingFilterBackend,
10
    SearchFilterBackend,
11
)
12 6
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet
13

14 6
from cyborgbackup.elasticsearch.documents.catalogs import CatalogDocument
15 6
from cyborgbackup.elasticsearch.serializers import ESCatalogDocumentSerializer
16

17

18 6
class ESCatalogViewSet(DocumentViewSet):
19 6
    document = CatalogDocument
20 6
    serializer_class = ESCatalogDocumentSerializer
21

22 6
    lookup_field = 'archive_name'
23 6
    filter_backends = [
24
        FilteringFilterBackend,
25
        OrderingFilterBackend,
26
        DefaultOrderingFilterBackend,
27
        SearchFilterBackend,
28
    ]
29

30
    # Define search fields
31 6
    search_fields = (
32
        'archive_name',
33
        'path',
34
    )
35

36
    # Filter fields
37 6
    filter_fields = {
38
        'path': {
39
            'field': 'path.keyword',
40
            'lookups': [
41
                LOOKUP_FILTER_REGEXP,
42
                LOOKUP_FILTER_TERM
43
            ]
44
        },
45
        'archive_name': {
46
            'field': 'archive_name.keyword',
47
            'lookups': [
48
                LOOKUP_FILTER_WILDCARD,
49
                LOOKUP_FILTER_REGEXP,
50
                LOOKUP_FILTER_TERM
51
            ]
52
        },
53
        'owner': 'owner.keyword',
54
        'group': 'group.keyword',
55
        'mtime': 'mtime.keyword',
56
        'mode': 'mode.keyword',
57
        'size': 'size',
58
        'job': 'job',
59
    }
60

61
    # Define ordering fields
62 6
    ordering_fields = {
63
        'path': 'path.keyword',
64
        'archive_name': 'archive_name.keyword'
65
    }
66

67
    # Specify default ordering
68 6
    ordering = ('archive_name', 'path')

Read our documentation on viewing source code .

Loading