def tasks(self, request, pk=None): if request.method == 'POST' or request.method == 'PUT': items = get_task_items(self.get_object()) for i in items: if i['item'] == request.data['type']: item = apps.get_model(app_label=i['app'], model_name=i['model']).objects.get( id=request.data['item']['id']) i['s_model'].add(item) if request.method == 'POST' else i[ 's_model'].remove(item) break return Response(request.data['item'], status=status.HTTP_201_CREATED) return Response({ 'preboarding': PreboardingUserSerializer( PreboardingUser.objects.filter(user=self.get_object()), many=True).data, 'to_do': ToDoUserSerializer(ToDoUser.objects.filter(user=self.get_object()), many=True).data, 'resources': NewHireResourceItemSerializer( ResourceUser.objects.filter(user=self.get_object()), many=True).data, 'introductions': IntroductionSerializer(self.get_object().introductions, many=True).data, 'appointments': AppointmentSerializer(self.get_object().appointments, many=True).data, 'conditions': ConditionSerializer(self.get_object().conditions, many=True).data })
def progress(self, request, pk=None): todo_serializer = ToDoUserSerializer( ToDoUser.objects.filter(user=self.get_object()), many=True) resource_serializer = NewHireProgressResourceSerializer( ResourceUser.objects.filter(user=self.get_object()), many=True) data = { 'to_do': todo_serializer.data, 'resources': resource_serializer.data } return Response(data)
def tasks(self, request, pk=None): if request.method == 'POST' or request.method == 'PUT': items = get_task_items(self.get_object()) for i in items: if i['item'] == request.data['type']: item = apps.get_model(app_label=i['app'], model_name=i['model']).objects.get( id=request.data['item']['id']) i['s_model'].add(item) if request.method == 'POST' else i[ 's_model'].remove(item) break return Response(request.data['item'], status=status.HTTP_201_CREATED) user = self.get_object() return Response({ 'preboarding': PreboardingUserSerializer(PreboardingUser.objects.filter( user=user).select_related('preboarding').prefetch_related( 'preboarding__content__files'), many=True).data, 'to_do': ToDoUserSerializer( ToDoUser.objects.filter(user=user).select_related( 'to_do').prefetch_related('to_do__content__files'), many=True).data, 'resources': NewHireResourceItemSerializer(ResourceUser.objects.filter( user=user).select_related('resource').prefetch_related( 'resource__chapters__content__files'), many=True).data, 'introductions': IntroductionSerializer( user.introductions.select_related('intro_person'), many=True).data, 'appointments': AppointmentSerializer(user.appointments, many=True).data, 'conditions': ConditionSerializer(user.conditions.prefetch_related( 'to_do', 'resources', 'badges', 'admin_tasks', 'external_messages', 'introductions', 'condition_to_do'), many=True).data })
def get(self, request, id): to_do_items = ToDoUserSerializer( ToDoUser.objects.get(user=request.user, id=id)) return Response(to_do_items.data)
def get(self, request): to_do_items = ToDoUserSerializer( ToDoUser.objects.filter(user=request.user), many=True) return Response(to_do_items.data)