mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 20:33:11 +00:00
Make event logs filter more user friendly
This commit is contained in:
parent
c5b9715cd4
commit
82e74fc7a3
2 changed files with 68 additions and 14 deletions
|
@ -28,6 +28,7 @@ from re2o.base import get_input_formats_help_text
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
# Import all models in which there are classes to be filtered on
|
# Import all models in which there are classes to be filtered on
|
||||||
|
import cotisations.models
|
||||||
import machines.models
|
import machines.models
|
||||||
import preferences.models
|
import preferences.models
|
||||||
import tickets.models
|
import tickets.models
|
||||||
|
@ -35,7 +36,23 @@ import topologie.models
|
||||||
import users.models
|
import users.models
|
||||||
|
|
||||||
|
|
||||||
def get_classes(module):
|
CHOICES_ACTION_TYPE = (
|
||||||
|
("users", _("Users")),
|
||||||
|
("machines", _("Machines")),
|
||||||
|
("subscriptions", _("Subscription")),
|
||||||
|
("whitelists", _("Whitelists")),
|
||||||
|
("bans", _("Bans")),
|
||||||
|
("topology", _("Topology")),
|
||||||
|
("all", _("All")),
|
||||||
|
)
|
||||||
|
|
||||||
|
CHOICES_TYPE = (
|
||||||
|
("ip", _("IPv4")),
|
||||||
|
("mac", _("MAC address")),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def all_classes(module):
|
||||||
classes = []
|
classes = []
|
||||||
|
|
||||||
for name, obj in inspect.getmembers(module):
|
for name, obj in inspect.getmembers(module):
|
||||||
|
@ -45,18 +62,37 @@ def get_classes(module):
|
||||||
return classes
|
return classes
|
||||||
|
|
||||||
|
|
||||||
# Get the list of all imported classes
|
def classes_for_action_type(action_type):
|
||||||
modules = [machines.models, preferences.models, tickets.models, topologie.models, users.models]
|
"""Return the list of class names to be displayed for a
|
||||||
classes = sum([get_classes(m) for m in modules], [])
|
given actions type filter"""
|
||||||
|
if action_type == "users":
|
||||||
|
return [
|
||||||
|
users.models.User.__name__,
|
||||||
|
users.models.Adherent.__name__,
|
||||||
|
users.models.Club.__name__,
|
||||||
|
users.models.EMailAddress.__name__
|
||||||
|
]
|
||||||
|
|
||||||
CHOICES_ACTION_TYPE = [
|
if action_type == "machines":
|
||||||
(str(i), classes[i]) for i in range(len(classes))
|
return [
|
||||||
]
|
machines.models.Machine.__name__,
|
||||||
|
machines.models.Interface.__name__
|
||||||
|
]
|
||||||
|
|
||||||
CHOICES_TYPE = (
|
if action_type == "subscriptions":
|
||||||
("ip", _("IPv4")),
|
return all_classes(cotisations.models)
|
||||||
("mac", _("MAC address")),
|
|
||||||
)
|
if action_type == "whitelists":
|
||||||
|
return [users.models.Whitelist.__name__]
|
||||||
|
|
||||||
|
if action_type == "ban":
|
||||||
|
return [users.models.Ban.__name__]
|
||||||
|
|
||||||
|
if action_type == "topology":
|
||||||
|
return all_classes(topologie.models)
|
||||||
|
|
||||||
|
# "all" is a special case, just return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ActionsSearchForm(Form):
|
class ActionsSearchForm(Form):
|
||||||
|
|
|
@ -36,6 +36,7 @@ from users.models import Club
|
||||||
from topologie.models import Room
|
from topologie.models import Room
|
||||||
from topologie.models import Port
|
from topologie.models import Port
|
||||||
|
|
||||||
|
from .forms import classes_for_action_type
|
||||||
|
|
||||||
class ActionsSearch:
|
class ActionsSearch:
|
||||||
def get(self, params):
|
def get(self, params):
|
||||||
|
@ -46,7 +47,7 @@ class ActionsSearch:
|
||||||
user = params.get("u", None)
|
user = params.get("u", None)
|
||||||
start = params.get("s", None)
|
start = params.get("s", None)
|
||||||
end = params.get("e", None)
|
end = params.get("e", None)
|
||||||
actions_type = params.get("t", None)
|
action_types = params.get("t", None)
|
||||||
|
|
||||||
query = Q()
|
query = Q()
|
||||||
|
|
||||||
|
@ -59,8 +60,9 @@ class ActionsSearch:
|
||||||
if end:
|
if end:
|
||||||
query &= Q(date_created__leq=end)
|
query &= Q(date_created__leq=end)
|
||||||
|
|
||||||
if actions_type:
|
action_classes = self.classes_for_action_types(action_types)
|
||||||
query &= Q(version__content_type__in=actions_type)
|
if action_classes:
|
||||||
|
query &= Q(object__classname=action_classes)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
Revision.objects.all()
|
Revision.objects.all()
|
||||||
|
@ -69,6 +71,22 @@ class ActionsSearch:
|
||||||
.prefetch_related("version_set__object")
|
.prefetch_related("version_set__object")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def classes_for_action_types(self, action_types):
|
||||||
|
if action_types is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
classes = []
|
||||||
|
for action_type in action_types:
|
||||||
|
c = classes_for_action_type(action_type)
|
||||||
|
|
||||||
|
# Selecting "all" removes the filter
|
||||||
|
if c is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
classes += c
|
||||||
|
|
||||||
|
return classes
|
||||||
|
|
||||||
|
|
||||||
class MachineHistorySearchEvent:
|
class MachineHistorySearchEvent:
|
||||||
def __init__(self, user, machine, interface, start=None, end=None):
|
def __init__(self, user, machine, interface, start=None, end=None):
|
||||||
|
|
Loading…
Reference in a new issue