本文整理汇总了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")
示例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]],
})
示例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)))
示例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
示例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,
})
示例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
示例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
示例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})
示例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
#.........这里部分代码省略.........
示例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.")
#.........这里部分代码省略.........