当前位置: 首页>>代码示例>>Python>>正文


Python Migrations.app_label方法代码示例

本文整理汇总了Python中south.migration.Migrations.app_label方法的典型用法代码示例。如果您正苦于以下问题:Python Migrations.app_label方法的具体用法?Python Migrations.app_label怎么用?Python Migrations.app_label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在south.migration.Migrations的用法示例。


在下文中一共展示了Migrations.app_label方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_south_migrations

# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import app_label [as 别名]
    def test_south_migrations(self):

        from django.core.exceptions import ImproperlyConfigured
        from django.conf import settings
        from django.db import models

        from south.migration import Migrations, migrate_app
        from south.models import MigrationHistory
        from south.exceptions import NoMigrations
        from south.creator import changes, actions, freezer
        from south.management.commands.datamigration import Command as DataCommand

        apps = [app for app in settings.INSTALLED_APPS
                if app.startswith('wagtail.')]
        failing_apps = []
        for app_name in apps:
            app = app_name.split('.')[-1]
            try:
                models.get_app(app)
            except ImproperlyConfigured:
                # This module fails to load, probably because it has no
                # models.py. Ignore it and move on
                continue

            try:
                migrations = Migrations(app, force_creation=False, verbose_creation=False)
                last_migration = migrations[-1]
            except (NoMigrations, IndexError):
                # No migrations for this app, probably doesnt have models
                continue

            if migrations.app_label() not in getattr(last_migration.migration_class(), "complete_apps", []):
                self.fail("Automatic migrations checking failed, since the previous migration does not have this whole app frozen.\nEither make migrations using '--freeze %s' or set 'SOUTH_AUTO_FREEZE_APP = True' in your settings.py." % migrations.app_label())

            # Alright, construct two model dicts to run the differ on.
            old_defs = dict(
                (k, v) for k, v in last_migration.migration_class().models.items()
                if k.split(".")[0] == migrations.app_label()
            )
            new_defs = dict(
                (k, v) for k, v in freezer.freeze_apps([migrations.app_label()]).items()
                if k.split(".")[0] == migrations.app_label()
            )
            change_source = changes.AutoChanges(
                migrations = migrations,
                old_defs = old_defs,
                old_orm = last_migration.orm(),
                new_defs = new_defs,
            )

            name = 'test'

            # Get the actions, and then insert them into the actions lists
            if list(change_source.get_changes()):
                failing_apps.append(app_name)

        if failing_apps:
            self.fail('Model changes with no South migration detected in apps: %s' % (
                ', '.join(failing_apps)))
开发者ID:akrawchyk,项目名称:wagtail,代码行数:61,代码来源:test_migrations.py

示例2: handle

# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import app_label [as 别名]
    def handle(self, app=None, name="", added_model_list=None, added_field_list=None, freeze_list=None, initial=False, auto=False, stdout=False, added_index_list=None, verbosity=1, **options):
        
        # Any supposed lists that are None become empty lists
        added_model_list = added_model_list or []
        added_field_list = added_field_list or []
        added_index_list = added_index_list or []
        freeze_list = freeze_list or []

        # --stdout means name = -
        if stdout:
            name = "-"
        
        # Make sure options are compatable
        if initial and (added_model_list or added_field_list or auto):
            self.error("You cannot use --initial and other options together\n" + self.usage_str)
        
        if auto and (added_model_list or added_field_list or initial):
            self.error("You cannot use --auto and other options together\n" + self.usage_str)
        
        # specify the default name 'initial' if a name wasn't specified and we're
        # doing a migration for an entire app
        if not name and initial:
            name = 'initial'
        
        # if not name, there's an error
        if not name:
            self.error("You must provide a name for this migration\n" + self.usage_str)
        
        if not app:
            self.error("You must provide an app to create a migration for.\n" + self.usage_str)
        
        # Get the Migrations for this app (creating the migrations dir if needed)
        migrations = Migrations(app, force_creation=True, verbose_creation=verbosity > 0)
        
        # See what filename is next in line. We assume they use numbers.
        new_filename = migrations.next_filename(name)
        
        # What actions do we need to do?
        if auto:
            # Get the old migration
            try:
                last_migration = migrations[-1]
            except IndexError:
                self.error("You cannot use --auto on an app with no migrations. Try --initial.")
            # Make sure it has stored models
            if migrations.app_label() not in getattr(last_migration.migration_class(), "complete_apps", []):
                self.error("You cannot use automatic detection, since the previous migration does not have this whole app frozen.\nEither make migrations using '--freeze %s' or set 'SOUTH_AUTO_FREEZE_APP = True' in your settings.py." % migrations.app_label())
            # Alright, construct two model dicts to run the differ on.
            old_defs = dict(
                (k, v) for k, v in last_migration.migration_class().models.items()
                if k.split(".")[0] == migrations.app_label()
            )
            new_defs = dict(
                (k, v) for k, v in freezer.freeze_apps([migrations.app_label()]).items()
                if k.split(".")[0] == migrations.app_label()
            )
            change_source = changes.AutoChanges(
                migrations = migrations,
                old_defs = old_defs,
                old_orm = last_migration.orm(),
                new_defs = new_defs,
            )
        
        elif initial:
            # Do an initial migration
            change_source = changes.InitialChanges(migrations)
        
        else:
            # Read the commands manually off of the arguments
            if (added_model_list or added_field_list or added_index_list):
                change_source = changes.ManualChanges(
                    migrations,
                    added_model_list,
                    added_field_list,
                    added_index_list,
                )
            else:
                print >>sys.stderr, "You have not passed any of --initial, --auto, --add-model, --add-field or --add-index."
                sys.exit(1)
        
        # Get the actions, and then insert them into the actions lists
        forwards_actions = []
        backwards_actions = []
        for action_name, params in change_source.get_changes():
            # Run the correct Action class
            try:
                action_class = getattr(actions, action_name)
            except AttributeError:
                raise ValueError("Invalid action name from source: %s" % action_name)
            else:
                action = action_class(**params)
                action.add_forwards(forwards_actions)
                action.add_backwards(backwards_actions)
                print >>sys.stderr, action.console_line()
        
        # Nowt happen? That's not good for --auto.
        if auto and not forwards_actions:
            self.error("Nothing seems to have changed.")
        
        # Work out which apps to freeze
