change state delete to undo last state

This commit is contained in:
Thomas Nahuel Rusiecki 2024-12-16 15:21:09 -03:00
parent a971889fb1
commit 92024a96c1
2 changed files with 9 additions and 17 deletions

View file

@ -45,17 +45,10 @@ class ActionUndoView(DeleteView):
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 = 3600 seconds
data_to_return= super().delete(request, *args, **kwarg)
messages.success(request, f"Action to state'{self.object.state}' has been delete.")
return data_to_return
else:
#TODO: revise if condition is correct
messages.error(request, "You can undo an action within one hour of its creation.")
return reverse_lazy(self.get_success_url())
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"<Deleted> 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]))

View file

@ -90,7 +90,7 @@
</th>
<th scope="col">{% trans 'User' %}
</th>
<th scope="col">{% trans 'Date' %}
<th scope="col">{% trans 'Since' %}
</th>
</tr>
</thead>
@ -101,15 +101,14 @@
</td>
<td>{{ device_states.0.user.responsable_person|default:device_states.0.user.username }}
</td>
<td>{{ device_states.0.date|date:"M j, Y, H:i" }}
<td>{{ device_states.0.date|timesince }}
</td>
{% if device_states.0.date|timesince < '1 hour' %}
<td>
<a href="#" data-bs-toggle="modal" data-bs-target="#deleteStateModal{{ device_states.0.id }}" title="{% trans 'Undo' %}">
<i class="bi bi-trash text-danger"></i>
<td class="text-end">
<a href="#" data-bs-toggle="modal" class="text-danger" data-bs-target="#deleteStateModal{{ device_states.0.id }}" title="{% trans 'Undo' %}">
{% trans 'undo' %}
<i class="fas fa-undo ps-1"></i>
</a>
</td>
{% endif %}
</tr>
{% else %}
<tr>