From d305448e63e057e09059f286a4d795a9c6f83cae Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Mon, 9 Dec 2024 17:26:31 -0300 Subject: [PATCH] added loggin for state actions --- action/views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/action/views.py b/action/views.py index c185ad8..839e5ef 100644 --- a/action/views.py +++ b/action/views.py @@ -30,9 +30,7 @@ class NewActionView(View): institution=request.user.institution, ) #TODO: also change logger for full fledged table - device_logger.info( - f"Updated State to (key='{state_definition.state}', for device value='{snapshot_uuid}') by user {self.request.user}." - ) + device_logger.info(f"Updated State to (key='{state_definition.state}', for device value='{snapshot_uuid}') by user {self.request.user}.") messages.success(request, f"Action to '{state_definition.state}' has been added.") return redirect(request.META.get('HTTP_REFERER')) @@ -42,13 +40,19 @@ class NewActionView(View): class ActionUndoView(DeleteView): model = State - success_url = reverse_lazy('state_list') def delete(self, request, *args, **kwargs): self.object = self.get_object() time_since_creation = timezone.now() - self.object.date if time_since_creation.total_seconds() <= 3600: # 1 hour is 3600 seconds - return super().delete(request, *args, **kwargs) + device_logger.info(f"Action to state'{self.object.state}' has been deleted.") + data_to_return= super().delete(request, *args, **kwarg) + + messages.success(request, f"Action to state'{self.object.state}' has been deleted.") + return data_to_return else: messages.error(request, "You can undo an action within one hour of its creation.") - return redirect(request.META.get('HTTP_REFERER')) + return reverse_lazy(self.get_success_url()) + + def get_success_url(self): + return self.request.META.get('HTTP_REFERER', reverse_lazy('device:details', args=[self.object.snapshot_uuid]))