from django.core.management.base import BaseCommand from django.conf import settings from quiz.utils.importer import import_questions class Command(BaseCommand): help = 'Import questions from Markdown files' def add_arguments(self, parser): parser.add_argument( '--folder', type=str, default='content/Anatomi & Histologi 2/Gamla tentor', help='Folder to import questions from (relative to project root)' ) parser.add_argument( '--force', action='store_true', help='Force import even if files have not changed' ) def handle(self, *args, **options): import_folder = options['folder'] folder = settings.BASE_DIR.parent / import_folder if not folder.exists(): self.stdout.write(self.style.ERROR(f'Import folder {folder} does not exist')) return self.stdout.write(self.style.SUCCESS(f'Importing questions from {folder}...')) stats = import_questions(folder, folder, force=options['force']) # Only show full statistics if there were changes output = stats.format_output(show_if_no_changes=False) if output: self.stdout.write(output) if stats.errors > 0: self.stdout.write(self.style.WARNING(f'Completed with {stats.errors} errors')) else: self.stdout.write(self.style.SUCCESS('Import completed successfully!')) else: # No changes, show brief message self.stdout.write(self.style.SUCCESS(f'✓ All {stats.total_files} files up to date, no changes needed'))