Beispiel #1
0
    def put(self, request, table_name):
        try:
            if table_name not in settings.QUERY_TABLES:
                return_result = [
                    {
                        "result": "error",
                        "message": "Invalid code list table",
                    }
                ]
                return HttpResponse(json.dumps(return_result), content_type='application/json', status=status.HTTP_400_BAD_REQUEST)
            data = request.data['data']
            params = tuple(data)

            table_query_builder = TableQueryBuilder(table_name, "repo")
            delete_query = table_query_builder.delete()
            insert_query = table_query_builder.insert(params)

            return_result = update_table_from_tuple([delete_query, insert_query])
            return_status_code = status.HTTP_500_INTERNAL_SERVER_ERROR if return_result[
                0]['result'] == 'error' else status.HTTP_200_OK

            return HttpResponse(json.dumps(return_result), content_type='application/json', status=return_status_code)
        except Exception as e:
            handle_uncaught_error(e)
            raise CustomAPIException({'detail': str(e)})
Beispiel #2
0
 def create(self, validated_data):
     try:
         read_only_fields = ('user', 'theme_name', 'tags',
                             'operationstep_set', 'review_set')
         read_only_dict = dict()
         for field in read_only_fields:
             if field in validated_data:
                 read_only_dict[field] = validated_data.pop(field)
         operation = Operation.objects.create(**validated_data)
         operation.user = read_only_dict['user']
         if operation.advanced_config and len(
                 operation.advanced_config) > 0:
             operation.operation_query = query.get_advanced_config_query(
                 operation.advanced_config)
         else:
             for step in read_only_dict['operationstep_set']:
                 OperationStep.objects.create(operation=operation, **step)
             operation.operation_query = query.build_query(
                 operation=operation)
         operation.count_rows = True
         if not 'is_draft' in validated_data:
             operation.is_draft = False
         operation.save()
         self.create_operation_data_aliases(operation)
         return operation
     except AliasCreationError:
         raise AliasCreationError(
             {'error_code': operation.alias_creation_status})
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #3
0
 def get(self, request, pk, format=None):
     try:
         saved_query_data = self.get_object(pk)
         serializer = SavedQueryDataSerializer(saved_query_data)
         return Response(serializer.data)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #4
0
 def get(self, request, format=None):
     try:
         frozen_data = FrozenData.objects.all()
         serializer = FrozenDataSerializer(frozen_data, many=True)
         return Response(serializer.data)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #5
0
 def get(self, request):
     try:
         content = {"update_scripts": list_update_scripts()}
         post_status = status.HTTP_200_OK
         return Response(content, status=post_status)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #6
0
 def get(self, request, pk):
     try:
         operation = self.get_queryset(pk)
         estimate = query.querytime_estimate(operation=operation)
         return Response(estimate)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #7
0
    def update(self, instance, validated_data):
        try:
            info = model_meta.get_field_info(instance)

            advanced_config = validated_data.get('advanced_config', None)
            if advanced_config and len(advanced_config) > 0:
                instance.name = validated_data.get('name')
                instance.description = validated_data.get('description')
                instance.is_draft = validated_data.get('is_draft')
                instance.advanced_config = advanced_config
                instance.operation_query = query.get_advanced_config_query(
                    advanced_config)
                instance.save()
            else:
                updated_steps = validated_data.pop('operationstep_set')
                for attr, value in validated_data.items():
                    if attr in info.relations and info.relations[attr].to_many:
                        field = getattr(instance, attr)
                        field.set(value)
                    else:
                        setattr(instance, attr, value)
                instance.save()
                existing_steps = instance.operationstep_set.all()
                existing_step_ids = [step.step_id for step in existing_steps]
                for updated_step in updated_steps:
                    updated_step_id = updated_step.get("step_id")
                    if updated_step_id in existing_step_ids:
                        existing_step_ids.remove(updated_step_id)
                    updated_step_instance, _ = OperationStep.objects.get_or_create(
                        operation=instance, step_id=updated_step_id)
                    step_info = model_meta.get_field_info(
                        updated_step_instance)
                    for attr, value in updated_step.items():
                        if attr in step_info.relations and step_info.relations[
                                attr].to_many:
                            field = getattr(updated_step_instance, attr)
                            field.set(value)
                        else:
                            setattr(updated_step_instance, attr, value)
                    updated_step_instance.save()

                for step_for_delete_id in existing_step_ids:
                    step_for_delete = OperationStep.objects.get(
                        operation=instance, step_id=step_for_delete_id)
                    step_for_delete.delete()

                instance.operation_query = query.build_query(
                    operation=instance)
            instance.count_rows = True
            instance.save()
            self.update_operation_data_aliases(instance)
            return instance
        except AliasUpdateError:
            raise AliasUpdateError(
                {'error_code': instance.alias_creation_status})
        except Exception as e:
            handle_uncaught_error(e)
            raise CustomAPIException({'detail': str(e)})