#.........这里部分代码省略.........
开发者ID:stevejalim,项目名称:djeeknights,代码行数:103,代码来源:schemamigration.py

示例3: handle

# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import app_label [as 别名]
    def handle(self, app=None, name="", added_model_list=None,
               added_field_list=None, freeze_list=None, initial=False,
               auto=False, stdout=False, added_index_list=None, verbosity=1,
               empty=False, update=False, **options):

        # Any supposed lists that are None become empty lists
        added_model_list = added_model_list or []
        added_field_list = added_field_list or []
        added_index_list = added_index_list or []
        freeze_list = freeze_list or []

        # --stdout means name = -
        if stdout:
            name = "-"

        # Only allow valid names
        if re.search('[^_\w]', name) and name != "-":
            self.error(
                "Migration names should contain only alphanumeric characters and underscores.")

        # Make sure options are compatable
        if initial and (added_model_list or added_field_list or auto):
            self.error(
                "You cannot use --initial and other options together\n" + self.usage_str)

        if auto and (added_model_list or added_field_list or initial):
            self.error(
                "You cannot use --auto and other options together\n" + self.usage_str)

        if not app:
            self.error(
                "You must provide an app to create a migration for.\n" + self.usage_str)

        # See if the app exists
        app = app.split(".")[-1]
        try:
            app_module = models.get_app(app)
        except ImproperlyConfigured:
            print("There is no enabled application matching '%s'." % app)
            return

        # Get the Migrations for this app (creating the migrations dir if needed)
        migrations = Migrations(app, force_creation=True,
                                verbose_creation=int(verbosity) > 0)

        # What actions do we need to do?
        if auto:
            # Get the old migration
            try:
                last_migration = migrations[-2 if update else -1]
            except IndexError:
                self.error(
                    "You cannot use --auto on an app with no migrations. Try --initial.")
            # Make sure it has stored models
            if migrations.app_label() not in getattr(
                    last_migration.migration_class(), "complete_apps", []):
                self.error(
                    "You cannot use automatic detection, since the previous migration does not have this whole app frozen.\nEither make migrations using '--freeze %s' or set 'SOUTH_AUTO_FREEZE_APP = True' in your settings.py." % migrations.app_label())
            # Alright, construct two model dicts to run the differ on.
            old_defs = dict(
                (k, v) for k, v in
                last_migration.migration_class().models.items()
                if k.split(".")[0] == migrations.app_label()
            )
            new_defs = dict(
                (k, v) for k, v in
                freezer.freeze_apps([migrations.app_label()]).items()
                if k.split(".")[0] == migrations.app_label()
            )
            change_source = changes.AutoChanges(
                migrations=migrations,
                old_defs=old_defs,
                old_orm=last_migration.orm(),
                new_defs=new_defs,
            )

        elif initial:
            # Do an initial migration
            change_source = changes.InitialChanges(migrations)

        else:
            # Read the commands manually off of the arguments
            if (added_model_list or added_field_list or added_index_list):
                change_source = changes.ManualChanges(
                    migrations,
                    added_model_list,
                    added_field_list,
                    added_index_list,
                )
            elif empty:
                change_source = None
            else:
                print(
                    "You have not passed any of --initial, --auto, --empty, --add-model, --add-field or --add-index.",
                    file=sys.stderr)
                sys.exit(1)

        # Validate this so we can access the last migration without worrying
        if update and not migrations:
            self.error("You cannot use --update on an app with no migrations.")
#.........这里部分代码省略.........
开发者ID:repodevs,项目名称:bluebottle,代码行数:103,代码来源:bb_schemamigration.py


注:本文中的south.migration.Migrations.app_label方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。