remove defualt from stake holder model
This commit is contained in:
@@ -45,116 +45,97 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
# get device owner (organization)
|
# get device owner (organization)
|
||||||
organization = self.get_device_organization()
|
organization = self.get_device_organization()
|
||||||
"""
|
"""
|
||||||
try:
|
# convert headers to dictionary
|
||||||
# convert headers to dictionary
|
headers_data = {key: request.headers.get(key) for key in self.HEADERS}
|
||||||
headers_data = {key: request.headers.get(key) for key in self.HEADERS}
|
|
||||||
|
|
||||||
serial = headers_data['device-serial']
|
serial = headers_data['device-serial']
|
||||||
mac = headers_data['device-mac']
|
mac = headers_data['device-mac']
|
||||||
psp_name = headers_data['device-provider']
|
psp_name = headers_data['device-provider']
|
||||||
|
|
||||||
# provider organization
|
# provider organization
|
||||||
organization = pos_models.Organization.objects.get(en_name=psp_name)
|
organization = pos_models.Organization.objects.get(en_name=psp_name)
|
||||||
|
|
||||||
device = self.device_queryset.filter(serial=serial).first()
|
device = self.device_queryset.filter(serial=serial).first()
|
||||||
|
|
||||||
if not device and 'device_identity' in request.data.keys() and request.data['device_identity'] != "":
|
if not device and 'device_identity' in request.data.keys() and request.data['device_identity'] != "":
|
||||||
device = self.device_queryset.filter(device_identity=request.data['device_identity']).first()
|
device = self.device_queryset.filter(device_identity=request.data['device_identity']).first()
|
||||||
|
|
||||||
if device:
|
if device:
|
||||||
if not device.is_activated and device.pre_registered and device.assigned_state:
|
if not device.is_activated and device.pre_registered and device.assigned_state:
|
||||||
# activate device
|
# activate device
|
||||||
device.is_activated = True
|
device.is_activated = True
|
||||||
device.save()
|
device.save()
|
||||||
|
|
||||||
if device.is_activated and device.assigned_state:
|
if device.is_activated and device.assigned_state:
|
||||||
# when device is logged in, its has an organization owner client, if not it will show error
|
# when device is logged in, its has an organization owner client, if not it will show error
|
||||||
device_owner_org = self.get_device_organization()
|
device_owner_org = self.get_device_organization()
|
||||||
|
|
||||||
session = self.session_queryset.filter(serial=serial).first()
|
session = self.session_queryset.filter(serial=serial).first()
|
||||||
if not session:
|
if not session:
|
||||||
pos_models.Sessions.objects.create(
|
pos_models.Sessions.objects.create(
|
||||||
device=device,
|
device=device,
|
||||||
name=headers_data['device-name'],
|
name=headers_data['device-name'],
|
||||||
version=headers_data['device-version'],
|
version=headers_data['device-version'],
|
||||||
mac=headers_data['device-mac'],
|
mac=headers_data['device-mac'],
|
||||||
ip=get_client_ip(request),
|
ip=get_client_ip(request),
|
||||||
sdk=headers_data['device-sdk'],
|
sdk=headers_data['device-sdk'],
|
||||||
serial=headers_data['device-serial'],
|
serial=headers_data['device-serial'],
|
||||||
latitude=headers_data['device-lot'],
|
latitude=headers_data['device-lot'],
|
||||||
longitude=headers_data['device-lng'],
|
longitude=headers_data['device-lng'],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
session.name = headers_data['device-name']
|
session.name = headers_data['device-name']
|
||||||
session.version = headers_data['device-version']
|
session.version = headers_data['device-version']
|
||||||
session.mac = headers_data['device-mac']
|
session.mac = headers_data['device-mac']
|
||||||
session.ip = get_client_ip(request)
|
session.ip = get_client_ip(request)
|
||||||
session.sdk = headers_data['device-sdk']
|
session.sdk = headers_data['device-sdk']
|
||||||
session.latitude = headers_data['device-lot']
|
session.latitude = headers_data['device-lot']
|
||||||
session.longitude = headers_data['device-lng']
|
session.longitude = headers_data['device-lng']
|
||||||
session.save()
|
session.save()
|
||||||
|
|
||||||
org_data = {
|
org_data = {
|
||||||
'id': device_owner_org.id,
|
'id': device_owner_org.id,
|
||||||
'name': device_owner_org.name,
|
'name': device_owner_org.name,
|
||||||
'en_name': device_owner_org.en_name
|
'en_name': device_owner_org.en_name
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response({
|
|
||||||
"message": "خوش آمدید", # noqa
|
|
||||||
"device_identity": device.device_identity,
|
|
||||||
"serial": device.serial,
|
|
||||||
"password": device.password,
|
|
||||||
"provider": organization.name,
|
|
||||||
"provider_tell": organization.phone,
|
|
||||||
"device_owner": org_data,
|
|
||||||
"device_owner_users": get_users_of_organization(device_owner_org)
|
|
||||||
}, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
return Response({
|
return Response({
|
||||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
"message": "خوش آمدید", # noqa
|
||||||
"device_identity": device.device_identity,
|
"device_identity": device.device_identity,
|
||||||
"password": "****",
|
|
||||||
"serial": device.serial,
|
"serial": device.serial,
|
||||||
|
"password": device.password,
|
||||||
"provider": organization.name,
|
"provider": organization.name,
|
||||||
"provider_tell": organization.phone,
|
"provider_tell": organization.phone,
|
||||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
"device_owner": org_data,
|
||||||
|
"device_owner_users": get_users_of_organization(device_owner_org)
|
||||||
|
}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
else:
|
return Response({
|
||||||
pre_device = pos_models.Device.objects.create(
|
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
||||||
serial=serial,
|
"device_identity": device.device_identity,
|
||||||
mac=mac,
|
"password": "****",
|
||||||
organization=organization,
|
"serial": device.serial,
|
||||||
pre_registered=True,
|
"provider": organization.name,
|
||||||
is_activated=False
|
"provider_tell": organization.phone,
|
||||||
)
|
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
return Response({
|
else:
|
||||||
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
pre_device = pos_models.Device.objects.create(
|
||||||
"device_identity": pre_device.device_identity,
|
serial=serial,
|
||||||
"password": "****",
|
mac=mac,
|
||||||
"provider": organization.name,
|
organization=organization,
|
||||||
"provider_tell": organization.phone,
|
pre_registered=True,
|
||||||
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
is_activated=False
|
||||||
except Exception as e:
|
|
||||||
error_message = str(e)
|
|
||||||
error_title = e.__class__.__name__
|
|
||||||
error_traceback = traceback.format_exc()
|
|
||||||
print(error_message)
|
|
||||||
print(error_title)
|
|
||||||
print(error_traceback)
|
|
||||||
print(headers_data)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"result": "خطای سرور داخلی رخ داده است. لطفا بعدا تلاش کنید.", # noqa
|
|
||||||
"error_message": error_message,
|
|
||||||
"error_title": error_title,
|
|
||||||
"error_traceback": error_traceback,
|
|
||||||
},
|
|
||||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return Response({
|
||||||
|
"message": "دستگاه در سیستم ثبت در انتظار فعال سازی توسط پذیرنده می باشد", # noqa
|
||||||
|
"device_identity": pre_device.device_identity,
|
||||||
|
"password": "****",
|
||||||
|
"provider": organization.name,
|
||||||
|
"provider_tell": organization.phone,
|
||||||
|
}, status=status.HTTP_412_PRECONDITION_FAILED)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['post'],
|
methods=['post'],
|
||||||
detail=False,
|
detail=False,
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ class DeviceAssignmentViewSet(viewsets.ModelViewSet, SoftDeleteMixin):
|
|||||||
assignment=assignment,
|
assignment=assignment,
|
||||||
device=assignment.device,
|
device=assignment.device,
|
||||||
organization=assignment.client.organization,
|
organization=assignment.client.organization,
|
||||||
default=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
|||||||
Reference in New Issue
Block a user