"""Defines views for the notifications application."""fromtypingimportAny,Typefromdjango.contribimportmessagesfromdjango.core.managementimportCommandError,call_commandfromdjango.httpimportHttpRequest,HttpResponse,HttpResponseRedirectfromdjango.shortcutsimportredirectfromdjango.urlsimportreverse_lazyfromdjango.utils.translationimportgettext_lazyas_fromdjango.views.genericimportDeleteView,TemplateViewfromhome.viewsimportERROR,SUCCESSfromnotifications.modelsimportNotificationModelfromtrustpoint.loggerimportLoggerMixin
[docs]classRefreshNotificationsView(LoggerMixin,TemplateView):"""View to execute all notifications and redirect back to dashboard."""
[docs]defget(self,request:HttpRequest,*args:Any,**kwargs:Any)->HttpResponseRedirect:"""Handles GET requests and redirects to the dashboard. Args: request: The HTTP request object. *args: Additional positional arguments. **kwargs: Keyword arguments passed to super().get_context_data. Returns: The response that redirects the user to home:dashboard. """delargsdelkwargstry:call_command('execute_all_notifications')messages.add_message(request,SUCCESS,_('Successfully refreshed notifications.'))exceptCommandErrorase:messages.add_message(request,ERROR,_('Error refreshing notifications: {}').format(str(e)))returnredirect('home:dashboard')
[docs]classNotificationDeleteView(LoggerMixin,DeleteView[NotificationModel,Any]):"""View to delete a notification."""
[docs]model:Type[NotificationModel]=NotificationModel# Explicitly set the model type