logging for statedefinitions
This commit is contained in:
parent
2d84b71cb2
commit
814f28bbd7
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from smtplib import SMTPException
|
from smtplib import SMTPException
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
@ -18,6 +19,8 @@ from user.models import User, Institution
|
||||||
from admin.email import NotifyActivateUserByEmail
|
from admin.email import NotifyActivateUserByEmail
|
||||||
from action.models import StateDefinition
|
from action.models import StateDefinition
|
||||||
|
|
||||||
|
device_logger = logging.getLogger('device_log')
|
||||||
|
|
||||||
class AdminView(DashboardView):
|
class AdminView(DashboardView):
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
response = super().get(*args, **kwargs)
|
response = super().get(*args, **kwargs)
|
||||||
|
@ -139,11 +142,13 @@ class StateDefinitionContextMixin(ContextMixin):
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class StatesPanelView(AdminView, StateDefinitionContextMixin, TemplateView):
|
class StatesPanelView(AdminView, StateDefinitionContextMixin, TemplateView):
|
||||||
template_name = "states_panel.html"
|
template_name = "states_panel.html"
|
||||||
title = _("States")
|
title = _("States")
|
||||||
breadcrumb = _("admin / States") + " /"
|
breadcrumb = _("admin / States") + " /"
|
||||||
|
|
||||||
|
|
||||||
class AddStateDefinitionView(AdminView, StateDefinitionContextMixin, CreateView):
|
class AddStateDefinitionView(AdminView, StateDefinitionContextMixin, CreateView):
|
||||||
template_name = "states_panel.html"
|
template_name = "states_panel.html"
|
||||||
title = _("New State Definition")
|
title = _("New State Definition")
|
||||||
|
@ -157,7 +162,8 @@ class AddStateDefinitionView(AdminView, StateDefinitionContextMixin, CreateView)
|
||||||
form.instance.user = self.request.user
|
form.instance.user = self.request.user
|
||||||
try:
|
try:
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
messages.success(self.request, _("State definition successfully added."))
|
messages.success(self.request, _("State definition successfully added."))
|
||||||
|
device_logger.info(f"<Created> StateDefinition with value {form.instance.state} by user {self.request.user}.")
|
||||||
return response
|
return response
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
messages.error(self.request, _("State is already defined."))
|
messages.error(self.request, _("State is already defined."))
|
||||||
|
@ -172,6 +178,7 @@ class DeleteStateDefinitionView(AdminView, StateDefinitionContextMixin, SuccessM
|
||||||
success_url = reverse_lazy('admin:states')
|
success_url = reverse_lazy('admin:states')
|
||||||
|
|
||||||
def get_success_message(self, cleaned_data):
|
def get_success_message(self, cleaned_data):
|
||||||
|
device_logger.info(f"<Deleted> StateDefinition with value {self.object.state} by user {self.request.user}.")
|
||||||
return f'State definition: {self.object.state}, has been deleted'
|
return f'State definition: {self.object.state}, has been deleted'
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
def delete(self, request, *args, **kwargs):
|
||||||
|
@ -183,6 +190,7 @@ class DeleteStateDefinitionView(AdminView, StateDefinitionContextMixin, SuccessM
|
||||||
|
|
||||||
return super().delete(request, *args, **kwargs)
|
return super().delete(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class UpdateStateOrderView(AdminView, TemplateView):
|
class UpdateStateOrderView(AdminView, TemplateView):
|
||||||
success_url = reverse_lazy('admin:states')
|
success_url = reverse_lazy('admin:states')
|
||||||
|
|
||||||
|
@ -194,12 +202,17 @@ class UpdateStateOrderView(AdminView, TemplateView):
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
current_order = 1
|
current_order = 1
|
||||||
|
_log = []
|
||||||
for lookup_id in ordered_ids:
|
for lookup_id in ordered_ids:
|
||||||
state_definition = StateDefinition.objects.get(id=lookup_id)
|
state_definition = StateDefinition.objects.get(id=lookup_id)
|
||||||
state_definition.order = current_order
|
state_definition.order = current_order
|
||||||
state_definition.save()
|
state_definition.save()
|
||||||
|
_log.append(f"{state_definition.state} (ID: {lookup_id} -> Order: {current_order})")
|
||||||
current_order += 1
|
current_order += 1
|
||||||
|
|
||||||
|
device_logger.info(
|
||||||
|
f"<Updated Order> State order updated by user {self.request.user}: {', '.join(_log)}"
|
||||||
|
)
|
||||||
messages.success(self.request, _("Order changed succesfuly."))
|
messages.success(self.request, _("Order changed succesfuly."))
|
||||||
return redirect(self.success_url)
|
return redirect(self.success_url)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue