You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB
Python

from osinacore.models import *
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from django.contrib.auth.models import User
from .serializers import *
class UserProfilesAPIView(APIView):
def get(self, request):
data = []
users = User.objects.all()
for user in users:
user_data = {
"user": UserSerializer(user).data,
"customer_profile": None,
"staff_profile": None
}
# Check for customer profile
customer = CustomerProfile.objects.filter(user=user).first()
if customer:
user_data["customer_profile"] = CustomerProfileSerializer(customer).data
# Check for staff profile
staff = StaffProfile.objects.filter(user=user).first()
if staff:
user_data["staff_profile"] = StaffProfileSerializer(staff).data
data.append(user_data)
return Response(data, status=status.HTTP_200_OK)
def get_all_business_related_data():
business_types = BusinessType.objects.all()
departments = Department.objects.all()
job_positions = JobPosition.objects.all()
business_types_data = BusinessTypeSerializer(business_types, many=True).data
departments_data = DepartmentSerializer(departments, many=True).data
job_positions_data = JobPositionSerializer(job_positions, many=True).data
return {
'business_types': business_types_data,
'departments': departments_data,
'job_positions': job_positions_data,
}
class BusinessDataAPIView(APIView):
def get(self, request):
data = get_all_business_related_data()
return Response(data)