Ejemplo n.º 1
0
 def __new__(cls, name, bases, attrs):
     super_new = super(PageMetaClass, cls).__new__
     if not settings.CMS_MODERATOR:
         attrs = install_mptt(cls, name, bases, attrs)
         new_class = super_new(cls, name, bases, attrs)
         finish_mptt(new_class)
         return new_class
     
     if 'objects' in attrs:
         if not isinstance(attrs['objects'], PublisherManager):
             raise ValueError, ("Model %s extends Publisher, " +
                                "so its 'objects' manager must be " +
                                "a subclass of publisher.PublisherManager") % (name,)
     else:
         attrs['objects'] = PublisherManager()
     
     attrs['_is_publisher_model'] = lambda self: True
     
     # build meta object
     publisher_meta = attrs.pop('PublisherMeta', None)
     attrs['_publisher_meta'] = PublisherOptions(name, bases, publisher_meta)
                 
     
     # take care of mptt, if required
     attrs = install_mptt(cls, name, bases, attrs)
     
     new_class = super_new(cls, name, bases, attrs)
     finish_mptt(new_class)
     return new_class
Ejemplo n.º 2
0
    def __new__(cls, name, bases, attrs):
        super_new = super(PageMetaClass, cls).__new__
        if not settings.CMS_MODERATOR:
            attrs = install_mptt(cls, name, bases, attrs)
            new_class = super_new(cls, name, bases, attrs)
            finish_mptt(new_class)
            return new_class

        if 'objects' in attrs:
            if not isinstance(attrs['objects'], PublisherManager):
                raise ValueError, (
                    "Model %s extends Publisher, " +
                    "so its 'objects' manager must be " +
                    "a subclass of publisher.PublisherManager") % (name, )
        else:
            attrs['objects'] = PublisherManager()

        attrs['_is_publisher_model'] = lambda self: True

        # build meta object
        publisher_meta = attrs.pop('PublisherMeta', None)
        attrs['_publisher_meta'] = PublisherOptions(name, bases,
                                                    publisher_meta)

        # take care of mptt, if required
        attrs = install_mptt(cls, name, bases, attrs)

        new_class = super_new(cls, name, bases, attrs)
        finish_mptt(new_class)
        return new_class
Ejemplo n.º 3
0
 def publisher_modelbase_new(cls, name, bases, attrs):
     """Override modelbase new method, check if Publisher attribute is
     subclass of Publisher.
     """
     
     if '_is_public_model' in attrs:
         attrs = install_mptt(cls, name, bases, attrs)
         new_class = _old_new(cls, name, bases, attrs)
         finish_mptt(new_class)
         return new_class
     
     # in case of model inheritance
     base_under_publisher = bool(filter(lambda b: issubclass(b, Publisher), bases))
     
     if Publisher in bases or base_under_publisher:            
         # copy attrs, because ModelBase affects them
         public_attrs = deepcopy(attrs)
         
         attrs['_is_publisher_model'] = lambda self: True
                     
         # create proxy - accessor for public model
         class PublicModelProxy(object):
             def __get__(self, name, cls):
                 public_name = PublisherManager.PUBLISHER_MODEL_NAME % cls._meta.object_name
                 model = get_model(cls._meta.app_label, public_name.lower())
                 return model
         
         attrs['PublicModel'] = PublicModelProxy()
     
     # take care of mptt, if required
     attrs = install_mptt(cls, name, bases, attrs)
     
     new_class = _old_new(cls, name, bases, attrs)
     
     if '_is_publisher_model' in attrs:
         # register it for future use..., @see publisher.post
         if not base_under_publisher:
             public_bases = list(bases)
             public_bases.remove(Publisher)
             if not public_bases:
                 public_bases = (models.Model,)
         else:
             public_bases = bases
         publisher_manager.register(cls, name, tuple(public_bases), public_attrs, new_class)
     
     finish_mptt(new_class)
     
     return new_class
Ejemplo n.º 4
0
 def __new__(cls, name, bases, attrs):
     render_meta = attrs.pop('RenderMeta', None)
     if render_meta is not None:
         attrs['_render_meta'] = render_meta()
     attrs = install_mptt(cls, name, bases, attrs)
     new_class = super(PluginModelBase, cls).__new__(cls, name, bases, attrs)
     found = False
     bbases = bases
     while bbases:
         bcls = bbases[0]
         if bcls.__name__ == "CMSPlugin":
             found = True
             bbases = False
         else:
             bbases = bcls.__bases__  
     if found:
         if new_class._meta.db_table.startswith("%s_" % new_class._meta.app_label):
             table = "cmsplugin_" + new_class._meta.db_table.split("%s_" % new_class._meta.app_label, 1)[1]
             new_class._meta.db_table = table
     return new_class 
