當前位置: 首頁>>代碼示例>>Python>>正文


Python coreapi.Field方法代碼示例

本文整理匯總了Python中coreapi.Field方法的典型用法代碼示例。如果您正苦於以下問題:Python coreapi.Field方法的具體用法?Python coreapi.Field怎麽用?Python coreapi.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coreapi的用法示例。


在下文中一共展示了coreapi.Field方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_schema_fields

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_schema_fields(self, view):
        fields = self.get_default_schema_fields()

        for field_name in self.search_index_class.fields:
            field = self.search_index_class.fields[field_name]

            if field.faceted:
                fields.append(
                    coreapi.Field(
                        name=field_name,
                        location='query',
                        required=False,
                        schema=coreschema.String(description=field_name),
                    ))

        return fields 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:18,代碼來源:filters.py

示例2: get_manual_fields

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_manual_fields(self, path, method):
        f, url, params, returns = self._method_meta[method]
        if params is None:
            return []
        field_schemas = T(params).__schema__.items
        path_fields = self.get_path_fields(path, method)
        path_field_names = set(x.name for x in path_fields)
        fields = []
        for name, item in field_schemas.items():
            if name in path_field_names or name in ['id', 'pk']:
                continue
            required = not item.params.get('optional', False)
            default = item.params.get('default')
            if not (default is None or default == ''):
                required = False
            if method in ['GET', 'DELETE']:
                location = 'query'
            else:
                location = 'form'
            field = coreapi.Field(
                name=name,
                required=required,
                location=location,
                schema=coreschema_from_validr(item)
            )
            fields.append(field)
        return fields 
開發者ID:anyant,項目名稱:rssant,代碼行數:29,代碼來源:__init__.py

示例3: schema

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def schema(self):
        fields = [
            coreapi.Field(
                "auth_token",
                required=True,
                location="form",
                schema=coreschema.String(max_length=40),
            )]
        return schemas.ManualSchema(fields=fields) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:11,代碼來源:v1.py

示例4: schema

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def schema(self):
        if self.request.method == 'GET':
            fields = [
                coreapi.Field(
                    "name",
                    required=False,
                    location="query",
                    schema=coreschema.String(max_length=30)
                ),
                coreapi.Field(
                    "name_contains",
                    required=False,
                    location="query",
                    schema=coreschema.String(max_length=30)
                )]
        elif self.request.method == 'POST':
            fields = [
                coreapi.Field(
                    "params",
                    required=True,
                    location="body",
                    schema=coreschema.Object()
                )]
        else:
            fields = [
                coreapi.Field(
                    "name",
                    required=True,
                    location="body",
                    schema=coreschema.String(max_length=30)
                )]
        return schemas.ManualSchema(fields=fields) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:34,代碼來源:v1.py

示例5: get_default_schema_fields

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_default_schema_fields(self):
        return [
            # Search query field is required
            coreapi.Field(
                name='text',
                location='query',
                required=True,
                schema=coreschema.String(description='Search query on text content (Lucence syntax support).'),
            )
        ] 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:12,代碼來源:api_views.py

示例6: get_default_schema_fields

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_default_schema_fields(self):
        return [
            # Search query field is required
            coreapi.Field(
                name='text',
                location='query',
                required=True,
                schema=coreschema.String(description='Search query on text content (Lucence syntax support).'),
                description='',
                example=[_('search_example_query1'),  _('search_example_query2'), _('search_example_query3')]
            )
        ] 
開發者ID:openlegaldata,項目名稱:oldp,代碼行數:14,代碼來源:api_views.py

