Exemplo n.º 1
0
    def _find_base_classes(self, class_mapping):
        r = []
        for base in self.options.bases:
            if base in class_mapping:
                r.append(class_mapping[base])
            else:
                raise MissingBaseClassMappingError(
                    "Please provide a class_mapping for '{}'".format(base))

        # TODO: how to provide additional mappings for a model name?
        # Note: the next lines conflict if models inherit from each other
        # if name in class_mapping:
        #     r.append(class_mapping[name])

        if has_option(class_mapping, "bases"):
            r += get_option(class_mapping, "bases")

        if not any([isinstance(base, self.base_model) for base in r]):
            r.append(self.base_model)

        return tuple(r)
Exemplo n.º 2
0
def _find_base_classes(name, spec, class_mapping=None):
    if class_mapping is None:
        class_mapping = {}
    for k, v in iteritems(DEFAULT_MAPPINGS):
        if k not in class_mapping:
            class_mapping[k] = v

    r = []
    for base in get_option(spec, 'bases', []):
        if base in class_mapping:
            r.append(class_mapping[base])
        else:
            raise MissingBaseClassMappingError(
                "Please provide a class_mapping for {}".format(base))

    # TODO: how to provide additional mappings for a model name?
    # Note: the next lines conflict if models inherit from each other
    # if name in class_mapping:
    #     r.append(class_mapping[name])

    if not any([isinstance(base, BaseModel) for base in r]):
        r.append(BaseModel)

    return tuple(r)
Exemplo n.º 3
0
def _get_bases(spec):
    if has_option(spec, "bases"):
        return set(get_option(spec, "bases"))
    else:
        return set()
Exemplo n.º 4
0
 def _get_model_name(self, name, spec=None):
     if spec and has_option(spec, "name"):
         return get_option(spec, "name")
     return camelize(name) + self._model_suffix