コード例 #1
0
ファイル: plugin_pool.py プロジェクト: acspike/django-cms
    def set_plugin_meta(self):
        """
        Patches a plugin model by forcing a specifc db_table whether the
        'new style' table name exists or not. The same goes for all the
        ManyToMany attributes.
        This method must be run whenever a plugin model is accessed
        directly.

        The model is modified in place; a 'patched' attribute is added
        to the model to check whether it's already been modified.
        """
        if self.patched:
            return
        table_names = connection.introspection.table_names()
        subs = get_subclasses(CMSPlugin)
        for model in subs:
            if not model._meta.abstract:

                splitter = '%s_' % model._meta.app_label
                table_name = model._meta.db_table
                if (table_name not in table_names
                and splitter in table_name):
                    old_db_name = table_name
                    splitted = table_name.split(splitter, 1)
                    table_name = 'cmsplugin_%s' % splitted[1]
                    if table_name in table_names:
                        model._meta.db_table = table_name
                        warnings.warn(
                            'please rename the table "%s" to "%s" in %s\nThe compatibility code will be removed in 3.1' % (
                                table_name, old_db_name, model._meta.app_label), DeprecationWarning)
                for att_name in model.__dict__.keys():
                    att = model.__dict__[att_name]
                    if isinstance(att, ManyToManyField):
                        table_name = att.rel.through._meta.db_table
                        if (table_name not in table_names
                        and splitter in table_name):
                            old_db_name = table_name
                            splitted = table_name.split(splitter, 1)
                            table_name = 'cmsplugin_%s' % splitted[1]
                            if table_name in table_names:
                                att.rel.through._meta.db_table = table_name
                                warnings.warn(
                                    'please rename the table "%s" to "%s" in %s\nThe compatibility code will be removed in 3.1' % (
                                        table_name, old_db_name, model._meta.app_label), DeprecationWarning)
                    elif isinstance(att, ReverseManyRelatedObjectsDescriptor):
                        table_name = att.through._meta.db_table
                        if (table_name not in table_names
                        and splitter in table_name):
                            old_db_name = table_name
                            splitted = table_name.split(splitter, 1)
                            table_name = 'cmsplugin_%s_items' % splitted[1]
                            if table_name in table_names:
                                att.through._meta.db_table = table_name
                                warnings.warn(
                                    'please rename the table "%s" to "%s" in %s\nThe compatibility code will be removed in 3.1' % (
                                        table_name, old_db_name, model._meta.app_label), DeprecationWarning)

        self.patched = True
コード例 #2
0
ファイル: plugin_pool.py プロジェクト: mgom/django-cms
    def set_plugin_meta(self):
        """
        Patches a plugin model by forcing a specifc db_table whether the
        'new style' table name exists or not. The same goes for all the
        ManyToMany attributes.
        This method must be run whenever a plugin model is accessed
        directly.

        The model is modified in place; a 'patched' attribute is added
        to the model to check whether it's already been modified.
        """
        if self.patched:
            return
        table_names = connection.introspection.table_names()
        subs = get_subclasses(CMSPlugin)
        for model in subs:
            if not model._meta.abstract:

                splitter = '%s_' % model._meta.app_label
                table_name = model._meta.db_table
                if (table_name not in table_names and splitter in table_name):
                    old_db_name = table_name
                    splitted = table_name.split(splitter, 1)
                    table_name = 'cmsplugin_%s' % splitted[1]
                    if table_name in table_names:
                        model._meta.db_table = table_name
                        warnings.warn(
                            'please rename the table "%s" to "%s" in %s\nThe compatibility code will be removed in 3.1'
                            % (table_name, old_db_name, model._meta.app_label),
                            DeprecationWarning)
                for att_name in model.__dict__.keys():
                    att = model.__dict__[att_name]
                    if isinstance(att, ManyToManyField):
                        table_name = att.rel.through._meta.db_table
                        if (table_name not in table_names
                                and splitter in table_name):
                            old_db_name = table_name
                            splitted = table_name.split(splitter, 1)
                            table_name = 'cmsplugin_%s' % splitted[1]
                            if table_name in table_names:
                                att.rel.through._meta.db_table = table_name
                                warnings.warn(
                                    'please rename the table "%s" to "%s" in %s\nThe compatibility code will be removed in 3.1'
                                    % (table_name, old_db_name,
                                       model._meta.app_label),
                                    DeprecationWarning)
                    elif isinstance(att, ReverseManyRelatedObjectsDescriptor):
                        table_name = att.through._meta.db_table
                        if (table_name not in table_names
                                and splitter in table_name):
                            old_db_name = table_name
                            splitted = table_name.split(splitter, 1)
                            table_name = 'cmsplugin_%s_items' % splitted[1]
                            if table_name in table_names:
                                att.through._meta.db_table = table_name
                                warnings.warn(
                                    'please rename the table "%s" to "%s" in %s\nThe compatibility code will be removed in 3.1'
                                    % (table_name, old_db_name,
                                       model._meta.app_label),
                                    DeprecationWarning)

        self.patched = True