diff --git a/action/views.py b/action/views.py index a3e036c..1a1977c 100644 --- a/action/views.py +++ b/action/views.py @@ -5,14 +5,11 @@ from action.forms import ChangeStateForm, AddNoteForm from django.views.generic.edit import DeleteView, CreateView, FormView from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ -from action.models import State, StateDefinition, Note +from action.models import State, StateDefinition, Note, DeviceLog from device.models import Device import logging -device_logger = logging.getLogger('device_log') - - class ChangeStateView(View): def post(self, request, *args, **kwargs): @@ -30,9 +27,13 @@ class ChangeStateView(View): institution=self.request.user.institution, ) - device_logger.info(f" State to '{new_state}', from '{previous_state}' ) by user {self.request.user}.") - message = _("State changed from '{}' to '{}'.".format(previous_state, new_state) ) + DeviceLog.objects.create( + snapshot_uuid=snapshot_uuid, + event=message, + user=self.request.user, + institution=self.request.user.institution, + ) messages.success(request,message) else: messages.error(request, "There was an error with your submission.") @@ -48,9 +49,7 @@ class UndoStateView(DeleteView): return super().delete(request, *args, **kwarg) def get_success_url(self): - messages.info(self.request, f"Action to state: {self.object.state} has been deleted.") - device_logger.info(f" State '{self.object.state}', for device '{self.object.snapshot_uuid}') by user {self.request.user}.") return self.request.META.get('HTTP_REFERER', reverse_lazy('device:details', args=[self.object.snapshot_uuid])) @@ -68,6 +67,14 @@ class AddNoteView(View): user=self.request.user, institution=self.request.user.institution, ) + + message = _("Note: '{}' ".format(note) ) + DeviceLog.objects.create( + snapshot_uuid=snapshot_uuid, + event=message, + user=self.request.user, + institution=self.request.user.institution, + ) messages.success(request, _("Note has been added")) else: messages.error(request, "There was an error with your submission.") diff --git a/device/templates/details.html b/device/templates/details.html index 9e8dfc8..1490aa3 100644 --- a/device/templates/details.html +++ b/device/templates/details.html @@ -36,12 +36,12 @@ {% endfor %} - + {% else %} {% endif %} @@ -65,7 +65,7 @@ {% trans 'Log' %}