Пример #1
0
    def post(self, request, slug_project, database_object_project, use_sandbox, format=None):
        serializer = Serializer_Settings_Batch(data=request.data)

        if serializer.is_valid():
            serializer.save(database_object_project=database_object_project)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
 def put(self, request, slug_project, database_object_project, use_sandbox, id_settings_batch, format=None):
     item = Manager_Settings_Batch.get(id_settings_batch)
     serializer = Serializer_Settings_Batch(item, data=request.data, partial=True)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #3
0
    def get(self,
            request,
            slug_project,
            database_object_project,
            use_sandbox,
            format=None):

        queryset, list_fields = Manager_Settings_Batch.get_all(
            database_object_project=database_object_project,
            request=request,
        )

        queryset_paginated, count_items = paginate_queryset(queryset, request)

        serializer = Serializer_Settings_Batch(queryset_paginated,
                                               many=True,
                                               context={
                                                   'usecase':
                                                   'list_settings_batch',
                                                   'fields': list_fields,
                                               })

        return Response({
            'items_total': count_items,
            'data': serializer.data,
        })
Пример #4
0
    def __init__(self, *args, **kwargs):
        super(Serializer_Batch, self).__init__(*args, **kwargs)

        context = kwargs.get('context', {})

        self.fields['settings_batch'] = Serializer_Settings_Batch(
            context=context)
Пример #5
0
def settings_batch_all(request,
                       slug_project,
                       database_object_project,
                       use_sandbox,
                       format=None):
    queryset, list_fields = Manager_Settings_Batch.get_all(
        database_object_project=database_object_project,
        request=request,
    )

    serializer = Serializer_Settings_Batch(queryset,
                                           many=True,
                                           context={
                                               'usecase': 'settings_batch_all',
                                               'fields': list_fields,
                                           })

    return Response(serializer.data)
Пример #6
0
def settings_batch_all(request, slug_project, database_object_project, use_sandbox, format=None):
    list_fields = request.query_params.getlist('fields[]')
    if len(list_fields) == 0:
        list_fields = None

    queryset = Manager_Settings_Batch.get_all(
        database_object_project=database_object_project,
        request=request,
        fields=list_fields,
    )

    serializer = Serializer_Settings_Batch(
        queryset,
        many=True,
        context={
            'usecase': 'settings_batch_all',
            'fields': list_fields,
        }
    )

    return Response(serializer.data)
Пример #7
0
 def get(self, request, slug_project, id_settings_batch):
     item = Manager_Settings_Batch.get(id_settings_batch)
     serializer = Serializer_Settings_Batch(item, context={'request': request})
     return Response(serializer.data)
Пример #8
0
class Serializer_Batch(serializers.ModelSerializer):
    def __init__(self, *args, **kwargs):
        super(Serializer_Batch, self).__init__(*args, **kwargs)

        context = kwargs.get('context', {})

        self.fields['settings_batch'] = Serializer_Settings_Batch(
            context=context)

        keep_fields(self, context.get('fields'))

    settings_batch = Serializer_Settings_Batch()

    data_csv = serializers.ListField(required=False)
    # hits = Serializer_HIT(many=True, read_only=True)
    count_hits = serializers.IntegerField(required=False)

    count_assignments_total = serializers.IntegerField(required=False)
    count_assignments_approved = serializers.IntegerField(required=False)
    count_assignments_rejected = serializers.IntegerField(required=False)
    count_assignments_submitted = serializers.IntegerField(required=False)
    count_assignments_dead = serializers.IntegerField(required=False)
    count_assignments_pending = serializers.IntegerField(required=False)

    count_assignments_available = serializers.IntegerField(required=False)

    costs_max = serializers.IntegerField(required=False)
    costs_so_far = serializers.IntegerField(required=False)

    class Meta:
        model = Batch
        fields = (
            'id',
            'name',
            'count_hits',
            'datetime_creation',
            'project',
            'use_sandbox',
            # 'hits',
            'data_csv',
            'settings_batch',
            'count_assignments_total',
            'count_assignments_approved',
            'count_assignments_rejected',
            'count_assignments_submitted',
            'count_assignments_dead',
            'count_assignments_pending',
            'count_assignments_available',
            'costs_max',
            'costs_so_far',
        )
        extra_kwargs = {
            # 'template': {
            #     'source': 'template_worker',
            # },
            'name': {
                'required': False
            },
            'use_sandbox': {
                'required': False
            },
        }

    def create(self, validated_data):
        print('validated_data')
        print(validated_data)
        print('validated_data')

        batch = Manager_Batches.create(
            database_object_project=validated_data.get(
                'database_object_project'),
            use_sandbox=validated_data.get('use_sandbox'),
            data=validated_data)

        batch = Batch.objects.get_or_create(name='gmudupzvxtjtpmcepnre',
                                            use_sandbox=True)[0]
        foo = Settings_Batch.objects.get_or_create(name='gmudupzvxtjtpmcepnre',
                                                   defaults={
                                                       'batch':
                                                       batch,
                                                       'project':
                                                       Project.objects.first()
                                                   })

        return batch
        # return batch
        # return {'data_csv': []}

    def update(self, instance, validated_data):
        print('validated_data')
        print(validated_data)
        print('validated_data')

        return dictionary_qualification