Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/rest_framework/schemas/utils.py: 15%
21 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1"""
2utils.py # Shared helper functions
4See schemas.__init__.py for package overview.
5"""
6from django.db import models
7from django.utils.translation import gettext_lazy as _
9from rest_framework.mixins import RetrieveModelMixin
12def is_list_view(path, method, view):
13 """
14 Return True if the given path/method appears to represent a list view.
15 """
16 if hasattr(view, 'action'):
17 # Viewsets have an explicitly defined action, which we can inspect.
18 return view.action == 'list'
20 if method.lower() != 'get':
21 return False
22 if isinstance(view, RetrieveModelMixin):
23 return False
24 path_components = path.strip('/').split('/')
25 if path_components and '{' in path_components[-1]:
26 return False
27 return True
30def get_pk_description(model, model_field):
31 if isinstance(model_field, models.AutoField):
32 value_type = _('unique integer value')
33 elif isinstance(model_field, models.UUIDField):
34 value_type = _('UUID string')
35 else:
36 value_type = _('unique value')
38 return _('A {value_type} identifying this {name}.').format(
39 value_type=value_type,
40 name=model._meta.verbose_name,
41 )