8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-05-18 16:43:11 +00:00
re2o/machines/views_autocomplete.py

106 lines
3 KiB
Python
Raw Normal View History

2020-12-28 15:21:33 +00:00
# -*- mode: python; coding: utf-8 -*-
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017-2020 Gabriel Détraz
# Copyright © 2017-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.
# App de gestion des users pour re2o
# Lara Kermarec, Gabriel Détraz, Lemesle Augustin
# Gplv2
"""
Django views autocomplete view
Here are defined the autocomplete class based view.
"""
from __future__ import unicode_literals
from django.db.models import Q, Value, CharField
from django.db.models.functions import Concat
from .models import (
Interface,
Machine,
Vlan,
MachineType,
2020-12-28 19:01:02 +00:00
IpType,
2020-12-28 15:21:33 +00:00
Extension,
Domain,
OuverturePortList,
2020-12-31 19:12:36 +00:00
IpList,
2020-12-28 15:21:33 +00:00
)
from re2o.views import AutocompleteViewMixin
2020-12-28 15:21:33 +00:00
class VlanAutocomplete(AutocompleteViewMixin):
obj_type = Vlan
class MachineAutocomplete(AutocompleteViewMixin):
obj_type = Machine
class MachineTypeAutocomplete(AutocompleteViewMixin):
obj_type = MachineType
2020-12-28 19:01:02 +00:00
class IpTypeAutocomplete(AutocompleteViewMixin):
obj_type = IpType
2020-12-28 15:21:33 +00:00
class ExtensionAutocomplete(AutocompleteViewMixin):
2020-12-31 19:12:36 +00:00
obj_type = Extension
2020-12-28 15:21:33 +00:00
class DomainAutocomplete(AutocompleteViewMixin):
2020-12-31 19:12:36 +00:00
obj_type = Domain
2020-12-28 15:21:33 +00:00
class OuverturePortListAutocomplete(AutocompleteViewMixin):
2020-12-31 19:12:36 +00:00
obj_type = OuverturePortList
2020-12-28 15:21:33 +00:00
class InterfaceAutocomplete(AutocompleteViewMixin):
obj_type = Interface
# Precision on search to add annotations so search behaves more like users expect it to
def filter_results(self):
2020-12-28 15:21:33 +00:00
if self.q:
self.query_set = self.query_set.filter(
2020-12-31 19:12:36 +00:00
Q(domain__name__icontains=self.q) | Q(machine__name__icontains=self.q)
2020-12-28 15:21:33 +00:00
)
class IpListAutocomplete(AutocompleteViewMixin):
obj_type = IpList
# Precision on search to add annotations so search behaves more like users expect it to
def filter_results(self):
2020-12-31 19:12:36 +00:00
machine_type = self.forwarded.get("machine_type", None)
self.query_set = self.query_set.filter(interface__isnull=True)
2021-01-01 23:27:31 +00:00
if machine_type:
self.query_set = self.query_set.filter(
2020-12-31 19:12:36 +00:00
ip_type__machinetype__id=machine_type
)
2021-01-01 23:27:31 +00:00
2020-12-31 19:12:36 +00:00
if self.q:
self.query_set = self.query_set.filter(Q(ipv4__startswith=self.q))