Beispiel #1
0
def unload_app(app_name):
    # Output DROP TABLE statements for standard application tables.
    connection = connections[DEFAULT_DB_ALIAS]
    cursor = connection.cursor()
    
    output = []
    to_delete = set()
    references_to_delete = {}
    
    table_names = connection.introspection.get_table_list(cursor)
    for model in loaded_models[app_name]:
        if cursor and connection.introspection.table_name_converter(model._meta.db_table) in table_names:
            # The table exists, so it needs to be dropped
            opts = model._meta
            for f in opts.local_fields:
                if f.rel and f.rel.to not in to_delete:
                    references_to_delete.setdefault(f.rel.to, []).append( (model, f) )
            to_delete.add(model)
    
    for model in loaded_models[app_name]:
        if connection.introspection.table_name_converter(model._meta.db_table) in table_names:
            output.extend(connection.creation.sql_destroy_model(model, references_to_delete, no_style()))
    output = output[::-1] # Reverse it, to deal with table dependencies.
    for deletion in output:
        cursor.execute(deletion)
    transaction.commit_unless_managed(using=DEFAULT_DB_ALIAS)
    
    del cache.app_store[cache.load_app(app_name)]
Beispiel #2
0
def unload_app(app_name):
    # Output DROP TABLE statements for standard application tables.
    connection = connections[DEFAULT_DB_ALIAS]
    cursor = connection.cursor()

    output = []
    to_delete = set()
    references_to_delete = {}

    table_names = connection.introspection.get_table_list(cursor)
    for model in loaded_models[app_name]:
        if cursor and connection.introspection.table_name_converter(
                model._meta.db_table) in table_names:
            # The table exists, so it needs to be dropped
            opts = model._meta
            for f in opts.local_fields:
                if f.rel and f.rel.to not in to_delete:
                    references_to_delete.setdefault(f.rel.to, []).append(
                        (model, f))
            to_delete.add(model)

    for model in loaded_models[app_name]:
        if connection.introspection.table_name_converter(
                model._meta.db_table) in table_names:
            output.extend(
                connection.creation.sql_destroy_model(model,
                                                      references_to_delete,
                                                      no_style()))
    output = output[::-1]  # Reverse it, to deal with table dependencies.
    for deletion in output:
        cursor.execute(deletion)
    transaction.commit_unless_managed(using=DEFAULT_DB_ALIAS)

    del cache.app_store[cache.load_app(app_name)]
Beispiel #3
0
    def get_for_picking(self, ct):
        """ Returns class instance of a given model ContentType"""
        if type(ct) is not ContentType:
            raise TypeError, "cannot call get_for_picking without a valid ContentType, called with {0:>s}".format
    
        model = app_cache.get_model(ct.app_label, ct.model)
        
        if not model:
            try:
                app_cache.write_lock.acquire()
                module = app_cache.load_app('libscampi.contrib.{0:>s}'.format(ct.app_label))
                app_cache.write_lock.release()
                model = app_cache.get_model(ct.app_label, ct.model)
            except ImportError:
                raise NameError, "cannot get ({0:>s}, {1:>s}) from any path".format(ct.app_label, ct.model)
        
        if not self.is_registered(model):
            raise NameError, "({0:>s}, {1:>s}) is not registered for picking".format(ct.app_label, ct.model)

        try:
            fs = self.get_registration_info(model)()
        except PickerError:
            raise NameError, "({0:>s}, {1:>s}) has no filter set".format(ct.app_label, ct.model)
            
        return model, fs
Beispiel #4
0
 def test_new_import_doesnot_raise_exception(self):
     self.setup_app("circular_import_new", "circular_import_new.models.MyProduct")
     try:
         app = cache.load_app("circular_import_new")
     except ImproperlyConfigured:
         app = False
     self.assertTrue(app, 'Could not load app "circular_import_new"')
Beispiel #5
0
 def test_new_import_doesnot_raise_exception(self):
     self.setup_app('circular_import_new',
                    'circular_import_new.models.MyProduct')
     try:
         app = cache.load_app('circular_import_new')
     except ImproperlyConfigured:
         app = False
     self.assertTrue(app, 'Could not load app "circular_import_new"')
Beispiel #6
0
    def test_migration_path(self):
        _old_app_store = copy.deepcopy(cache.app_store)

        test_apps = [
            'migrations.migrations_test_apps.normal',
            'migrations.migrations_test_apps.with_package_model',
        ]

        base_dir = os.path.dirname(os.path.dirname(__file__))

        try:
            with override_settings(INSTALLED_APPS=test_apps):
                for app in test_apps:
                    cache.load_app(app)
                    migration = migrations.Migration('0001_initial', app.split('.')[-1])
                    expected_path = os.path.join(base_dir, *(app.split('.') + ['migrations', '0001_initial.py']))
                    writer = MigrationWriter(migration)
                    self.assertEqual(writer.path, expected_path)
        finally:
            cache.app_store = _old_app_store
    def test_migration_path(self):
        _old_app_store = copy.deepcopy(cache.app_store)

        test_apps = [
            'migrations.migrations_test_apps.normal',
            'migrations.migrations_test_apps.with_package_model',
        ]

        base_dir = os.path.dirname(os.path.dirname(__file__))

        try:
            with override_settings(INSTALLED_APPS=test_apps):
                for app in test_apps:
                    cache.load_app(app)
                    migration = migrations.Migration('0001_initial',
                                                     app.split('.')[-1])
                    expected_path = os.path.join(
                        base_dir,
                        *(app.split('.') + ['migrations', '0001_initial.py']))
                    writer = MigrationWriter(migration)
                    self.assertEqual(writer.path, expected_path)
        finally:
            cache.app_store = _old_app_store