Skip to content
Snippets Groups Projects

Bump Python requirement psycopg2-binary to 2.9.10

Closed Teklia Bot requested to merge bump-psycopg2-binary into master
Files
149
@@ -61,6 +61,7 @@ from arkindex.documents.models import (
from arkindex.documents.serializers.elements import (
CorpusSerializer,
ElementBulkSerializer,
ElementChildrenCreateSerializer,
ElementCreateSerializer,
ElementDestinationSerializer,
ElementListSerializer,
@@ -98,7 +99,7 @@ from arkindex.training.models import DatasetElement, ModelVersion
from arkindex.users.models import Role
from arkindex.users.utils import filter_rights
classifications_queryset = Classification.objects.select_related("ml_class", "worker_version").order_by("-confidence")
classifications_queryset = Classification.objects.select_related("ml_class", "worker_run").order_by("-confidence")
def _fetch_has_children(elements):
@@ -356,7 +357,7 @@ class ElementsListAutoSchema(AutoSchema):
* `eq` (default): Elements having a classification with this exact confidence.
* `lt`: Elements having a classification with a confidence strictly lower than the filter.
* `lte`: Elements having a classification with a confidence lower than or equal to the filter.
* `lt`: Elements having a classification with a confidence strictly greater than the filter.
* `gt`: Elements having a classification with a confidence strictly greater than the filter.
* `gte`: Elements having a classification with a confidence greater than or equal to the filter.
This requires `classification_confidence` to be set.
@@ -394,7 +395,7 @@ class ElementsListAutoSchema(AutoSchema):
* `eq` (default): Elements having a transcription with this exact confidence.
* `lt`: Elements having a transcription with a confidence strictly lower than the filter.
* `lte`: Elements having a transcription with a confidence lower than or equal to the filter.
* `lt`: Elements having a transcription with a confidence strictly greater than the filter.
* `gt`: Elements having a transcription with a confidence strictly greater than the filter.
* `gte`: Elements having a transcription with a confidence greater than or equal to the filter.
This requires `transcription_confidence` to be set.
@@ -475,6 +476,13 @@ class ElementsListAutoSchema(AutoSchema):
type=bool,
required=False,
),
OpenApiParameter(
"with_transcriptions",
description="Returns all transcriptions for each element. "
"Otherwise, `transcriptions` will always be null.",
type=bool,
required=False,
),
OpenApiParameter(
"with_has_children",
description="Include the `has_children` boolean to tell if each element has direct children. "
@@ -924,6 +932,14 @@ class ElementsListBase(CorpusACLMixin, DestroyModelMixin, ListAPIView):
to_attr="prefetched_metadata",
))
with_transcriptions = self.clean_params.get("with_transcriptions")
if with_transcriptions and with_transcriptions.lower() not in ("false", "0"):
prefetch.add(Prefetch(
"transcriptions",
queryset=Transcription.objects.select_related("worker_run").order_by("-confidence"),
to_attr="prefetched_transcriptions"
))
return prefetch
@property
@@ -1195,6 +1211,41 @@ class ElementChildren(ElementsListBase):
return Element.objects.all().distinct()
class ElementChildrenCreate(CreateAPIView):
"""
Add an element as a parent to multiple elements at once.
Requires contributor access to the corpus.
The child elements must be in the same corpus as the parent to add.
Elements that have child elements are not supported.
"""
serializer_class = ElementChildrenCreateSerializer
permission_classes = (IsVerified, )
def get_queryset(self):
return Element.objects.filter(corpus__in=Corpus.objects.writable(self.request.user)).prefetch_related("paths")
@cached_property
def parent(self):
return self.get_object()
def get_serializer_context(self):
context = super().get_serializer_context()
# The OpenAPI schema generator creates a fake request without a parent ID set
if self.lookup_field not in self.kwargs:
return context
context["parent"] = self.parent
return context
@extend_schema(
operation_id="CreateElementChildren",
tags=["elements"],
)
@transaction.atomic
def post(self, *args, **kwargs):
return super().post(*args, **kwargs)
@extend_schema(tags=["elements"])
@extend_schema_view(
get=extend_schema(description="Retrieve a single element's information and metadata"),
@@ -1502,6 +1553,8 @@ class CorpusList(ListCreateAPIView):
serializer_class = CorpusSerializer
pagination_class = None
permission_classes = (IsVerifiedOrReadOnly, )
# Used by OpenAPI schema generation to get the view's model without making any SQL queries
queryset = Corpus.objects.none()
def get_queryset(self):
# We need to prefetch the access rights on each corpora
Loading