Commit b56cbe6a authored by chirac's avatar chirac Committed by root

Phase 2 modification domain

parent adf88afa
......@@ -19,7 +19,7 @@ from reversion.models import Version
from users.models import User, ServiceUser, Right, School, ListRight, ListShell, Ban, Whitelist
from cotisations.models import Facture, Vente, Article, Banque, Paiement, Cotisation
from machines.models import Machine, MachineType, IpType, Extension, Interface, Alias, IpList
from machines.models import Machine, MachineType, IpType, Extension, Interface, Domain, IpList
from topologie.models import Switch, Port, Room
from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER
......@@ -99,7 +99,7 @@ def stats_models(request):
'typeip' : [IpType.PRETTY_NAME, IpType.objects.count()],
'extension' : [Extension.PRETTY_NAME, Extension.objects.count()],
'interface' : [Interface.PRETTY_NAME, Interface.objects.count()],
'alias' : [Alias.PRETTY_NAME, Alias.objects.count()],
'alias' : [Domain.PRETTY_NAME, Domain.objects.exclude(cname=None).count()],
'iplist' : [IpList.PRETTY_NAME, IpList.objects.count()],
},
'Topologie' : {
......
......@@ -26,7 +26,7 @@ class IpListAdmin(VersionAdmin):
list_display = ('ipv4','ip_type')
class InterfaceAdmin(VersionAdmin):
list_display = ('machine','type','dns','mac_address','ipv4','details')
list_display = ('machine','type','mac_address','ipv4','details')
class DomainAdmin(VersionAdmin):
list_display = ('interface_parent', 'name', 'extension', 'cname')
......
from django.forms import ModelForm, Form, ValidationError
from django import forms
from .models import Alias, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, IpType
from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, IpType
from django.db.models import Q
class EditMachineForm(ModelForm):
......@@ -27,14 +27,13 @@ class EditInterfaceForm(ModelForm):
def __init__(self, *args, **kwargs):
super(EditInterfaceForm, self).__init__(*args, **kwargs)
self.fields['dns'].label = 'Nom dns de la machine'
self.fields['mac_address'].label = 'Adresse mac'
self.fields['type'].label = 'Type de machine'
self.fields['type'].empty_label = "Séléctionner un type de machine"
class AddInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
fields = ['ipv4','mac_address','dns','type','details']
fields = ['ipv4','mac_address','type','details']
def __init__(self, *args, **kwargs):
infra = kwargs.pop('infra')
......@@ -48,11 +47,11 @@ class AddInterfaceForm(EditInterfaceForm):
class NewInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
fields = ['mac_address','dns','type','details']
fields = ['mac_address','type','details']
class BaseEditInterfaceForm(EditInterfaceForm):
class Meta(EditInterfaceForm.Meta):
fields = ['ipv4','mac_address','dns','type','details']
fields = ['ipv4','mac_address','type','details']
def __init__(self, *args, **kwargs):
infra = kwargs.pop('infra')
......@@ -66,8 +65,8 @@ class BaseEditInterfaceForm(EditInterfaceForm):
class AliasForm(ModelForm):
class Meta:
model = Alias
fields = ['alias','extension']
model = Domain
fields = ['name','extension']
def __init__(self, *args, **kwargs):
infra = kwargs.pop('infra')
......@@ -76,16 +75,16 @@ class AliasForm(ModelForm):
self.fields['extension'].queryset = Extension.objects.filter(need_infra=False)
class DelAliasForm(ModelForm):
alias = forms.ModelMultipleChoiceField(queryset=Alias.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple)
alias = forms.ModelMultipleChoiceField(queryset=Domain.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple)
def __init__(self, *args, **kwargs):
interface = kwargs.pop('interface')
super(DelAliasForm, self).__init__(*args, **kwargs)
self.fields['alias'].queryset = Alias.objects.filter(interface_parent=interface)
self.fields['alias'].queryset = Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent=interface))
class Meta:
exclude = ['interface_parent', 'alias', 'extension']
model = Alias
exclude = ['interface_parent', 'name', 'extension', 'cname']
model = Domain
class MachineTypeForm(ModelForm):
class Meta:
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0039_auto_20161224_1732'),
]
operations = [
migrations.RemoveField(
model_name='interface',
name='dns',
),
]
......@@ -78,7 +78,6 @@ class Interface(models.Model):
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
details = models.CharField(max_length=255, blank=True)
dns = models.CharField(help_text="Obligatoire et unique, ne doit pas comporter de points", max_length=255, unique=True)
def is_active(self):
""" Renvoie si une interface doit avoir accès ou non """
......@@ -93,7 +92,11 @@ class Interface(models.Model):
self.mac_address = str(EUI(self.mac_address)) or None
def __str__(self):
return self.domain_set.all().first()
try:
domain = self.domain
except:
domain = None
return str(domain)
class Domain(models.Model):
PRETTY_NAME = "Domaine dns"
......@@ -109,7 +112,7 @@ class Domain(models.Model):
def clean(self):
if self.interface_parent and self.cname:
raise ValidationError("On ne peut créer à la fois A et CNAME")
if self.related==self:
if self.cname==self:
raise ValidationError("On ne peut créer un cname sur lui même")
def __str__(self):
......
#Augustin Lemesle
from rest_framework import serializers
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias, Mx, Ns
from machines.models import Interface, IpType, Extension, IpList, MachineType, Domain, Mx, Ns
class IpTypeField(serializers.RelatedField):
def to_representation(self, value):
......@@ -17,10 +17,14 @@ class IpListSerializer(serializers.ModelSerializer):
class InterfaceSerializer(serializers.ModelSerializer):
ipv4 = IpListSerializer(read_only=True)
mac_address = serializers.SerializerMethodField('get_macaddress')
dns = serializers.SerializerMethodField('get_dns')
class Meta:
model = Interface
fields = ('ipv4', 'mac_address', 'dns')
fields = ('ipv4', 'mac_address')
def get_dns(self, obj):
return obj.domain_set.all().first()
def get_macaddress(self, obj):
return str(obj.mac_address)
......@@ -74,16 +78,20 @@ class NsSerializer(serializers.ModelSerializer):
def get_interface_name(self, obj):
return obj.interface.dns + obj.interface.ipv4.ip_type.extension.name
class AliasSerializer(serializers.ModelSerializer):
class DomainSerializer(serializers.ModelSerializer):
interface_parent = serializers.SerializerMethodField('get_interface_name')
extension = serializers.SerializerMethodField('get_zone_name')
cname = serializers.SerializerMethodField('get_cname')
class Meta:
model = Alias
fields = ('interface_parent', 'alias', 'extension')
model = Domain
fields = ('interface_parent', 'name', 'extension', 'cname')
def get_zone_name(self, obj):
return obj.extension.name
def get_cname(self, obj):
return obj.cname.name + obj.cname.extension.name
def get_interface_name(self, obj):
return obj.interface_parent.dns + obj.interface_parent.ipv4.ip_type.extension.name
return obj.name + obj.extension.name
......@@ -28,13 +28,13 @@
</td>
{% endif %}
<td>
{% if interface.alias_set.all %}
{% if interface.domain.related_domain.all %}
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioninterface" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
{{ interface.dns }} <span class="caret"></span>
{{ interface.domain }} <span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="editioninterface">
{% for al in interface.alias_set.all %}
{% for al in interface.domain.related_domain.all %}
<li>
<a href="http://{{ al }}">
{{ al }}
......@@ -45,7 +45,7 @@
</ul>
</div>
{% else %}
{{ interface.dns }}
{{ interface.domain }}
{% endif %}
</td>
<td>{{ interface.type }}</td>
......
......@@ -19,6 +19,9 @@
{% if interfaceform %}
{% bootstrap_form interfaceform %}
{% endif %}
{% if domainform %}
{% bootstrap_form domainform %}
{% endif %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<br />
......
This diff is collapsed.
......@@ -55,7 +55,7 @@ def search_result(search, type, request):
if i == '0':
recherche['users_list'] = User.objects.filter((Q(room__name__icontains = search) | Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query1).order_by('state', 'surname')
if i == '1':
data = Interface.objects.filter(Q(machine__user__pseudo__icontains = search) | Q(machine__user__name__icontains = search) | Q(machine__user__surname__icontains = search) | Q(dns__icontains = search) | Q(mac_address__icontains = search) | Q(ipv4__ipv4__icontains = search))
data = Interface.objects.filter(Q(machine__user__pseudo__icontains = search) | Q(machine__user__name__icontains = search) | Q(machine__user__surname__icontains = search) | Q(mac_address__icontains = search) | Q(ipv4__ipv4__icontains = search))
for d in data:
recherche['machines_list'].append(d.machine)
if i == '2':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment