8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Handle dates more gracefuly in machine history view

This commit is contained in:
Jean-Romain Garnier 2020-04-22 18:52:58 +02:00 committed by Gabriel Detraz
parent fa439f9e9c
commit bc688d39f9

View file

@ -22,7 +22,6 @@
The models definitions for the Machines app The models definitions for the Machines app
""" """
from reversion.models import Version from reversion.models import Version
from datetime import datetime
from machines.models import IpList from machines.models import IpList
from machines.models import Interface from machines.models import Interface
@ -74,21 +73,6 @@ class MachineHistory:
self.end = params.get("e", None) self.end = params.get("e", None)
search_type = params.get("t", 0) search_type = params.get("t", 0)
# Convert dates to datetime objects
if self.start:
self.start = datetime.datetime(
self.start.year,
self.start.month,
self.start.day
)
if self.end:
self.end = datetime.datetime(
self.end.year,
self.end.month,
self.end.day
)
self.events = [] self.events = []
if search_type == "ip": if search_type == "ip":
return self.__get_by_ip(search) return self.__get_by_ip(search)
@ -113,12 +97,12 @@ class MachineHistory:
self.__last_evt.end_date = evt.start_date self.__last_evt.end_date = evt.start_date
# If the event ends before the given date, remove it # If the event ends before the given date, remove it
if self.start and evt.start_date < self.start: if self.start and evt.start_date.date() < self.start:
self.__last_evt = None self.__last_evt = None
self.events.pop() self.events.pop()
# Make sure the new event starts before the given end date # Make sure the new event starts before the given end date
if self.end and evt.start_date > self.end: if self.end and evt.start_date.date() > self.end:
return return
# Save the new element # Save the new element