mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00

- enable CORS for localhost calls - add Filter to allow API calls that can select Documents without any tag
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
from django_filters.rest_framework import CharFilter, FilterSet, BooleanFilter
|
|
|
|
from .models import Correspondent, Document, Tag
|
|
|
|
|
|
class CorrespondentFilterSet(FilterSet):
|
|
|
|
class Meta(object):
|
|
model = Correspondent
|
|
fields = {
|
|
"name": [
|
|
"startswith", "endswith", "contains",
|
|
"istartswith", "iendswith", "icontains"
|
|
],
|
|
"slug": ["istartswith", "iendswith", "icontains"]
|
|
}
|
|
|
|
|
|
class TagFilterSet(FilterSet):
|
|
|
|
class Meta(object):
|
|
model = Tag
|
|
fields = {
|
|
"name": [
|
|
"startswith", "endswith", "contains",
|
|
"istartswith", "iendswith", "icontains"
|
|
],
|
|
"slug": ["istartswith", "iendswith", "icontains"]
|
|
}
|
|
|
|
|
|
class DocumentFilterSet(FilterSet):
|
|
|
|
CHAR_KWARGS = {
|
|
"lookup_expr": (
|
|
"startswith",
|
|
"endswith",
|
|
"contains",
|
|
"istartswith",
|
|
"iendswith",
|
|
"icontains"
|
|
)
|
|
}
|
|
|
|
correspondent__name = CharFilter(name="correspondent__name", **CHAR_KWARGS)
|
|
correspondent__slug = CharFilter(name="correspondent__slug", **CHAR_KWARGS)
|
|
tags__name = CharFilter(name="tags__name", **CHAR_KWARGS)
|
|
tags__slug = CharFilter(name="tags__slug", **CHAR_KWARGS)
|
|
tags__empty = BooleanFilter(name='tags', lookup_expr='isnull', distinct=True)
|
|
|
|
class Meta(object):
|
|
model = Document
|
|
fields = {
|
|
"title": [
|
|
"startswith", "endswith", "contains",
|
|
"istartswith", "iendswith", "icontains"
|
|
],
|
|
"content": ["contains", "icontains"],
|
|
}
|