8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Add autocomplete on machine form fields

This commit is contained in:
chirac 2020-12-28 16:19:29 +01:00 committed by Gabriel Detraz
parent e4d4250dad
commit d00d7019c5
2 changed files with 96 additions and 1 deletions

View file

@ -40,7 +40,7 @@ from django.forms import ModelForm, Form
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from re2o.field_permissions import FieldPermissionFormMixin from re2o.field_permissions import FieldPermissionFormMixin
from re2o.mixins import FormRevMixin from re2o.mixins import FormRevMixin, AutocompleteModelMixin, AutocompleteMultipleModelMixin
from .models import ( from .models import (
Domain, Domain,
Machine, Machine,
@ -71,6 +71,11 @@ class EditMachineForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class Meta: class Meta:
model = Machine model = Machine
fields = "__all__" fields = "__all__"
widgets = {
"user": AutocompleteModelMixin(
url="/users/user-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -91,6 +96,17 @@ class EditInterfaceForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class Meta: class Meta:
model = Interface model = Interface
fields = ["machine", "machine_type", "ipv4", "mac_address", "details"] fields = ["machine", "machine_type", "ipv4", "mac_address", "details"]
widgets = {
"machine": AutocompleteModelMixin(
url="/machines/machine-autocomplete",
),
"machine_type": AutocompleteModelMixin(
url="/machines/machinetype-autocomplete",
),
"ipv4": AutocompleteModelMixin(
url="/machines/ipv4-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -139,6 +155,11 @@ class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class Meta: class Meta:
model = Domain model = Domain
fields = ["name", "extension", "ttl"] fields = ["name", "extension", "ttl"]
widgets = {
"extension": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -222,6 +243,14 @@ class IpTypeForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = IpType model = IpType
fields = "__all__" fields = "__all__"
widgets = {
"vlan": AutocompleteModelMixin(
url="/machines/vlan-autocomplete",
),
"extension": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -351,6 +380,14 @@ class MxForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Mx model = Mx
fields = ["zone", "priority", "name", "ttl"] fields = ["zone", "priority", "name", "ttl"]
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"name": AutocompleteModelMixin(
url="/machines/domain-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -386,6 +423,14 @@ class NsForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Ns model = Ns
fields = ["zone", "ns", "ttl"] fields = ["zone", "ns", "ttl"]
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"ns": AutocompleteModelMixin(
url="/machines/domain-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -419,6 +464,11 @@ class TxtForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Txt model = Txt
fields = "__all__" fields = "__all__"
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -449,6 +499,11 @@ class DNameForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = DName model = DName
fields = "__all__" fields = "__all__"
widgets = {
"zone": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -479,6 +534,14 @@ class SrvForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Srv model = Srv
fields = "__all__" fields = "__all__"
widgets = {
"extension": AutocompleteModelMixin(
url="/machines/extension-autocomplete",
),
"target": AutocompleteModelMixin(
url="/machines/domain-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -509,6 +572,14 @@ class NasForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Nas model = Nas
fields = "__all__" fields = "__all__"
widgets = {
"nas_type": AutocompleteModelMixin(
url="/machines/machinetype-autocomplete",
),
"machine_type": AutocompleteModelMixin(
url="/machines/machinetype-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -539,6 +610,11 @@ class RoleForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Role model = Role
fields = "__all__" fields = "__all__"
widgets = {
"servers": AutocompleteMultipleModelMixin(
url="/machines/interface-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -572,6 +648,11 @@ class ServiceForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Service model = Service
fields = "__all__" fields = "__all__"
widgets = {
"servers": AutocompleteMultipleModelMixin(
url="/machines/interface-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -656,6 +737,11 @@ class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
class Meta: class Meta:
model = Interface model = Interface
fields = ["port_lists"] fields = ["port_lists"]
widgets = {
"port_lists": AutocompleteMultipleModelMixin(
url="/machines/ouvertureportlist-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)

View file

@ -29,6 +29,7 @@ from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
from . import views from . import views
from . import views_autocomplete
urlpatterns = [ urlpatterns = [
url(r"^new_machine/(?P<userid>[0-9]+)$", views.new_machine, name="new-machine"), url(r"^new_machine/(?P<userid>[0-9]+)$", views.new_machine, name="new-machine"),
@ -153,4 +154,12 @@ urlpatterns = [
views.configure_ports, views.configure_ports,
name="port-config", name="port-config",
), ),
### Autocomplete Views
url(r'^vlan-autocomplete/$', views_autocomplete.VlanAutocomplete.as_view(), name='vlan-autocomplete',),
url(r'^interface-autocomplete/$', views_autocomplete.InterfaceAutocomplete.as_view(), name='interface-autocomplete',),
url(r'^machine-autocomplete/$', views_autocomplete.MachineAutocomplete.as_view(), name='machine-autocomplete',),
url(r'^machinetype-autocomplete/$', views_autocomplete.MachineTypeAutocomplete.as_view(), name='machinetype-autocomplete',),
url(r'^extension-autocomplete/$', views_autocomplete.ExtensionAutocomplete.as_view(), name='extension-autocomplete',),
url(r'^domain-autocomplete/$', views_autocomplete.DomainAutocomplete.as_view(), name='domain-autocomplete',),
url(r'^ouvertureportlist-autocomplete/$', views_autocomplete.OuverturePortListAutocomplete.as_view(), name='ouvertureportlist-autocomplete',),
] ]