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


Python freezer.freeze_apps函数代码示例

本文整理汇总了Python中south.creator.freezer.freeze_apps函数的典型用法代码示例。如果您正苦于以下问题:Python freeze_apps函数的具体用法?Python freeze_apps怎么用?Python freeze_apps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_not_deleted_auto

    def test_not_deleted_auto(self):

        empty_defs = { }
        old_defs = freezer.freeze_apps(["non_managed"])
        class InitialMigration(SchemaMigration):
            "Serves as fake previous migration"
        
            def forwards(self, orm):
                pass
        
            def backwards(self, orm):
                pass
        
            models = self.full_defs

            complete_apps = ['non_managed']
                    
        migrations = Migrations("non_managed")
        initial_orm = FakeORM(InitialMigration, "non_managed")
        changes = AutoChanges(
            migrations = migrations,
            old_defs = self.full_defs,
            old_orm = initial_orm,
            new_defs = empty_defs,
        )
        change_list = changes.get_changes()
        if list(change_list):
            self.fail("Auto migration deletes table for non-managed model")
开发者ID:brynn,项目名称:slowdown,代码行数:28,代码来源:autodetection.py

示例2: get_changes

 def get_changes(self):
     # Get the model defs so we can use them for the yield later
     model_defs = freeze_apps([self.migrations.app_label()])
     # Make the model changes
     for model_name in self.added_models:
         model = models.get_model(self.migrations.app_label(), model_name)
         real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
         yield ("AddModel", {
             "model": model,
             "model_def": real_fields,
         })
     # And the field changes
     for field_desc in self.added_fields:
         try:
             model_name, field_name = field_desc.split(".")
         except (TypeError, ValueError):
             raise ValueError("%r is not a valid field description." % field_desc)
         model = models.get_model(self.migrations.app_label(), model_name)
         real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
         yield ("AddField", {
             "model": model,
             "field": model._meta.get_field_by_name(field_name)[0],
             "field_def": real_fields[field_name],
         })
     # And the indexes
     for field_desc in self.added_indexes:
         try:
             model_name, field_name = field_desc.split(".")
         except (TypeError, ValueError):
             print("%r is not a valid field description." % field_desc)
         model = models.get_model(self.migrations.app_label(), model_name)
         yield ("AddIndex", {
             "model": model,
             "fields": [model._meta.get_field_by_name(field_name)[0]],
         })
开发者ID:adamjberg,项目名称:finna-be-octo-ninja,代码行数:35,代码来源:changes.py

示例3: test_south_migrations

    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,代码行数:59,代码来源:test_migrations.py

示例4: get_user_frozen_models

def get_user_frozen_models(user_model):
    from south.creator.freezer import freeze_apps
    user_app, user_class = user_model.split('.')
    if user_model != 'auth.User':
        from south.migration.base import Migrations
        from south.exceptions import NoMigrations
        try:
            user_migrations = Migrations(user_app)
        except NoMigrations:
            extra_model = freeze_apps(user_app)
        else:
            from pybb import defaults
            migration_name = defaults.PYBB_INITIAL_CUSTOM_USER_MIGRATION or '0001_initial.py'
            initial_user_migration = user_migrations.migration(migration_name)
            extra_model = initial_user_migration.migration_class().models
    else:
        extra_model = freeze_apps(user_app)
    return extra_model
开发者ID:TechMobileSoftware,项目名称:pybbm,代码行数:18,代码来源:compat.py

