commonground-api-common 2.6.3__py3-none-any.whl → 2.6.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {commonground_api_common-2.6.3.dist-info → commonground_api_common-2.6.4.dist-info}/METADATA +1 -1
- {commonground_api_common-2.6.3.dist-info → commonground_api_common-2.6.4.dist-info}/RECORD +10 -9
- {commonground_api_common-2.6.3.dist-info → commonground_api_common-2.6.4.dist-info}/WHEEL +1 -1
- vng_api_common/__init__.py +1 -1
- vng_api_common/conf/api.py +1 -1
- vng_api_common/filters.py +0 -49
- vng_api_common/filters_backend.py +61 -0
- vng_api_common/viewsets.py +1 -1
- {commonground_api_common-2.6.3.data → commonground_api_common-2.6.4.data}/scripts/generate_schema +0 -0
- {commonground_api_common-2.6.3.dist-info → commonground_api_common-2.6.4.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
|
-
commonground_api_common-2.6.
|
2
|
-
vng_api_common/__init__.py,sha256=
|
1
|
+
commonground_api_common-2.6.4.data/scripts/generate_schema,sha256=OpKgzlFc_uzA3TVW_vHSYXAD_feLaCdTEnkWjIcxVzA,280
|
2
|
+
vng_api_common/__init__.py,sha256=ODIwI6SfzWmx_FdtwCfr6k5TmpNuA5JdvGyV-9G9YrM,22
|
3
3
|
vng_api_common/admin.py,sha256=iFtUPGf-ha0I-bXgq8QIFrP23Kzk_H3FlgAjt0U-ip0,259
|
4
4
|
vng_api_common/apps.py,sha256=QQiJXRmjX9Q91oh0P9fvVnHe3NSYd1cEcUUBw0HLBCA,3690
|
5
5
|
vng_api_common/checks.py,sha256=tOyfV7MMLGh4anrd_W30LvJCxiyQ4sFs1mGd9mtrEc0,1175
|
@@ -13,7 +13,8 @@ vng_api_common/doc.py,sha256=a4Wm6Y-Va-tBsLwZFjPX_oA4PppkDR4wpIiw9q7NLd4,1167
|
|
13
13
|
vng_api_common/exception_handling.py,sha256=Z8Si1-GPWaTtsgaFI_zLOvlnLVLM8jqfgFIimX8eo-8,4759
|
14
14
|
vng_api_common/exceptions.py,sha256=7Qk5dlETjoQjZeGRKei4PkeLACLoZOMrMiuyi-yn6Kk,615
|
15
15
|
vng_api_common/fields.py,sha256=SXY0HB9NiDVmlKdjBDy3b55E4rn-qboiIMBr_eOBuZE,6302
|
16
|
-
vng_api_common/filters.py,sha256=
|
16
|
+
vng_api_common/filters.py,sha256=mfpew4NkUy4AIqXDg5rE1tzUl8Ae9FTmYz9_MKjjLuA,3763
|
17
|
+
vng_api_common/filters_backend.py,sha256=bb8D0Z6uT39PW5ASqlExTesALOVAplJgG4hR7ikG2BI,2096
|
17
18
|
vng_api_common/filtersets.py,sha256=CpmuOg6jGKFDwVeCusax-CBI7tv-EuOSBLwewdkLu1Y,1256
|
18
19
|
vng_api_common/generators.py,sha256=88yQN5-vRFUegfzQcsZtlpbtQyn_zZQwvs20OidPK7M,1239
|
19
20
|
vng_api_common/geo.py,sha256=AZbrw0rwGYOmaSUk8JJSkx-4_tVrfT_cgggh9omRwhU,1862
|
@@ -34,7 +35,7 @@ vng_api_common/utils.py,sha256=EHqVjZhtqnbU7YrqgYIBss28Sd19jtnTLNaMWLfj3Zw,8203
|
|
34
35
|
vng_api_common/validators.py,sha256=ejaFZvFXFaBlqxjA2_07NSHKHlG5pejrfC_GHjwCj6E,12852
|
35
36
|
vng_api_common/version.py,sha256=yJV9_yTM7Qnzg0zGNkJQkN9Uai3I_ZUkcyseJRPRk5I,129
|
36
37
|
vng_api_common/views.py,sha256=pxpI2dl22I9auTYvRJ-Rx-_NHAKgo1F2QwQJF6WIjrE,7603
|
37
|
-
vng_api_common/viewsets.py,sha256=
|
38
|
+
vng_api_common/viewsets.py,sha256=jAXKHFRBhNKzkjugpYnXkE2zKvCWwKwZA6_VoiTWjvw,2286
|
38
39
|
vng_api_common/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
40
|
vng_api_common/api/permissions.py,sha256=okbwiscxlAtbQWTCRDLL2reOxgj0rRDZeDcrtXAYq00,739
|
40
41
|
vng_api_common/api/serializers.py,sha256=F1od8SZxgIlGVTSd_x5eTxacL6x8HbNn35O9z1zjio4,213
|
@@ -106,7 +107,7 @@ vng_api_common/caching/models.py,sha256=RroS9HFiKNXDV59Odh0x8BO8Az8E81v4gwuprF1A
|
|
106
107
|
vng_api_common/caching/registry.py,sha256=mY1r99x7m0DQ1BN9lZF2zMjFj_oDNq7urxDkOH7-8Yg,6205
|
107
108
|
vng_api_common/caching/signals.py,sha256=78ej5cVan-JpNHKzZNAfs0m2ON_TXKphe8ZKtP-6FVY,4615
|
108
109
|
vng_api_common/conf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
109
|
-
vng_api_common/conf/api.py,sha256=
|
110
|
+
vng_api_common/conf/api.py,sha256=tNShwZevKpJ6n713pPGPuUpThcPq-057JAd3xSHW5sU,3158
|
110
111
|
vng_api_common/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
111
112
|
vng_api_common/contrib/setup_configuration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
112
113
|
vng_api_common/contrib/setup_configuration/models.py,sha256=1-G0hXeRe-x6GYtsAaQeMGXq0-cwU5LMb8KTQWj-pQk,1201
|
@@ -183,7 +184,7 @@ vng_api_common/tests/auth.py,sha256=IKDWTEFv4Bign4F70-ibsFcnJqRxEJaXvqaPQJWa1xY,
|
|
183
184
|
vng_api_common/tests/caching.py,sha256=zfIw5cRRvO9cekHZZKfRqZc8cx5IfJUYNmcH6cuIMg4,624
|
184
185
|
vng_api_common/tests/schema.py,sha256=WDvifDQQiKqIpQijpeQ7rYkFroJmuPuHe7zNhl1Bigk,2293
|
185
186
|
vng_api_common/tests/urls.py,sha256=PFrYzQbBC0TFPMEn3uPhcBG0IQs9JsEPqckicJT1UA4,2159
|
186
|
-
commonground_api_common-2.6.
|
187
|
-
commonground_api_common-2.6.
|
188
|
-
commonground_api_common-2.6.
|
189
|
-
commonground_api_common-2.6.
|
187
|
+
commonground_api_common-2.6.4.dist-info/METADATA,sha256=3ukeRcXs4xAZnPuryteaoyPCP7SHHYFMa6tIAxgP6HM,6969
|
188
|
+
commonground_api_common-2.6.4.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
189
|
+
commonground_api_common-2.6.4.dist-info/top_level.txt,sha256=vPismc83zPzWXTmlNCCwfDlFV9iygJYxNJW5iDjKTgw,15
|
190
|
+
commonground_api_common-2.6.4.dist-info/RECORD,,
|
vng_api_common/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "2.6.
|
1
|
+
__version__ = "2.6.4"
|
vng_api_common/conf/api.py
CHANGED
@@ -33,7 +33,7 @@ BASE_REST_FRAMEWORK = {
|
|
33
33
|
# of applications
|
34
34
|
"DEFAULT_AUTHENTICATION_CLASSES": (),
|
35
35
|
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning",
|
36
|
-
"DEFAULT_FILTER_BACKENDS": ("vng_api_common.
|
36
|
+
"DEFAULT_FILTER_BACKENDS": ("vng_api_common.filters_backend.Backend",),
|
37
37
|
#
|
38
38
|
# # Filtering
|
39
39
|
"ORDERING_PARAM": "ordering", # 'ordering',
|
vng_api_common/filters.py
CHANGED
@@ -5,67 +5,18 @@ from django.core.exceptions import ValidationError
|
|
5
5
|
from django.core.validators import URLValidator
|
6
6
|
from django.db import models
|
7
7
|
from django.forms.widgets import URLInput
|
8
|
-
from django.http import QueryDict
|
9
8
|
from django.utils.translation import gettext_lazy as _
|
10
9
|
|
11
10
|
from django_filters import fields, filters
|
12
11
|
from django_filters.constants import EMPTY_VALUES
|
13
|
-
from django_filters.rest_framework import DjangoFilterBackend
|
14
|
-
from djangorestframework_camel_case.parser import CamelCaseJSONParser
|
15
|
-
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
|
16
|
-
from djangorestframework_camel_case.util import underscoreize
|
17
|
-
from rest_framework.request import Request
|
18
|
-
from rest_framework.views import APIView
|
19
12
|
|
20
13
|
from .constants import FILTER_URL_DID_NOT_RESOLVE
|
21
|
-
from .search import is_search_view
|
22
14
|
from .utils import NotAViewSet, get_resource_for_path
|
23
15
|
from .validators import validate_rsin
|
24
16
|
|
25
17
|
logger = logging.getLogger(__name__)
|
26
18
|
|
27
19
|
|
28
|
-
class Backend(DjangoFilterBackend):
|
29
|
-
def _is_camel_case(self, view):
|
30
|
-
return any(
|
31
|
-
issubclass(parser, CamelCaseJSONParser) for parser in view.parser_classes
|
32
|
-
) or any(
|
33
|
-
issubclass(renderer, CamelCaseJSONRenderer)
|
34
|
-
for renderer in view.renderer_classes
|
35
|
-
)
|
36
|
-
|
37
|
-
def _transform_query_params(self, view, query_params: QueryDict) -> QueryDict:
|
38
|
-
if not self._is_camel_case(view):
|
39
|
-
return query_params
|
40
|
-
|
41
|
-
# data can be a regular dict if it's coming from a serializer
|
42
|
-
if hasattr(query_params, "lists"):
|
43
|
-
data = dict(query_params.lists())
|
44
|
-
else:
|
45
|
-
data = query_params
|
46
|
-
|
47
|
-
transformed = underscoreize(data)
|
48
|
-
|
49
|
-
return QueryDict(urlencode(transformed, doseq=True))
|
50
|
-
|
51
|
-
def get_filterset_kwargs(
|
52
|
-
self, request: Request, queryset: models.QuerySet, view: APIView
|
53
|
-
):
|
54
|
-
"""
|
55
|
-
Get the initialization parameters for the filterset.
|
56
|
-
|
57
|
-
* filter on request.data if request.query_params is empty
|
58
|
-
* do the camelCase transformation of filter parameters
|
59
|
-
"""
|
60
|
-
kwargs = super().get_filterset_kwargs(request, queryset, view)
|
61
|
-
filter_parameters = (
|
62
|
-
request.query_params if not is_search_view(view) else request.data
|
63
|
-
)
|
64
|
-
query_params = self._transform_query_params(view, filter_parameters)
|
65
|
-
kwargs["data"] = query_params
|
66
|
-
return kwargs
|
67
|
-
|
68
|
-
|
69
20
|
class URLModelChoiceField(fields.ModelChoiceField):
|
70
21
|
widget = URLInput
|
71
22
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import logging
|
2
|
+
from urllib.parse import urlencode
|
3
|
+
|
4
|
+
from django.db import models
|
5
|
+
from django.http import QueryDict
|
6
|
+
from django.utils.translation import gettext_lazy as _
|
7
|
+
|
8
|
+
from django_filters.rest_framework import DjangoFilterBackend
|
9
|
+
from djangorestframework_camel_case.parser import CamelCaseJSONParser
|
10
|
+
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
|
11
|
+
from djangorestframework_camel_case.util import underscoreize
|
12
|
+
from rest_framework.request import Request
|
13
|
+
from rest_framework.views import APIView
|
14
|
+
|
15
|
+
from .filtersets import FilterSet
|
16
|
+
from .search import is_search_view
|
17
|
+
|
18
|
+
logger = logging.getLogger(__name__)
|
19
|
+
|
20
|
+
|
21
|
+
class Backend(DjangoFilterBackend):
|
22
|
+
filterset_base = FilterSet
|
23
|
+
|
24
|
+
def _is_camel_case(self, view):
|
25
|
+
return any(
|
26
|
+
issubclass(parser, CamelCaseJSONParser) for parser in view.parser_classes
|
27
|
+
) or any(
|
28
|
+
issubclass(renderer, CamelCaseJSONRenderer)
|
29
|
+
for renderer in view.renderer_classes
|
30
|
+
)
|
31
|
+
|
32
|
+
def _transform_query_params(self, view, query_params: QueryDict) -> QueryDict:
|
33
|
+
if not self._is_camel_case(view):
|
34
|
+
return query_params
|
35
|
+
|
36
|
+
# data can be a regular dict if it's coming from a serializer
|
37
|
+
if hasattr(query_params, "lists"):
|
38
|
+
data = dict(query_params.lists())
|
39
|
+
else:
|
40
|
+
data = query_params
|
41
|
+
|
42
|
+
transformed = underscoreize(data)
|
43
|
+
|
44
|
+
return QueryDict(urlencode(transformed, doseq=True))
|
45
|
+
|
46
|
+
def get_filterset_kwargs(
|
47
|
+
self, request: Request, queryset: models.QuerySet, view: APIView
|
48
|
+
):
|
49
|
+
"""
|
50
|
+
Get the initialization parameters for the filterset.
|
51
|
+
|
52
|
+
* filter on request.data if request.query_params is empty
|
53
|
+
* do the camelCase transformation of filter parameters
|
54
|
+
"""
|
55
|
+
kwargs = super().get_filterset_kwargs(request, queryset, view)
|
56
|
+
filter_parameters = (
|
57
|
+
request.query_params if not is_search_view(view) else request.data
|
58
|
+
)
|
59
|
+
query_params = self._transform_query_params(view, filter_parameters)
|
60
|
+
kwargs["data"] = query_params
|
61
|
+
return kwargs
|
vng_api_common/viewsets.py
CHANGED
@@ -6,7 +6,7 @@ from rest_framework.pagination import PageNumberPagination
|
|
6
6
|
from rest_framework.settings import api_settings
|
7
7
|
from rest_framework_nested.viewsets import NestedViewSetMixin # noqa
|
8
8
|
|
9
|
-
from .
|
9
|
+
from .filters_backend import Backend
|
10
10
|
from .utils import underscore_to_camel
|
11
11
|
|
12
12
|
|
{commonground_api_common-2.6.3.data → commonground_api_common-2.6.4.data}/scripts/generate_schema
RENAMED
File without changes
|
{commonground_api_common-2.6.3.dist-info → commonground_api_common-2.6.4.dist-info}/top_level.txt
RENAMED
File without changes
|