"""This module defines a Django management command to delete all existing notifications."""fromtypingimportAnyfromdjango.core.management.baseimportBaseCommandfromnotifications.modelsimportNotificationModelfromtrustpoint.settingsimportDOCKER_CONTAINER
[docs]classCommand(BaseCommand):"""A Django management command to delete all existing notifications. If running inside a Docker container, the command deletes notifications without user confirmation. Otherwise, it prompts the user for confirmation. """
[docs]defhandle(self,**options:Any)->None:# noqa: ARG002"""Entrypoint for the command. Args: **options: A variable-length argument. """ifDOCKER_CONTAINER:self.delete_notifications()returnconfirm=input('Are you sure you want to delete all notifications? Type "yes" to confirm: ')ifconfirm.strip().lower()=='yes':self.delete_notifications()else:self.stdout.write(self.style.WARNING('Deletion cancelled.'))
[docs]defdelete_notifications(self)->None:"""Deletes all notifications and reports the result."""count,_=NotificationModel.objects.all().delete()self.stdout.write(self.style.SUCCESS(f'Deleted {count} notifications.'))