Esempio n. 1
0
    def create_mapping(self):
        mapping = {}
        aliases = self._meta.field_aliases
        for model in self.get_related_models():
            for field, mode in self._get_fields_with_modes(model):
                map_base = self._get_map_base(field, mode)

                if isinstance(field, RelatedField) and not field.null:
                    map_base["priority"] -= 10

                # Figure out names
                names = [field.name]
                if field.verbose_name:
                    names.append(field.verbose_name)

                # find aliases
                this_aliases = aliases.get(field.name)
                if this_aliases:
                    if isinstance(this_aliases, six.string_types):
                        this_aliases = [this_aliases]
                    names.extend(this_aliases)

                # Assign into mapping
                for name in names:
                    if map_base.get("translated"):
                        mapping[name] = copy_update(map_base,
                                                    lang=self.language)
                    else:
                        mapping[name] = map_base

        mapping = dict((fold_mapping_name(mname), mdata)
                       for (mname, mdata) in six.iteritems(mapping))
        self.mapping = mapping
        return mapping
Esempio n. 2
0
    def create_mapping(self):
        mapping = {}
        aliases = self._meta.field_aliases
        for model in self.get_related_models():
            for field, mode in self._get_fields_with_modes(model):
                map_base = self._get_map_base(field, mode)

                if isinstance(field, RelatedField) and not field.null:
                    map_base["priority"] -= 10

                # Figure out names
                names = [field.name]
                if field.verbose_name:
                    names.append(field.verbose_name)

                # find aliases
                this_aliases = aliases.get(field.name)
                if this_aliases:
                    if isinstance(this_aliases, six.string_types):
                        this_aliases = [this_aliases]
                    names.extend(this_aliases)

                # Assign into mapping
                for name in names:
                    if map_base.get("translated"):
                        mapping[name] = copy_update(map_base, lang=self.language)
                    else:
                        mapping[name] = map_base

        mapping = dict((fold_mapping_name(mname), mdata) for (mname, mdata) in six.iteritems(mapping))
        self.mapping = mapping
        return mapping