How to use the pydash._.is_list function in pydash

To help you get started, we’ve selected a few pydash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
def serialize(self, dest, current, attribute, opts):
        data = None

        if opts and opts.get('ref'):
            if not dest.get('relationships'):
                dest['relationships'] = {}

            def map_current(item):
                return self.serialize_ref(item, current, attribute, opts)

            if _.is_list(current.get(attribute)):
                data = map(map_current, current[attribute])

            else:
                data = self.serialize_ref(current[attribute], current,
                                         attribute, opts)

            dest['relationships'][self.key_for_attribute(attribute)] = {}
            if not opts.get('ignore_relationship_data'):
                dest['relationships'][self.key_for_attribute(attribute)]['data'] = data

            if opts.get('relationship_links'):
                dest['relationships'][self.key_for_attribute(attribute)]['links'] = \
                    self.get_links(current[attribute], opts['relationship_links'], dest)

            if opts.get('relationship_meta'):
                dest['relationships'][self.key_for_attribute(attribute)]['meta'] = \
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
data = self.serialize_ref(current[attribute], current,
                                         attribute, opts)

            dest['relationships'][self.key_for_attribute(attribute)] = {}
            if not opts.get('ignore_relationship_data'):
                dest['relationships'][self.key_for_attribute(attribute)]['data'] = data

            if opts.get('relationship_links'):
                dest['relationships'][self.key_for_attribute(attribute)]['links'] = \
                    self.get_links(current[attribute], opts['relationship_links'], dest)

            if opts.get('relationship_meta'):
                dest['relationships'][self.key_for_attribute(attribute)]['meta'] = \
                    self.get_meta(current['attribute'], opts['relationship_meta'])
        else:
            if _.is_list(current[attribute]):
                if len(current[attribute]) and _.is_dict(current[attribute][0]):
                    def map_current(item):
                        return self.serialize_nested(item, current, attribute,
                                                    opts)
                    data = map(map_current, current[attribute])
                else:
                    data = current[attribute]

                dest['attributes'][self.key_for_attribute(attribute)] = data
            elif _.is_dict(current[attribute]):
                data = self.serialize_nested(current[attribute], current,
                                            attribute, opts)
                dest['attributes'][self.key_for_attribute(attribute)] = data
            else:
                dest['attributes'][self.key_for_attribute(attribute)] = current[attribute]
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
def _is_complex_type(self, obj):
        return _.is_list(obj) or _.is_dict(obj)
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
acc[self.key_for_attribute(key)] = self.key_for_attribute(value)
            else:
                acc[self.key_for_attribute(key)] = value
            return acc, value, key

        def map_function(item):
            if self._is_complex_type(item):
                return self.key_for_attribute(item)
            else:
                return item

        if _.is_dict(attribute):
            return _.transform(attribute, transform_callback)


        elif _.is_list(attribute):
            map(map_function, attribute)

        else:
            if _.is_function(self.opts.get('key_for_attribute')):
                return self.opts['key_for_attribute'](attribute)
            else:
                caserized = inflector.caserize(attribute, self.opts)
                return caserized

pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.

MIT
Latest version published 1 month ago

Package Health Score

90 / 100
Full package analysis

Similar packages