def required_object_for_operation(self, request, object, *args, **kwargs): try: operation_result = self.execute_operation(object, kwargs[OPERATION_OR_ATTRIBUTES_KWARGS_LABEL]) contype_type = self.content_type_for_object_type(request, type(operation_result)) serialize_data = self.serialize_object(request, operation_result, contype_type) return RequiredObject(serialize_data, contype_type, 200) except InvalidOperationException as ex: return RequiredObject( json.dumps( {"Invalid Operation": ex.args[0]} ), JSON_CONTENT_TYPE, 400 )
def required_object_for_operation(self, request, object, *args, **kwargs): try: # todo: need to decide content-type (by operation return type and accept) and serialization operation_name, operation_result = self.execute_operation(object, kwargs[OPERATION_OR_ATTRIBUTES_KWARGS_LABEL]) contype_type = self.content_type_for_object_type(request, type(operation_result)) #operation_name = self.get_operation_name_from_path(kwargs[OPERATION_OR_ATTRIBUTES_KWARGS_LABEL]) serialize_data = self.serialize_object(request, operation_result, contype_type, operation_name=operation_name) return RequiredObject(serialize_data, contype_type, 200) except InvalidOperationException as ex: return RequiredObject( json.dumps( {"Invalid Operation": ex.args[0]} ), JSON_CONTENT_TYPE, 400 )
def required_object_for_simple_path(self, request): # django context object is required when the serializer has HyperlinkedrelatedField serializer = self.serializer_class(self.object_model, context={'request': request}) return RequiredObject( serializer.data, self.content_type_or_default_content_type(request), self.object_model, 200)
def base_required_context(self, request, *args, **kwargs): context = {} term_definition_context = self.context_class().create_context_for_fields(self.serializer_class.Meta.model()._meta.fields) supported_operation_context = self.context_class().create_context_for_operations(operations.OPERATIONS_BY_TYPE[FeatureModel]) context.update(term_definition_context) context.update(supported_operation_context) return RequiredObject(context, CONTENT_TYPE_JSONLD, 200)
def basic_get(self, request, *args, **kwargs): empty_object = self.serializer_class.Meta.model() if OPERATION_OR_ATTRIBUTES_KWARGS_LABEL in kwargs: return self.required_object_for_operation(request, empty_object, *args, **kwargs) queryset = self.serializer_class.Meta.model.objects.all() contype_accept = self.feature_utils.content_type_by_accept(request, *args, kwargs) serialize_data = self.serialize_object(request, queryset, contype_accept) return RequiredObject(serialize_data, contype_accept, 200)
def required_object_for_count_resource_operation(self, request, attributes_functions_str): c_type_by_operation = self.define_content_type_by_operation( request, self.get_operation_name_from_path(attributes_functions_str)) data = { self.operation_controller.count_resource_collection_operation_name: len(self.object_model) } return RequiredObject(data, c_type_by_operation, self.object_model, 200)
def required_context_for_operation(self, request, *args, **kwargs): context = {} operation_return_type = self.get_operation_return_type( kwargs["operation"]) try: supported_operation_context = self.context_class( ).create_context_for_operations( operations.OPERATIONS_BY_TYPE[operation_return_type]) except KeyError: supported_operation_context = {"hydra:supportedOperation": []} context.update(supported_operation_context) return RequiredObject(context, CONTENT_TYPE_JSONLD, 200)
def basic_get(self, request, *args, **kwargs): if self.path_has_only_attributes(kwargs): return self.required_object_for_attributes(request, *args, **kwargs) object = self.get_object(**kwargs) # http://192.168.0.11:8000/api/restful-ide/bcim/unidades-federativas/1/envelope/transform/3857/envelope/transform/3674 if OPERATION_OR_ATTRIBUTES_KWARGS_LABEL in kwargs: return self.required_object_for_operation(request, object, *args, **kwargs) contype_accept = self.feature_utils.content_type_by_accept(request, *args, kwargs) serialize_data = self.serialize_object(request, object, contype_accept) return RequiredObject(serialize_data, contype_accept, 200)
def basic_get(self, request, *args, **kwargs): pk_dict = {} pk_dict["pk"] = kwargs["pk"] object = get_object_or_404(self.serializer_class.Meta.model, **pk_dict) # http://192.168.0.11:8000/api/restful-ide/bcim/unidades-federativas/1/envelope/transform/3857/envelope/transform/3674 if "operation" in kwargs: return self.required_object_for_operation(request, object, *args, **kwargs) contype_accept = self.feature_utils.content_type_by_accept( request, *args, kwargs) serialize_data = self.serialize_object(request, object, contype_accept) return RequiredObject(serialize_data, contype_accept, 200)
def required_object_for_simple_path(self, request): return RequiredObject( self.object_model, self.content_type_or_default_content_type(request), self.object_model, 200)
def basic_get(self, request, *args, **kwargs): queryset = self.serializer_class.Meta.model.objects.all() serializer = self.serializer_class(queryset, many=True, context={'request': request}) return RequiredObject(serializer.data, JSON_CONTENT_TYPE, 200)