mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Rename MachineHistory to MachineHistorySearch
This commit is contained in:
parent
5b42ca8cbe
commit
290504be78
3 changed files with 15 additions and 15 deletions
|
@ -18,7 +18,7 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 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 import forms
|
||||||
from django.forms import Form
|
from django.forms import Form
|
||||||
|
@ -31,7 +31,7 @@ CHOICES_TYPE = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MachineHistoryForm(Form):
|
class MachineHistorySearchForm(Form):
|
||||||
"""The form for a simple search"""
|
"""The form for a simple search"""
|
||||||
|
|
||||||
q = forms.CharField(
|
q = forms.CharField(
|
||||||
|
@ -46,7 +46,7 @@ class MachineHistoryForm(Form):
|
||||||
e = forms.DateField(required=False, label=_("End date"))
|
e = forms.DateField(required=False, label=_("End date"))
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
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"].help_text = get_input_formats_help_text(
|
||||||
self.fields["s"].input_formats
|
self.fields["s"].input_formats
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,7 +34,7 @@ from users.models import Club
|
||||||
from topologie.models import Room
|
from topologie.models import Room
|
||||||
|
|
||||||
|
|
||||||
class MachineHistoryEvent:
|
class MachineHistorySearchEvent:
|
||||||
def __init__(self, user, machine, interface, start=None, end=None):
|
def __init__(self, user, machine, interface, start=None, end=None):
|
||||||
"""
|
"""
|
||||||
:param user: User, The user owning the maching at the time of the event
|
: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):
|
def __init__(self):
|
||||||
self.events = []
|
self.events = []
|
||||||
self.__last_evt = None
|
self.__last_evt = None
|
||||||
|
@ -85,7 +85,7 @@ class MachineHistory:
|
||||||
"""
|
"""
|
||||||
:param search: ip or mac to lookup
|
:param search: ip or mac to lookup
|
||||||
:param params: dict built by the search view
|
: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.start = params.get("s", None)
|
||||||
self.end = params.get("e", None)
|
self.end = params.get("e", None)
|
||||||
|
@ -93,9 +93,9 @@ class MachineHistory:
|
||||||
|
|
||||||
self.events = []
|
self.events = []
|
||||||
if search_type == "ip":
|
if search_type == "ip":
|
||||||
return self.__get_by_ip(search)
|
return self.__get_by_ip(search)[::-1]
|
||||||
elif search_type == "mac":
|
elif search_type == "mac":
|
||||||
return self.__get_by_mac(search)
|
return self.__get_by_mac(search)[::-1]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class MachineHistory:
|
||||||
:param machine: Version, the machine version related to the interface
|
:param machine: Version, the machine version related to the interface
|
||||||
:param interface: Version, the interface targeted by this event
|
: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
|
evt.start_date = interface.revision.date_created
|
||||||
|
|
||||||
# Try not to recreate events if it's unnecessary
|
# Try not to recreate events if it's unnecessary
|
||||||
|
@ -182,7 +182,7 @@ class MachineHistory:
|
||||||
def __get_by_ip(self, ip):
|
def __get_by_ip(self, ip):
|
||||||
"""
|
"""
|
||||||
:param ip: str, The IP to lookup
|
: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)
|
interfaces = self.__get_interfaces_for_ip(ip)
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ class MachineHistory:
|
||||||
def __get_by_mac(self, mac):
|
def __get_by_mac(self, mac):
|
||||||
"""
|
"""
|
||||||
:param mac: str, The MAC address to lookup
|
: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)
|
interfaces = self.__get_interfaces_for_mac(mac)
|
||||||
|
|
||||||
|
|
|
@ -101,8 +101,8 @@ from re2o.utils import (
|
||||||
from re2o.base import re2o_paginator, SortTable
|
from re2o.base import re2o_paginator, SortTable
|
||||||
from re2o.acl import can_view_all, can_view_app, can_edit_history, can_view
|
from re2o.acl import can_view_all, can_view_app, can_edit_history, can_view
|
||||||
|
|
||||||
from .models import MachineHistory, UserHistory
|
from .models import MachineHistorySearch, UserHistory
|
||||||
from .forms import MachineHistoryForm
|
from .forms import MachineHistorySearchForm
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -486,9 +486,9 @@ def stats_actions(request):
|
||||||
def stats_search_machine_history(request):
|
def stats_search_machine_history(request):
|
||||||
"""View which displays the history of machines with the given
|
"""View which displays the history of machines with the given
|
||||||
une IP or MAC adresse"""
|
une IP or MAC adresse"""
|
||||||
history_form = MachineHistoryForm(request.GET or None)
|
history_form = MachineHistorySearchForm(request.GET or None)
|
||||||
if history_form.is_valid():
|
if history_form.is_valid():
|
||||||
history = MachineHistory()
|
history = MachineHistorySearch()
|
||||||
events = history.get(
|
events = history.get(
|
||||||
history_form.cleaned_data.get("q", ""),
|
history_form.cleaned_data.get("q", ""),
|
||||||
history_form.cleaned_data
|
history_form.cleaned_data
|
||||||
|
|
Loading…
Reference in a new issue