Supercedes drf's serializers.ModelSerializer's fields property
        :return: a set of permission-scrubbed fields
431214
def fields(self):
        
        ret = super(FieldPermissionSerializerMixin, self).fields
        request = self._context["request"]

        forbidden_field_names = [
            field_name for field_name, field in ret.items() if hasattr(field, 'check_permission') and (not field.check_permission(request))
        ]

        for field_name in forbidden_field_names:
            ret.pop(field_name)

        return ret
88492
def _delete_fields(self):
        
        for key in self._json_dict.keys():
            if not key.startswith("_"):
                delattr(self, key)
        self._json_dict = {}
        self.id = None
        self.name = None
1143316
def get_model_fields(self):
        

        model_fields = getattr(self.Meta, 'fields', None)

        if model_fields is not None:
            model_fields = set(model_fields)

        return model_fields
331463
def get_fields(self):
        """"""
        fields = super(DataSerializer, self).get_fields()

        # Hide collections/entities fields on list views as fetching them may be expensive.
        if self.parent is not None:
            del fields['collections']
            del fields['entities']

        return fields
476247
def get_rendered_fields(self, ctx=None):
        '''
        
        '''
        if ctx is None:
            ctx = RenderContext()
        ctx.push(self)
        current = self._fields[self._field_idx]
        res = current.get_rendered_fields(ctx)
        ctx.pop()
        return res
167951
def needs_serialization(self):
        
        return any(field.is_set_on(self) for field in six.itervalues(self.fields))
802746
def restore_descriptor(self, converted_descriptor):
        

        # Convert
        fields = []
        for field in converted_descriptor['fields']:
            field_type = self.restore_type(field['type'])
            resfield = {
                'name': field['name'],
                'type': field_type,
            }
            if field.get('mode', 'NULLABLE') != 'NULLABLE':
                resfield['constraints'] = {'required': True}
            fields.append(resfield)
        descriptor = {'fields': fields}

        return descriptor
1254987
def end_serialization(self):
        
        if (self.root):
            self.indent(0)
            self.xml.endElement("django-objects")
            self.xml.endDocument()
356360
def get_fields(schema, exclude_dump_only=False):
    
    if hasattr(schema, "fields"):
        fields = schema.fields
    elif hasattr(schema, "_declared_fields"):
        fields = copy.deepcopy(schema._declared_fields)
    else:
        raise ValueError(
            "{!r} doesn't have either `fields` or `_declared_fields`.".format(schema)
        )
    Meta = getattr(schema, "Meta", None)
    warn_if_fields_defined_in_meta(fields, Meta)
    return filter_excluded_fields(fields, Meta, exclude_dump_only)
440510
def get_fieldsets(self, request, obj=None):
        
        fieldsets = super(BaseDynamicInlineAdmin, self).get_fieldsets(
                                                            request, obj)
        if issubclass(self.model, Orderable):
            for fieldset in fieldsets:
                fields = [f for f in list(fieldset[1]["fields"])
                          if not hasattr(f, "translated_field")]
                try:
                    fields.remove("_order")
                except ValueError:
                    pass
                fieldset[1]["fields"] = fields
            fieldsets[-1][1]["fields"].append("_order")
        return fieldsets
685685
def get_fieldsets(self):
        

        if self.fieldsets:
            return self.fieldsets
        form_class = self.get_form_class()
        form = self.get_form(form_class)
        fields = form.base_fields.keys()

        readonly_fields = self.get_readonly_fields()
        if readonly_fields:
            fields.extend(readonly_fields)

        return [(None, {'fields': fields})]
753599
def extract_fields(self):
        

        # get the proper data manager for the object
        dm = IDataManager(self.context)

        # filter out ignored fields
        fieldnames = filter(lambda name: name not in self.ignore, self.keys)

        # schema mapping
        out = dict()

        for fieldname in fieldnames:
            try:
                # get the field value with the data manager
                fieldvalue = dm.json_data(fieldname)
            # https://github.com/collective/plone.jsonapi.routes/issues/52
            # -> skip restricted fields
            except Unauthorized:
                logger.debug("Skipping restricted field '%s'" % fieldname)
                continue
            except ValueError:
                logger.debug("Skipping invalid field '%s'" % fieldname)
                continue

            out[fieldname] = api.to_json_value(self.context, fieldname, fieldvalue)

        return out
1263494
def inherits_modelpermissions_serializer(cls):
    
    def is_modelperms():
        return 'ModelPermissionsSerializer' in [
            ser.__name__ for ser in cls.__bases__
        ]
    is_serializer = type(cls).__name__ == 'SerializerMetaclass'

    return inspect.isclass(cls) and is_serializer and is_modelperms()
830034
def _get_user_allowed_fields(self):
        
        model_name = self.Meta.model.__name__.lower()
        app_label = self.Meta.model._meta.app_label
        full_model_name = '%s.%s' % (app_label, model_name)
        permissions = self.cached_allowed_fields.get(full_model_name)

        if not permissions:
            permissions = FieldPermission.objects.filter(
                user_field_permissions__user=self.user,
                content_type__model=model_name,
                content_type__app_label=app_label
            )
            self.cached_allowed_fields[full_model_name] = permissions
        return permissions
958120
def get_readonly_fields(self, request, obj=None):
        """"""
        return list(self.readonly_fields) + [field.name for field in obj._meta.fields]
92934
def get_fields(self):
        
        field_mapping = OrderedDict()
        for field, data in self.instance.items():
            field_mapping.update(
                {field: self.facet_dict_field_class(
                    child=self.facet_list_field_class(child=self.facet_field_serializer_class(data)), required=False)}
            )

        if self.serialize_objects is True:
            field_mapping["objects"] = serializers.SerializerMethodField()

        return field_mapping
1122670
def get_fields(self):
        
        fields = super(BaseHookSerializer, self).get_fields()
        fields['event_types'] = serializers.MultipleChoiceField(
            choices=loggers.get_valid_events(), required=False)
        fields['event_groups'] = serializers.MultipleChoiceField(
            choices=loggers.get_event_groups_keys(), required=False)
        return fields