Beispiel #1
0
 def get(self, request):
     """
     """
     user = request.user
     groups = user.group_set.all()
     providers = []
     records = CoreMaintenanceRecord.objects.none()
     for g in groups:
         for p in g.providers.all():
             if p not in providers:
                 providers.append(p)
     if 'active' in request.GET:
         if request.GET['active'].lower() == "true":
             now_time = timezone.now()
             for p in providers:
                 records |= CoreMaintenanceRecord.active(p)
         else:
             all_records = CoreMaintenanceRecord.objects.all()
             now_time = timezone.now()
             for p in providers:
                 records |= CoreMaintenanceRecord.active(p)
             records = all_records.exclude(id__in=records)
     else:
         records = CoreMaintenanceRecord.objects.filter(
             Q(provider__in=providers) | Q(provider=None))
     return Response(MaintenanceRecordSerializer(records, many=True).data)
 def get(self, request):
     """
     """
     query = request.GET
     user = request.user
     providers = []
     records = CoreMaintenanceRecord.objects.none()
     active_records = query.get('active','false').lower() == "true"
     if user and type(user) != AnonymousUser:
         groups = user.group_set.all()
         for group in groups:
             provider_ids = group.identities.filter(only_current_provider(), provider__active=True).values_list('provider', flat=True)
             providers = Provider.objects.filter(id__in=provider_ids)
             for p in providers:
                 if active_records:
                     records |= CoreMaintenanceRecord.active(p)
                 else:
                     records |= CoreMaintenanceRecord.objects.filter(
                             provider=p)
     if active_records:
         global_records = CoreMaintenanceRecord.active()
     else:
         global_records  = CoreMaintenanceRecord.objects.filter(
                 provider=None)
     records |= global_records
     return Response(MaintenanceRecordSerializer(records, many=True).data)
Beispiel #3
0
 def get(self, request, record_id):
     """
     Get a maintenance record.
     """
     try:
         mach_request = CoreMaintenanceRecord.objects.get(id=record_id)
     except CoreMaintenanceRecord.DoesNotExist:
         return Response('No maintenance record with id %s' % record_id,
                         status=status.HTTP_404_NOT_FOUND)
     return Response(MaintenanceRecordSerializer(mach_request).data)
    def patch(self, request, record_id):
        """
        Update a maintenance record.
        """
        #user = request.user
        data = request.DATA
        try:
            record = CoreMaintenanceRecord.objects.get(id=record_id)
        except CoreMaintenanceRecord.DoesNotExist:
            return Response('No maintenance record with id %s' % record_id,
                            status=status.HTTP_404_NOT_FOUND)

        serializer = MaintenanceRecordSerializer(record, data=data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #5
0
 def get(self, request):
     """
     """
     query = request.GET
     user = request.user
     providers = []
     records = CoreMaintenanceRecord.objects.none()
     active_records = query.get('active', 'false').lower() == "true"
     if user and type(user) != AnonymousUser:
         groups = user.group_set.all()
         for g in groups:
             for p in g.providers.all():
                 if active_records:
                     records |= CoreMaintenanceRecord.active(p)
                 else:
                     records |= CoreMaintenanceRecord.objects.filter(
                         provider=p)
     if active_records:
         global_records = CoreMaintenanceRecord.active()
     else:
         global_records = CoreMaintenanceRecord.objects.filter(
             provider=None)
     records |= global_records
     return Response(MaintenanceRecordSerializer(records, many=True).data)