transmeta/management/commands/sync_transmeta_db.py
def handle(self, *args, **options):
        """ command execution """
        assume_yes = options.get('assume_yes', False)
        default_language = options.get('default_language', None)

        # set manual transaction management
        transaction.commit_unless_managed()
        transaction.enter_transaction_management()
        transaction.managed(True)

        self.cursor = connection.cursor()
        self.introspection = connection.introspection

        self.default_lang = default_language or mandatory_language()

        all_models = get_models()
        found_db_change_fields = False
        for model in all_models:
            if hasattr(model._meta, 'translatable_fields'):
                model_full_name = '%s.%s' % (model._meta.app_label, model._meta.module_name)
                translatable_fields = get_all_translatable_fields(model, column_in_current_table=True)
                db_table = model._meta.db_table
                for field_name in translatable_fields:
                    db_table_fields = self.get_table_fields(db_table)
                    db_change_langs = list(set(list(self.get_db_change_languages(field_name, db_table_fields)) + [self.default_lang]))
                    if db_change_langs:
                        sql_sentences = self.get_sync_sql(field_name, db_change_langs, model, db_table_fields)
                        if sql_sentences:
                            found_db_change_fields = True
                            print_db_change_langs(db_change_langs, field_name, model_full_name)
                            execute_sql = ask_for_confirmation(sql_sentences, model_full_name, assume_yes)
                            if execute_sql:
                                print ('Executing SQL...')
                                for sentence in sql_sentences:
                                    self.cursor.execute(sentence)
                                    # commit
                                    transaction.commit()
                                print ('Done')
                            else:
                                print ('SQL not executed')

        if transaction.is_dirty():
            transaction.commit()
        transaction.leave_transaction_management()

        if not found_db_change_fields:
            print ('\nNo new translatable fields detected')
        if default_language:
            variable = 'TRANSMETA_DEFAULT_LANGUAGE'
            has_transmeta_default_language = getattr(settings, variable, False)
            if not has_transmeta_default_language:
                variable = 'LANGUAGE_CODE'
            if getattr(settings, variable) != default_language:
                print (('\n\nYou should change in your settings '
                       'the %s variable to "%s"' % (variable, default_language)))
def handle(self, *args, **options):
        """ command execution """
        assume_yes = options.get('assume_yes', False)
        default_language = options.get('default_language', None)

        # set manual transaction management
        transaction.commit_unless_managed()
        transaction.enter_transaction_management()
        transaction.managed(True)

        self.cursor = connection.cursor()
        self.introspection = connection.introspection

        self.default_lang = default_language or mandatory_language()

        all_models = get_models()
        found_db_change_fields = False
        for model in all_models:
            if hasattr(model._meta, 'translatable_fields'):
                model_full_name = '%s.%s' % (model._meta.app_label, model._meta.module_name)
                translatable_fields = get_all_translatable_fields(model, column_in_current_table=True)
                db_table = model._meta.db_table
                for field_name in translatable_fields:
                    db_table_fields = self.get_table_fields(db_table)
                    db_change_langs = list(set(list(self.get_db_change_languages(field_name, db_table_fields)) + [self.default_lang]))
                    if db_change_langs:
                        sql_sentences = self.get_sync_sql(field_name, db_change_langs, model, db_table_fields)
                        if sql_sentences:
                            found_db_change_fields = True
                            print_db_change_langs(db_change_langs, field_name, model_full_name)
                            execute_sql = ask_for_confirmation(sql_sentences, model_full_name, assume_yes)
                            if execute_sql:
                                print ('Executing SQL...')
                                for sentence in sql_sentences:
                                    self.cursor.execute(sentence)
                                    # commit
                                    transaction.commit()
                                print ('Done')
                            else:
                                print ('SQL not executed')

        if transaction.is_dirty():
            transaction.commit()
        transaction.leave_transaction_management()

        if not found_db_change_fields:
            print ('\nNo new translatable fields detected')
        if default_language:
            variable = 'TRANSMETA_DEFAULT_LANGUAGE'
            has_transmeta_default_language = getattr(settings, variable, False)
            if not has_transmeta_default_language:
                variable = 'LANGUAGE_CODE'
            if getattr(settings, variable) != default_language:
                print (('\n\nYou should change in your settings '
                       'the %s variable to "%s"' % (variable, default_language)))
command execution