示例#1
0
    def _preprocess_mapping(self, mapping):
        """
            Preprocess the mapping :
            after the preprocces, everything is
            callable in the val of the dictionary

            use to allow syntaxical sugar like 'field': 'external_field'
            instead of 'field' : value('external_field')
        """
        #m = dict(mapping)
        m = mapping
        for key, value in m.items():
            if isinstance(value, basestring):
                m[key] = mapper.value(value)
            #set parent for instance of dbmapper
            elif isinstance(value, mapper.dbmapper):
                value.set_parent(self)
            elif isinstance(value, create_childs):
                # {'child_ids':[{'id':id1, 'name':name1}, {'id':id2, 'name':name2}]}
                # ->
                # {'child_ids/id':[id1, id2], 'child_ids/name': [name1, name2]}
                for c in value.get_childs():
                    self._preprocess_mapping(c)
                    for ckey, cvalue in c.items():
                        new_key = '%s/%s' % (key, ckey)
                        if new_key not in m:
                            m[new_key] = []
                        m[new_key].append(cvalue)
                del m[key] # delete 'child_ids'
        return m
示例#2
0
    def _preprocess_mapping(self, mapping):
        """
            Preprocess the mapping :
            after the preprocces, everything is
            callable in the val of the dictionary

            use to allow syntaxical sugar like 'field': 'external_field'
            instead of 'field' : value('external_field')
        """
        #m = dict(mapping)
        m = mapping
        for key, value in m.items():
            if isinstance(value, basestring):
                m[key] = mapper.value(value)
            #set parent for instance of dbmapper
            elif isinstance(value, mapper.dbmapper):
                value.set_parent(self)
            elif isinstance(value, create_childs):
                # {'child_ids':[{'id':id1, 'name':name1}, {'id':id2, 'name':name2}]}
                # ->
                # {'child_ids/id':[id1, id2], 'child_ids/name': [name1, name2]}
                for c in value.get_childs():
                    self._preprocess_mapping(c)
                    for ckey, cvalue in c.items():
                        new_key = '%s/%s' % (key, ckey)
                        if new_key not in m:
                            m[new_key] = []
                        m[new_key].append(cvalue)
                del m[key]  # delete 'child_ids'
        return m
    def _preprocess_mapping(self, mapping):
        """
            Preprocess the mapping :
            after the preprocces, everything is
            callable in the val of the dictionary

            use to allow syntaxical sugar like 'field': 'external_field'
            instead of 'field' : value('external_field')
        """
        map = dict(mapping)
        for key, value in map.items():
            if isinstance(value, basestring):
                map[key] = mapper.value(value)
            #set parent for instance of dbmapper
            elif isinstance(value, mapper.dbmapper):
                value.set_parent(self)
        return map
    def _preprocess_mapping(self, mapping):
        """
            Preprocess the mapping :
            after the preprocces, everything is
            callable in the val of the dictionary

            use to allow syntaxical sugar like 'field': 'external_field'
            instead of 'field' : value('external_field')
        """
        map = dict(mapping)
        for key, value in map.items():
            if isinstance(value, basestring):
                map[key] = mapper.value(value)
            #set parent for instance of dbmapper
            elif isinstance(value, mapper.dbmapper):
                value.set_parent(self)
        return map