Пример #1
0
 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
     })
Пример #2
0
 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
     })
Пример #3
0
 def get(self, request, id):
     b_u = ResourceUser.objects.filter(resource=request.user.resources.get(
         id=id)).first()
     resources = NewHireResourceItemSerializer(b_u,
                                               context={'request': request})
     return Response(resources.data)