示例5: get_changes

    def get_changes(self):
        # Get the frozen models for this app
        model_defs = freeze_apps([self.migrations.app_label()])

        for model in models.get_models(models.get_app(self.migrations.app_label())):

            # Don't do anything for unmanaged, abstract or proxy models
            if model._meta.abstract or getattr(
                    model._meta, "proxy", False) or not getattr(model._meta, "managed", True):
                continue

            real_fields, meta, m2m_fields = self.split_model_def(
                model, model_defs[model_key(model)])

            # Firstly, add the main table and fields
            yield ("AddModel", {
                "model": model,
                "model_def": real_fields,
            })

            # Then, add any indexing/uniqueness that's around
            if meta:
                for attr, operation in (("unique_together", "AddUnique"),
                                        ("index_together", "AddIndex")):
                    together = eval(meta.get(attr, "[]"))
                    if together:
                        # If it's only a single tuple, make it into the longer one
                        if isinstance(together[0], string_types):
                            together = [together]
                        # For each combination, make an action for it
                        for fields in together:
                            yield (operation, {
                                "model": model,
                                "fields": [model._meta.get_field_by_name(x)[0] for x in fields],
                            })

            # Finally, see if there's some M2M action
            for name, triple in m2m_fields.items():
                field = model._meta.get_field_by_name(name)[0]
                # But only if it's not through=foo (#120)
                if field.rel.through:
                    try:
                        # Django 1.1 and below
                        through_model = field.rel.through_model
                    except AttributeError:
                        # Django 1.2
                        through_model = field.rel.through
                if (not field.rel.through) or getattr(through_model._meta, "auto_created", False):
                    yield ("AddM2M", {
                        "model": model,
                        "field": field,
                    })
开发者ID:Kayle009,项目名称:sentry,代码行数:52,代码来源:changes.py

示例6: get_changes

 def get_changes(self):
     # Get the model defs so we can use them for the yield later
     model_defs = freeze_apps([self.migrations.app_label()])
     # Make the model changes
     for model_name in self.added_models:
         model = models.get_model(self.migrations.app_label(), model_name)
         real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
         yield ("AddModel", {
             "model": model,
             "model_def": real_fields,
         })
     # And the field changes
     for field_name in self.added_fields:
         raise NotImplementedError
     # And the indexes
     for index_name in self.added_indexes:
         raise NotImplementedError
开发者ID:stevejalim,项目名称:djeeknights,代码行数:17,代码来源:changes.py

示例7: custom_user_frozen_models

def custom_user_frozen_models(user_model):
    migration_name = getattr(settings, 'INITIAL_CUSTOM_USER_MIGRATION',
                             '0001_initial.py')
    if user_model != 'auth.User':
        from south.migration.base import Migrations
        from south.exceptions import NoMigrations
        from south.creator.freezer import freeze_apps
        user_app, user_model = user_model.split('.')
        try:
            user_migrations = Migrations(user_app)
        except NoMigrations:
            extra_model = freeze_apps(user_app)
        else:
            initial_user_migration = user_migrations.migration(migration_name)
            extra_model = initial_user_migration.migration_class().models
    else:
        extra_model = {}
    return extra_model
开发者ID:Memrise,项目名称:django-social-auth,代码行数:18,代码来源:utils.py

示例8: get_changes

    def get_changes(self):
        # Get the frozen models for this app
        model_defs = freeze_apps([self.migrations.app_label()])

        for model in models.get_models(models.get_app(self.migrations.app_label())):

            # Don't do anything for unmanaged, abstract or proxy models
            if (
                model._meta.abstract
                or getattr(model._meta, "proxy", False)
                or not getattr(model._meta, "managed", True)
            ):
                continue

            real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])

            # Firstly, add the main table and fields
            yield ("AddModel", {"model": model, "model_def": real_fields})

            # Then, add any uniqueness that's around
            if meta:
                unique_together = eval(meta.get("unique_together", "[]"))
                if unique_together:
                    # If it's only a single tuple, make it into the longer one
                    if isinstance(unique_together[0], basestring):
                        unique_together = [unique_together]
                    # For each combination, make an action for it
                    for fields in unique_together:
                        yield (
                            "AddUnique",
                            {"model": model, "fields": [model._meta.get_field_by_name(x)[0] for x in fields]},
                        )

            # Finally, see if there's some M2M action
            for name, triple in m2m_fields.items():
                field = model._meta.get_field_by_name(name)[0]
                # But only if it's not through=foo (#120)
                if (not field.rel.through) or getattr(field.rel.through._meta, "auto_created", False):
                    yield ("AddM2M", {"model": model, "field": field})
开发者ID:johnarnfield,项目名称:django-south,代码行数:39,代码来源:changes.py

示例9: handle

    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,代码行数:101,代码来源:schemamigration.py

示例10: handle

    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,代码行数:101,代码来源:bb_schemamigration.py


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