diff --git a/example/apps/test_security/tests/commands.py b/example/apps/test_security/tests/commands.py index a3f0f681..2f61d992 100644 --- a/example/apps/test_security/tests/commands.py +++ b/example/apps/test_security/tests/commands.py @@ -120,3 +120,10 @@ def test_elasticsearch_purge_logs_should_remove_logged_data(self): ).count(), 0) assert_equal(len(os.listdir(log_directory)), 1) shutil.rmtree(settings.BACKUP_STORAGE_PATH) + + @override_settings( + SECURITY_COMMAND_LOG_EXCLUDED_COMMANDS={'init_elasticsearch_log'}, + SECURITY_BACKUP_STORAGE_PATH=os.path.join(django_settings.PROJECT_DIR, 'var', 'backup_elastic') + ) + def test_sql_purge_logs_should_remove_logged_data(self): + test_call_command('init_elasticsearch_log', interactive=False) diff --git a/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py b/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py index 2969305b..8606780d 100644 --- a/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py +++ b/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py @@ -28,5 +28,9 @@ def handle(self, **options): self.stdout.write('Init elasticsearch logs') set_connection(init_documents=False) for document in InputRequestLog, OutputRequestLog, CommandLog, CeleryTaskRunLog, CeleryTaskInvocationLog: - document._index.delete(ignore=404) - document.init() + if issubclass(document, PartitionedLog): + template = document.get_template() + template.save() + else: + document._index.delete(ignore=404) + document.init()