fix: align media upload and gosedo records
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 1m13s
CI/CD Pipeline / Build and Push Images (push) Successful in 20s
CI/CD Pipeline / Internal Notify (push) Successful in 1s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 30s

This commit is contained in:
2026-08-20 11:43:00 +02:00
parent d95a002d84
commit f2e36a8991
5 changed files with 207 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ from apps.parsers.serializers import (
)
from apps.parsers.source_registry import PARSER_SOURCES, ParserSourceDescriptor
from apps.parsers.views import (
MEDIA_NEWS_UPLOAD_FILE_PARAM,
RESULT_DETAIL_PARAMS,
RESULT_LIST_PARAMS,
UPLOAD_FILE_PARAM,
@@ -123,7 +124,11 @@ def _upload_view(descriptor: ParserSourceDescriptor):
f"Ручная загрузка файла для источника: {descriptor.data_scope}. "
"Файл обрабатывается через Celery."
),
manual_parameters=[UPLOAD_FILE_PARAM],
manual_parameters=[
MEDIA_NEWS_UPLOAD_FILE_PARAM
if descriptor.key == "media_news"
else UPLOAD_FILE_PARAM
],
consumes=["multipart/form-data"],
tags=[tag],
responses={202: ParserRunResponseSerializer, 400: "Ошибка валидации"},

View File

@@ -19,6 +19,7 @@ from apps.core.serializers import BackgroundJobListSerializer
from apps.core.services import BackgroundJobService
from apps.parsers import tasks
from apps.parsers.fns_upload import FNSUploadService
from apps.parsers.media_news import MEDIA_NEWS_MAX_BYTES
from apps.parsers.models import (
VACANCY_RECORD_SOURCES,
FinancialReport,
@@ -374,6 +375,13 @@ UPLOAD_FILE_PARAM = openapi.Parameter(
type=openapi.TYPE_FILE,
required=True,
)
MEDIA_NEWS_UPLOAD_FILE_PARAM = openapi.Parameter(
"file",
openapi.IN_FORM,
description="XLSX-файл новостей СМИ размером не более 25 МиБ",
type=openapi.TYPE_FILE,
required=True,
)
RESULT_LIST_PARAMS = [
PAGE_PARAM,
PAGE_SIZE_PARAM,
@@ -2793,19 +2801,30 @@ class ParserUploadView(APIView):
)
serializer = ParserUploadRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
if source_key == "media_news" and not serializer.validated_data[
"file"
].name.lower().endswith(".xlsx"):
return api_error_response(
[
{
"code": "invalid_file_type",
"message": "Для новостей требуется XLSX",
}
],
status_code=status.HTTP_400_BAD_REQUEST,
)
uploaded_file = serializer.validated_data["file"]
if source_key == "media_news":
if not uploaded_file.name.lower().endswith(".xlsx"):
return api_error_response(
[
{
"code": "invalid_file_type",
"field": "file",
"message": "Для новостей требуется XLSX",
}
],
status_code=status.HTTP_400_BAD_REQUEST,
)
if uploaded_file.size > MEDIA_NEWS_MAX_BYTES:
return api_error_response(
[
{
"code": "file_too_large",
"field": "file",
"message": "Размер XLSX для новостей не должен превышать 25 МиБ",
}
],
status_code=status.HTTP_400_BAD_REQUEST,
)
file_path = _save_uploaded_parser_file(uploaded_file)
run_serializer = ParserRunRequestSerializer(data={"file_path": file_path})
run_serializer.is_valid(raise_exception=True)

View File

@@ -94,6 +94,8 @@ SOURCE_GROUP_VALUES = [choice.value for choice in SourceGroup]
SOURCE_RECORD_ORDERING_FIELDS = (
"record_date",
"record_type",
"external_id",
"extension__organization__name",
"extension__organization__full_name",
"created_at",
@@ -105,6 +107,9 @@ SOURCE_RECORD_ORDERING_FIELDS = (
"extension__organization__okpo",
"status",
"payload__attestation_status",
"payload__full_name",
"payload__medo_address",
"payload__registration_number",
"payload__sentiment",
"payload__news_source",
)
@@ -225,11 +230,14 @@ SOURCE_RECORD_LIST_PARAMS = [
_query_parameter(
"ordering",
description=(
"Сортировка по полям: record_date, extension__organization__name, "
"Сортировка по полям: record_date, record_type, external_id, "
"extension__organization__name, "
"extension__organization__full_name, created_at, updated_at, title, "
"uid, extension__organization__inn, extension__organization__ogrn, "
"extension__organization__okpo, status, "
"payload__attestation_status, payload__sentiment, "
"payload__attestation_status, payload__full_name, "
"payload__medo_address, payload__registration_number, "
"payload__sentiment, "
"payload__news_source. Для обратной сортировки используйте префикс -. "
"Значения record_date с null сортируются последними."
),