Esempio n. 1
0
    def register(self, model_name, Resource=AdminResource):
        """docstring for register"""
        if isinstance(model_name, (str, unicode, basestring, )):
            # for model_name2, model2 in loading.cache.models.items():
                # print model_name2, model2
            model = loading.get_model(model_name)
            if model is None:
                raise Exception('Model %s doesnt exist' % (model_name, ))
        else:
            model = model_name

        if model in self.resources_by_model:
            raise Exception('Aldready registered')
        
        resource = Resource(model)
        self.resources_by_model[model] = resource
        self.resources_by_slug[resource.slug] = resource
Esempio n. 2
0
    def __new__(cls, name, bases, attrs):
        Model = loading.get_model(name)
        if Model is not None:
            return Model
            
        super_new = super(DocumentMetaclass, cls).__new__
        parents = [base for base in bases if isinstance(base, DocumentMetaclass)]
        
        if not parents:
            return super_new(cls, name, bases, attrs)
            
        new_class = super_new(cls, name, bases, {'__module__': attrs.pop('__module__')})

        new_class.add_to_class('metadata', Metadata(attrs.pop('Metadata', None)))
            
        Criteria(new_class)
        
        for attr_name, attr in attrs.items():
            new_class.add_to_class(attr_name, attr)
        
        return loading.register(new_class)
Esempio n. 3
0
 def get_document_class(self, name):
     """docstring for get_collection"""
     if isinstance(name, (str, unicode, basestring, )):
         return loading.get_model(name)
     return name