Beispiel #8
0
 def get(self, request, pk, format=None):
     try:
         scheduled_event_run_instance = self.get_object(pk)
         serializer = ScheduledEventRunInstanceSerializer(
             scheduled_event_run_instance)
         return Response(serializer.data)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #9
0
 def post(self, request, format=None):
     try:
         serializer = ScheduledEventSerializer(data=request.data)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data, status=status.HTTP_201_CREATED)
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #10
0
    def get(self, request, format=None):
        try:
            scheduled_events = ScheduledEvent.objects.all().order_by('-start_date')
            if request.query_params.get('limit', None) is not None or request.query_params.get('offset', None) is not None:
                pagination_class = api_settings.DEFAULT_PAGINATION_CLASS
                paginator = pagination_class()
                page = paginator.paginate_queryset(scheduled_events, request)
                serializer = ScheduledEventSerializer(page, many=True)

                return paginator.get_paginated_response(serializer.data)
            serializer = ScheduledEventSerializer(scheduled_events, many=True)
            return Response(serializer.data)
        except Exception as e:
            handle_uncaught_error(e)
            raise CustomAPIException({'detail': str(e)})
Beispiel #11
0
 def get(self, request, pk):
     try:
         operation = self.get_object(pk)
         serializer = DataSerializer({
             "request": request,
             "operation_instance": operation
         })
         paginator = DataPaginator()
         paginator.set_count(serializer.data['count'])
         page_data = paginator.paginate_queryset(
             serializer.data['data'], request)
         return paginator.get_paginated_response(page_data)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #12
0
 def get(self, request, pk, format=None):
     try:
         datasets = self.get_queryset(pk, request)
         limit = self.request.query_params.get('limit', None)
         offset = self.request.query_params.get('offset', None)
         if limit is not None or offset is not None:
             pagination_class = api_settings.DEFAULT_PAGINATION_CLASS
             paginator = pagination_class()
             page = paginator.paginate_queryset(datasets, request)
             serializer = OperationSerializer(page, many=True)
             return paginator.get_paginated_response(serializer.data)
         else:
             serializer = OperationSerializer(datasets, many=True)
             return Response(serializer.data)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})
Beispiel #13
0
    def get(self, request, pk, format=None):
        try:
            scheduled_event_run_instance = self.get_object(pk, request)
            if self.request.query_params.get('limit', None) is not None or self.request.query_params.get('offset', None) is not None:
                pagination_class = api_settings.DEFAULT_PAGINATION_CLASS
                paginator = pagination_class()
                page = paginator.paginate_queryset(
                    scheduled_event_run_instance, request)
                serializer = ScheduledEventRunInstanceSerializer(
                    page, many=True)

                return paginator.get_paginated_response(serializer.data)
            else:
                serializer = ScheduledEventRunInstanceSerializer(
                    scheduled_event_run_instance, many=True)
                return Response(serializer.data)
        except Exception as e:
            handle_uncaught_error(e)
            raise CustomAPIException({'detail': str(e)})
Beispiel #14
0
 def post(self, request):
     """
     Expects old_password, new_password1, new_password2
     """
     try:
         form = PasswordChangeForm(request.user, request.data)
         if form.is_valid():
             user = form.save()
             update_session_auth_hash(request, user)
             content = {"messages": [
                 "Password successfully changed for user {}.".format(user.username)]}
             post_status = status.HTTP_202_ACCEPTED
         else:
             content = {"validation": form.errors.as_data()}
             post_status = status.HTTP_400_BAD_REQUEST
         return Response(content, status=post_status)
     except Exception as e:
         handle_uncaught_error(e)
         raise CustomAPIException({'detail': str(e)})