mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Add comments to logs/models.py
This commit is contained in:
parent
c4634191f5
commit
451923be3e
1 changed files with 13 additions and 4 deletions
|
@ -40,6 +40,9 @@ class HistoryEvent:
|
||||||
self.comment = interface.revision.get_comment() or None
|
self.comment = interface.revision.get_comment() or None
|
||||||
|
|
||||||
def is_similar(self, elt2):
|
def is_similar(self, elt2):
|
||||||
|
"""
|
||||||
|
Checks whether two events are similar enough to be merged
|
||||||
|
"""
|
||||||
return (
|
return (
|
||||||
elt2 is not None
|
elt2 is not None
|
||||||
and self.user.id == elt2.user.id
|
and self.user.id == elt2.user.id
|
||||||
|
@ -78,10 +81,13 @@ class MachineHistory:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __add_revision(self, user: User, machine: Version, interface: Version):
|
def __add_revision(self, user: User, machine: Version, interface: Version):
|
||||||
|
"""
|
||||||
|
Add a new revision to the chronological order
|
||||||
|
"""
|
||||||
evt = HistoryEvent(user, machine, interface)
|
evt = HistoryEvent(user, machine, interface)
|
||||||
evt.start_date = interface.revision.date_created
|
evt.start_date = interface.revision.date_created
|
||||||
|
|
||||||
# Try not to recreate events if unnecessary
|
# Try not to recreate events if it's unnecessary
|
||||||
if evt.is_similar(self.__last_evt):
|
if evt.is_similar(self.__last_evt):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -107,8 +113,12 @@ class MachineHistory:
|
||||||
Returns an iterable object with the Version objects
|
Returns an iterable object with the Version objects
|
||||||
of Interfaces with the given IP
|
of Interfaces with the given IP
|
||||||
"""
|
"""
|
||||||
# TODO: Deleted IpList
|
# TODO: What if ip list was deleted?
|
||||||
|
try:
|
||||||
ip_id = IpList.objects.get(ipv4=ip).id
|
ip_id = IpList.objects.get(ipv4=ip).id
|
||||||
|
except IpList.DoesNotExist:
|
||||||
|
return []
|
||||||
|
|
||||||
return filter(
|
return filter(
|
||||||
lambda x: x.field_dict["ipv4_id"] == ip_id,
|
lambda x: x.field_dict["ipv4_id"] == ip_id,
|
||||||
Version.objects.get_for_model(Interface).order_by("revision__date_created")
|
Version.objects.get_for_model(Interface).order_by("revision__date_created")
|
||||||
|
@ -119,7 +129,6 @@ class MachineHistory:
|
||||||
Returns an iterable object with the Version objects
|
Returns an iterable object with the Version objects
|
||||||
of Interfaces with the given MAC
|
of Interfaces with the given MAC
|
||||||
"""
|
"""
|
||||||
# TODO: What if IpList was deleted?
|
|
||||||
return filter(
|
return filter(
|
||||||
lambda x: str(x.field_dict["mac_address"]) == mac,
|
lambda x: str(x.field_dict["mac_address"]) == mac,
|
||||||
Version.objects.get_for_model(Interface).order_by("revision__date_created")
|
Version.objects.get_for_model(Interface).order_by("revision__date_created")
|
||||||
|
|
Loading…
Reference in a new issue