Files
social-graph/backend/import_export/views.py
T
gitrusprusandCursor 4eb4c145b6 Add JWT auth with per-user data isolation and account settings.
Users can register, log in, and manage profile/password in a personal account page; server data is scoped by owner across contacts, maps, tags, and import.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 21:10:16 +03:00

26 lines
1.0 KiB
Python

from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from core.access import use_jwt_auth
from core.drf_mixins import JwtAuthMixin
from .services import parse_upload_file, import_contacts_from_rows
class ImportContactsView(JwtAuthMixin, APIView):
def post(self, request):
file = request.FILES.get('file')
if not file:
return Response({'error': 'Файл не передан.'}, status=status.HTTP_400_BAD_REQUEST)
try:
rows, error = parse_upload_file(file)
if error:
return Response({'error': error}, status=status.HTTP_400_BAD_REQUEST)
owner = request.user if use_jwt_auth() and request.user.is_authenticated else None
return Response(import_contacts_from_rows(rows, owner=owner))
except Exception as e:
return Response(
{'error': f'Ошибка разбора файла: {e}'},
status=status.HTTP_400_BAD_REQUEST,
)