8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 04:43:10 +00:00
re2o/logs/forms.py

110 lines
3.4 KiB
Python
Raw Normal View History

2020-04-22 16:17:06 +00:00
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2020 Jean-Romain Garnier
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# 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 machine search view"""
2020-04-22 16:17:06 +00:00
from django import forms
from django.forms import Form
from django.utils.translation import ugettext_lazy as _
from re2o.base import get_input_formats_help_text
2020-04-24 13:37:05 +00:00
import inspect
# Import all models in which there are classes to be filtered on
import machines.models
import preferences.models
import tickets.models
import topologie.models
import users.models
def get_classes(module):
classes = []
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj):
2020-04-24 13:56:02 +00:00
classes.append(name)
2020-04-24 13:37:05 +00:00
return classes
# Get the list of all imported classes
modules = [machines.models, preferences.models, tickets.models, topologie.models, users.models]
2020-04-24 13:56:02 +00:00
classes = sum([get_classes(m) for m in modules], [])
2020-04-24 13:37:05 +00:00
2020-04-24 13:56:02 +00:00
CHOICES_ACTION_TYPE = [
(str(i), classes[i]) for i in range(len(classes))
]
2020-04-24 13:37:05 +00:00
2020-04-22 16:17:06 +00:00
CHOICES_TYPE = (
("ip", _("IPv4")),
2020-04-22 17:02:33 +00:00
("mac", _("MAC address")),
2020-04-22 16:17:06 +00:00
)
2020-04-24 13:37:05 +00:00
class ActionsSearchForm(Form):
2020-04-22 16:17:06 +00:00
"""The form for a simple search"""
2020-04-24 13:37:05 +00:00
u = forms.CharField(
label=_("Performed by"),
max_length=100,
required=False,
)
t = forms.MultipleChoiceField(
label=_("Action type"),
required=False,
widget=forms.CheckboxSelectMultiple,
choices=CHOICES_ACTION_TYPE,
initial=[i[0] for i in CHOICES_ACTION_TYPE],
)
s = forms.DateField(required=False, label=_("Start date"))
e = forms.DateField(required=False, label=_("End date"))
2020-04-22 16:17:06 +00:00
2020-04-24 13:37:05 +00:00
def __init__(self, *args, **kwargs):
2020-04-24 13:56:02 +00:00
super(ActionsSearchForm, self).__init__(*args, **kwargs)
2020-04-24 13:37:05 +00:00
self.fields["s"].help_text = get_input_formats_help_text(
self.fields["s"].input_formats
)
self.fields["e"].help_text = get_input_formats_help_text(
self.fields["e"].input_formats
)
class MachineHistorySearchForm(Form):
"""The form for a simple search"""
2020-04-22 16:17:06 +00:00
q = forms.CharField(
label=_("Search"),
max_length=100,
)
t = forms.CharField(
label=_("Search type"),
2020-04-22 16:32:56 +00:00
widget=forms.Select(choices=CHOICES_TYPE)
2020-04-22 16:17:06 +00:00
)
s = forms.DateField(required=False, label=_("Start date"))
e = forms.DateField(required=False, label=_("End date"))
def __init__(self, *args, **kwargs):
super(MachineHistorySearchForm, self).__init__(*args, **kwargs)
2020-04-22 16:17:06 +00:00
self.fields["s"].help_text = get_input_formats_help_text(
self.fields["s"].input_formats
)
self.fields["e"].help_text = get_input_formats_help_text(
self.fields["e"].input_formats
)