From 290504be788401311d482e74559ea4abcf1bcded Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Thu, 23 Apr 2020 17:14:42 +0200 Subject: [PATCH] Rename MachineHistory to MachineHistorySearch --- logs/forms.py | 6 +++--- logs/models.py | 16 ++++++++-------- logs/views.py | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/logs/forms.py b/logs/forms.py index 3182ef17..07e421c9 100644 --- a/logs/forms.py +++ b/logs/forms.py @@ -18,7 +18,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""The forms used by the search app""" +"""The forms used by the machine search view""" from django import forms from django.forms import Form @@ -31,7 +31,7 @@ CHOICES_TYPE = ( ) -class MachineHistoryForm(Form): +class MachineHistorySearchForm(Form): """The form for a simple search""" q = forms.CharField( @@ -46,7 +46,7 @@ class MachineHistoryForm(Form): e = forms.DateField(required=False, label=_("End date")) def __init__(self, *args, **kwargs): - super(MachineHistoryForm, self).__init__(*args, **kwargs) + super(MachineHistorySearchForm, self).__init__(*args, **kwargs) self.fields["s"].help_text = get_input_formats_help_text( self.fields["s"].input_formats ) diff --git a/logs/models.py b/logs/models.py index 2066c77e..2161ba9e 100644 --- a/logs/models.py +++ b/logs/models.py @@ -34,7 +34,7 @@ from users.models import Club from topologie.models import Room -class MachineHistoryEvent: +class MachineHistorySearchEvent: def __init__(self, user, machine, interface, start=None, end=None): """ :param user: User, The user owning the maching at the time of the event @@ -76,7 +76,7 @@ class MachineHistoryEvent: ) -class MachineHistory: +class MachineHistorySearch: def __init__(self): self.events = [] self.__last_evt = None @@ -85,7 +85,7 @@ class MachineHistory: """ :param search: ip or mac to lookup :param params: dict built by the search view - :return: list or None, a list of MachineHistoryEvent + :return: list or None, a list of MachineHistorySearchEvent in reverse chronological order """ self.start = params.get("s", None) self.end = params.get("e", None) @@ -93,9 +93,9 @@ class MachineHistory: self.events = [] if search_type == "ip": - return self.__get_by_ip(search) + return self.__get_by_ip(search)[::-1] elif search_type == "mac": - return self.__get_by_mac(search) + return self.__get_by_mac(search)[::-1] return None @@ -106,7 +106,7 @@ class MachineHistory: :param machine: Version, the machine version related to the interface :param interface: Version, the interface targeted by this event """ - evt = MachineHistoryEvent(user, machine, interface) + evt = MachineHistorySearchEvent(user, machine, interface) evt.start_date = interface.revision.date_created # Try not to recreate events if it's unnecessary @@ -182,7 +182,7 @@ class MachineHistory: def __get_by_ip(self, ip): """ :param ip: str, The IP to lookup - :returns: list, a list of MachineHistoryEvent + :returns: list, a list of MachineHistorySearchEvent """ interfaces = self.__get_interfaces_for_ip(ip) @@ -198,7 +198,7 @@ class MachineHistory: def __get_by_mac(self, mac): """ :param mac: str, The MAC address to lookup - :returns: list, a list of MachineHistoryEvent + :returns: list, a list of MachineHistorySearchEvent """ interfaces = self.__get_interfaces_for_mac(mac) diff --git a/logs/views.py b/logs/views.py index 25ee7403..9aaa1e03 100644 --- a/logs/views.py +++ b/logs/views.py @@ -101,8 +101,8 @@ from re2o.utils import ( from re2o.base import re2o_paginator, SortTable from re2o.acl import can_view_all, can_view_app, can_edit_history, can_view -from .models import MachineHistory, UserHistory -from .forms import MachineHistoryForm +from .models import MachineHistorySearch, UserHistory +from .forms import MachineHistorySearchForm @login_required @@ -486,9 +486,9 @@ def stats_actions(request): def stats_search_machine_history(request): """View which displays the history of machines with the given une IP or MAC adresse""" - history_form = MachineHistoryForm(request.GET or None) + history_form = MachineHistorySearchForm(request.GET or None) if history_form.is_valid(): - history = MachineHistory() + history = MachineHistorySearch() events = history.get( history_form.cleaned_data.get("q", ""), history_form.cleaned_data