Ejemplo n.º 5
0
 def publisher_modelbase_new(cls, name, bases, attrs):
     from publisher.models import Publisher
     
     
     """Override modelbase new method, check if Publisher attribute is
     subclass of Publisher.
     """
     # in case of model inheritance
     base_under_publisher = bool(filter(lambda b: issubclass(b, Publisher), bases))
     
     is_publisher_model = Publisher in bases or base_under_publisher
     
     if is_publisher_model:
         if ('objects' in attrs) and (not isinstance(attrs['objects'], PublisherManager)):
             raise ValueError, ("Model %s extends Publisher, " +
                                "so its 'objects' manager must be " +
                                "a subclass of publisher.PublisherManager") % (name,)
         
         if not 'objects' in attrs:
             attrs['objects'] = PublisherManager()
         
         attrs['_is_publisher_model'] = lambda self: True
         
         # build meta object
         publisher_meta = attrs.pop('PublisherMeta', None)
         attrs['_publisher_meta'] = PublisherOptions(name, bases, publisher_meta)
                 
     
     # take care of mptt, if required
     attrs = install_mptt(cls, name, bases, attrs)
     
     new_class = _old_new(cls, name, bases, attrs)
     finish_mptt(new_class)
     return new_class
 
     '''    
     """
     if Publisher in bases or base_under_publisher:            
         # copy attrs, because ModelBase affects them
         public_attrs = deepcopy(attrs)
         
         attrs['_is_publisher_model'] = lambda self: True
                     
         # create proxy - accessor for public model
         class PublicModelProxy(object):
             def __get__(self, name, cls):
                 public_name = PublisherManager.PUBLISHER_MODEL_NAME % cls._meta.object_name
                 model = get_model(cls._meta.app_label, public_name.lower())
                 return model
         
         attrs['PublicModel'] = PublicModelProxy()
     """
     
     
     
     if is_publisher_model:
         # register it for future use..., @see publisher.post
         if not base_under_publisher:
             public_bases = list(bases)
             public_bases.remove(Publisher)
             if not public_bases:
                 public_bases = (models.Model,)
         else:
             public_bases = bases
         publisher_manager.register(cls, name, tuple(public_bases), public_attrs, new_class)
     
     finish_mptt(new_class)
     '''
     return new_class
Ejemplo n.º 6
0
    def publisher_modelbase_new(cls, name, bases, attrs):
        from publisher.models import Publisher
        """Override modelbase new method, check if Publisher attribute is
        subclass of Publisher.
        """
        # in case of model inheritance
        base_under_publisher = bool(
            filter(lambda b: issubclass(b, Publisher), bases))

        is_publisher_model = Publisher in bases or base_under_publisher

        if is_publisher_model:
            if ('objects' in attrs) and (not isinstance(
                    attrs['objects'], PublisherManager)):
                raise ValueError, (
                    "Model %s extends Publisher, " +
                    "so its 'objects' manager must be " +
                    "a subclass of publisher.PublisherManager") % (name, )

            if not 'objects' in attrs:
                attrs['objects'] = PublisherManager()

            attrs['_is_publisher_model'] = lambda self: True

            # build meta object
            publisher_meta = attrs.pop('PublisherMeta', None)
            attrs['_publisher_meta'] = PublisherOptions(
                name, bases, publisher_meta)

        # take care of mptt, if required
        attrs = install_mptt(cls, name, bases, attrs)

        new_class = _old_new(cls, name, bases, attrs)
        finish_mptt(new_class)
        return new_class
        '''    
        """
        if Publisher in bases or base_under_publisher:            
            # copy attrs, because ModelBase affects them
            public_attrs = deepcopy(attrs)
            
            attrs['_is_publisher_model'] = lambda self: True
                        
            # create proxy - accessor for public model
            class PublicModelProxy(object):
                def __get__(self, name, cls):
                    public_name = PublisherManager.PUBLISHER_MODEL_NAME % cls._meta.object_name
                    model = get_model(cls._meta.app_label, public_name.lower())
                    return model
            
            attrs['PublicModel'] = PublicModelProxy()
        """
        
        
        
        if is_publisher_model:
            # register it for future use..., @see publisher.post
            if not base_under_publisher:
                public_bases = list(bases)
                public_bases.remove(Publisher)
                if not public_bases:
                    public_bases = (models.Model,)
            else:
                public_bases = bases
            publisher_manager.register(cls, name, tuple(public_bases), public_attrs, new_class)
        
        finish_mptt(new_class)
        '''
        return new_class