示例7: get_path_fields

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_path_fields(self, path, method, view):
        """
        Return a list of `coreapi.Field` instances corresponding to any
        templated path variables.
        """
        model = getattr(getattr(view, 'queryset', None), 'model', None)
        fields = []

        for variable in uritemplate.variables(path):

            if variable == 'version':
                continue

            title = ''
            description = ''
            schema_cls = coreschema.String
            kwargs = {}
            if model is not None:
                # Attempt to infer a field description if possible.
                try:
                    model_field = model._meta.get_field(variable)
                except:
                    model_field = None

                if model_field is not None and model_field.verbose_name:
                    title = force_text(model_field.verbose_name)

                if model_field is not None and model_field.help_text:
                    description = force_text(model_field.help_text)
                elif model_field is not None and model_field.primary_key:
                    description = get_pk_description(model, model_field)

                if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable:
                    kwargs['pattern'] = view.lookup_value_regex
                elif isinstance(model_field, models.AutoField):
                    schema_cls = coreschema.Integer

            field = Field(
                name=variable,
                location='path',
                required=True,
                schema=schema_cls(title=title, description=description, **kwargs)
            )
            fields.append(field)

        return fields 
開發者ID:limdauto,項目名稱:drf_openapi,代碼行數:48,代碼來源:entities.py

示例8: get_serializer_fields

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_serializer_fields(self, path, method, view, version=None, method_func=None):
        """
        Return a list of `coreapi.Field` instances corresponding to any
        request body input, as determined by the serializer class.
        """
        if method in ('PUT', 'PATCH', 'POST'):
            location = 'form'
        else:
            location = 'query'

        serializer_class = self.get_serializer_class(view, method_func)
        if not serializer_class:
            return []

        serializer = serializer_class()
        if isinstance(serializer, serializers.ListSerializer):
            return [
                Field(
                    name='data',
                    location=location,
                    required=True,
                    schema=coreschema.Array()
                )
            ]

        if not isinstance(serializer, serializers.Serializer):
            return []

        fields = []
        for field in serializer.fields.values():
            if field.read_only or isinstance(field, serializers.HiddenField):
                continue

            required = field.required and method != 'PATCH'
            # if the attribute ('help_text') of this field is a lazy translation object, force it to generate a string
            description = str(field.help_text) if isinstance(field.help_text, Promise) else field.help_text
            fallback_schema = self.fallback_schema_from_field(field)
            field = Field(
                name=field.field_name,
                location=location,
                required=required,
                schema=fallback_schema if fallback_schema else field_to_schema(field),
                description=description,
            )
            fields.append(field)

        return fields 
開發者ID:limdauto,項目名稱:drf_openapi,代碼行數:49,代碼來源:entities.py

示例9: get_response_object

# 需要導入模塊: import coreapi [as 別名]
# 或者: from coreapi import Field [as 別名]
def get_response_object(self, response_serializer_class, description):

        fields = []
        serializer = response_serializer_class()
        nested_obj = {}

        for field in serializer.fields.values():
            # If field is a serializer, attempt to get its schema.
            if isinstance(field, serializers.Serializer):
                subfield_schema = self.get_response_object(field.__class__, None)[0].get('schema')

                # If the schema exists, use it as the nested_obj
                if subfield_schema is not None:
                    nested_obj[field.field_name] = subfield_schema
                    nested_obj[field.field_name]['description'] = field.help_text
                    continue

            # Otherwise, carry-on and use the field's schema.
            fallback_schema = self.fallback_schema_from_field(field)
            fields.append(Field(
                name=field.field_name,
                location='form',
                required=field.required,
                schema=fallback_schema if fallback_schema else field_to_schema(field),
            ))

        res = _get_parameters(Link(fields=fields), None)

        if not res:
            if nested_obj:
                return {
                    'description': description,
                    'schema': {
                        'type': 'object',
                        'properties': nested_obj
                    }
                }, {}
            else:
                return {}, {}

        schema = res[0]['schema']
        schema['properties'].update(nested_obj)
        response_schema = {
            'description': description,
            'schema': schema
        }

        error_status_codes = {}

        response_meta = getattr(response_serializer_class, 'Meta', None)

        for status_code, description in getattr(response_meta, 'error_status_codes', {}).items():
            error_status_codes[status_code] = {'description': description}

        return response_schema, error_status_codes 
開發者ID:limdauto,項目名稱:drf_openapi,代碼行數:57,代碼來源:entities.py


注:本文中的coreapi.Field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。