|
|
|
@ -2,7 +2,6 @@ |
|
|
|
import re |
|
|
|
import re |
|
|
|
import json |
|
|
|
import json |
|
|
|
from .serializers import DataAccessSerializer |
|
|
|
from .serializers import DataAccessSerializer |
|
|
|
from django.db.models import Q |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from rest_framework import viewsets |
|
|
|
from rest_framework import viewsets |
|
|
|
from rest_framework.views import APIView |
|
|
|
from rest_framework.views import APIView |
|
|
|
@ -10,9 +9,10 @@ from rest_framework.permissions import IsAuthenticated |
|
|
|
from rest_framework.response import Response |
|
|
|
from rest_framework.response import Response |
|
|
|
from rest_framework import status |
|
|
|
from rest_framework import status |
|
|
|
|
|
|
|
|
|
|
|
# from django.apps import apps |
|
|
|
|
|
|
|
from django.utils import timezone |
|
|
|
from django.utils import timezone |
|
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
|
|
|
|
from django.db import transaction |
|
|
|
|
|
|
|
from django.db.models import Q |
|
|
|
|
|
|
|
|
|
|
|
from collections import defaultdict |
|
|
|
from collections import defaultdict |
|
|
|
from urllib.parse import unquote |
|
|
|
from urllib.parse import unquote |
|
|
|
@ -101,12 +101,11 @@ class SynchronizationApi(HierarchyApiView): |
|
|
|
for op in operations: |
|
|
|
for op in operations: |
|
|
|
result = None |
|
|
|
result = None |
|
|
|
message = None |
|
|
|
message = None |
|
|
|
|
|
|
|
model_operation = op.get('operation') |
|
|
|
|
|
|
|
model_name = op.get('model_name') |
|
|
|
|
|
|
|
data = op.get('data') |
|
|
|
try: |
|
|
|
try: |
|
|
|
model_operation = op.get('operation') |
|
|
|
print(f'{model_operation} : {model_name}, id = {data['id']}') |
|
|
|
model_name = op.get('model_name') |
|
|
|
|
|
|
|
data = op.get('data') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f'{model_operation} : {model_name}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
models.add(model_name) |
|
|
|
models.add(model_name) |
|
|
|
|
|
|
|
|
|
|
|
@ -148,19 +147,19 @@ class SynchronizationApi(HierarchyApiView): |
|
|
|
try: |
|
|
|
try: |
|
|
|
instance = get_data(model_name, data_id) |
|
|
|
instance = get_data(model_name, data_id) |
|
|
|
instance._device_id = device_id |
|
|
|
instance._device_id = device_id |
|
|
|
instance.delete() |
|
|
|
|
|
|
|
response_status = status.HTTP_204_NO_CONTENT |
|
|
|
try: |
|
|
|
except model.DoesNotExist: # POST |
|
|
|
instance.delete() |
|
|
|
|
|
|
|
response_status = status.HTTP_204_NO_CONTENT |
|
|
|
|
|
|
|
except model.DoesNotExist: # a relationship was not found, not good |
|
|
|
|
|
|
|
response_status = status.HTTP_400_BAD_REQUEST |
|
|
|
|
|
|
|
except model.DoesNotExist: # the data was not found, it's ok |
|
|
|
response_status = status.HTTP_208_ALREADY_REPORTED |
|
|
|
response_status = status.HTTP_208_ALREADY_REPORTED |
|
|
|
# delete = ModelLog.objects.filter(model_id=data_id, operation=model_operation).first() |
|
|
|
print(f'{model_name} DoesNotExist, id: {data_id}') |
|
|
|
# if delete: |
|
|
|
|
|
|
|
# response_status = status.HTTP_208_ALREADY_REPORTED |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# response_status = status.HTTP_404_NOT_FOUND |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
response_status = status.HTTP_400_BAD_REQUEST |
|
|
|
response_status = status.HTTP_400_BAD_REQUEST |
|
|
|
print(f'other exception: {str(e)}, type: {type(e)}, args: {e.args}, traceback: {e.__traceback__}') |
|
|
|
print(f'OTHER exception on {model_operation} {model_name} : {str(e)}, type: {type(e)}, id: {data.get('id')}') |
|
|
|
message = str(e) |
|
|
|
message = str(e) |
|
|
|
|
|
|
|
|
|
|
|
results.append({ |
|
|
|
results.append({ |
|
|
|
|