Verified Commit eaf82732 authored by erdnaxe's avatar erdnaxe 🎇

Move DNAME and SRV in admin

parent 2bb6d53a
Pipeline #1107 passed with stage
in 2 minutes and 57 seconds
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2019-01-07 01:37+0100\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-03-31 16:09+0002\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language: fr_FR\n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-06-23 16:01+0200\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -10,22 +10,28 @@
The objects, fields and datastructures visible in the Django admin view
"""
from __future__ import unicode_literals
from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import (
DName,
MachineType,
Mx,
Nas,
Ns,
SOA,
Srv,
Txt,
Vlan,
)
@admin.register(DName)
class DNameAdmin(VersionAdmin):
"""Admin view of a DName object"""
list_display = ('zone', 'alias')
@admin.register(MachineType)
class MachineTypeAdmin(VersionAdmin):
"""Admin view of a MachineType object"""
......@@ -52,6 +58,13 @@ class NsAdmin(VersionAdmin):
list_display = ('zone', 'ns')
@admin.register(Srv)
class SrvAdmin(VersionAdmin):
"""Admin view of a Srv object"""
list_display = ('service', 'protocole', 'extension', 'ttl', 'priority',
'weight', 'port', 'target')
@admin.register(SOA)
class SOAAdmin(VersionAdmin):
"""Admin view of a SOA object"""
......
......@@ -33,14 +33,8 @@ from .models import (
IpList,
MachineType,
Extension,
SOA,
Mx,
Txt,
DName,
Ns,
Role,
Service,
Srv,
SshFp,
IpType,
OuverturePortList,
......@@ -257,64 +251,6 @@ class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
super(Ipv6ListForm, self).__init__(*args, prefix=prefix, **kwargs)
class DNameForm(FormRevMixin, ModelForm):
"""Add a DNAME entry for a zone"""
class Meta:
model = DName
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(DNameForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelDNameForm(FormRevMixin, Form):
"""Delete a set of DNAME entries"""
dnames = forms.ModelMultipleChoiceField(
queryset=Txt.objects.none(),
label=_("Current DNAME records"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelDNameForm, self).__init__(*args, **kwargs)
if instances:
self.fields['dnames'].queryset = instances
else:
self.fields['dnames'].queryset = DName.objects.all()
class SrvForm(FormRevMixin, ModelForm):
"""Ajout d'un srv pour une zone"""
class Meta:
model = Srv
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(SrvForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelSrvForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs Srv"""
srv = forms.ModelMultipleChoiceField(
queryset=Srv.objects.none(),
label=_("Current SRV records"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelSrvForm, self).__init__(*args, **kwargs)
if instances:
self.fields['srv'].queryset = instances
else:
self.fields['srv'].queryset = Srv.objects.all()
class RoleForm(FormRevMixin, ModelForm):
"""Add and edit role."""
......
This diff is collapsed.
......@@ -893,8 +893,15 @@ class Txt(RevMixin, AclMixin, models.Model):
class DName(RevMixin, AclMixin, models.Model):
"""A DNAME entry for the DNS."""
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
alias = models.CharField(max_length=255)
zone = models.ForeignKey(
'Extension',
on_delete=models.PROTECT,
verbose_name=_('zone'),
)
alias = models.CharField(
max_length=255,
verbose_name=_('record'),
)
class Meta:
verbose_name = _("DNAME record")
......@@ -914,7 +921,10 @@ class Srv(RevMixin, AclMixin, models.Model):
TCP = 'TCP'
UDP = 'UDP'
service = models.CharField(max_length=31)
service = models.CharField(
max_length=31,
verbose_name=_('service'),
)
protocole = models.CharField(
max_length=3,
choices=(
......@@ -922,33 +932,40 @@ class Srv(RevMixin, AclMixin, models.Model):
(UDP, 'UDP'),
),
default=TCP,
verbose_name=_('protocole'),
)
extension = models.ForeignKey(
'Extension',
on_delete=models.PROTECT,
verbose_name=_('extension'),
)
extension = models.ForeignKey('Extension', on_delete=models.PROTECT)
ttl = models.PositiveIntegerField(
default=172800, # 2 days
help_text=_("Time to Live")
verbose_name=_('time to live'),
)
priority = models.PositiveIntegerField(
default=0,
validators=[MaxValueValidator(65535)],
verbose_name=_('priority'),
help_text=_("Priority of the target server (positive integer value,"
" the lower it is, the more the server will be used if"
" available)")
" available)."),
)
weight = models.PositiveIntegerField(
default=0,
validators=[MaxValueValidator(65535)],
verbose_name=_('weight'),
help_text=_("Relative weight for records with the same priority"
" (integer value between 0 and 65535)")
" (integer value between 0 and 65535)."),
)
port = models.PositiveIntegerField(
validators=[MaxValueValidator(65535)],
help_text=_("TCP/UDP port")
verbose_name=_("TCP/UDP port"),
)
target = models.ForeignKey(
'Domain',
on_delete=models.PROTECT,
help_text=_("Target server")
verbose_name=_("target server"),
)
class Meta:
......
{% comment %}
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 © 2018 Charlie Jacomme
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.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Target zone" %}</th>
<th>{% trans "Record" %}</th>
<th></th>
</tr>
</thead>
{% for dname in dname_list %}
<tr>
<td>{{ dname.zone }}</td>
<td>{{ dname.dns_entry }}</td>
<td class="text-right">
{% can_edit dname %}
{% include 'buttons/edit.html' with href='machines:edit-dname' id=dname.id %}
{% acl_end %}
{% history_button dname %}
</td>
</tr>
{% endfor %}
</table>
{% comment %}
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 © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
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.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Service" %}</th>
<th>{% trans "Protocol" %}</th>
<th>{% trans "Extension" %}</th>
<th>{% trans "TTL" %}</th>
<th>{% trans "Priority" %}</th>
<th>{% trans "Weight" %}</th>
<th>{% trans "Port" %}</th>
<th>{% trans "Target" %}</th>
<th></th>
</tr>
</thead>
{% for srv in srv_list %}
<tr>
<td>{{ srv.service }}</td>
<td>{{ srv.protocole }}</td>
<td>{{ srv.extension }}</td>
<td>{{ srv.ttl }}</td>
<td>{{ srv.priority }}</td>
<td>{{ srv.weight }}</td>
<td>{{ srv.port }}</td>
<td>{{ srv.target }}</td>
<td class="text-right">
{% can_edit srv %}
{% include 'buttons/edit.html' with href='machines:edit-srv' id=srv.id %}
{% acl_end %}
{% history_button srv %}
</td>
</tr>
{% endfor %}
</table>
......@@ -40,26 +40,4 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="fa fa-trash"></i>{% trans " Delete one or several extensions" %}
</a>
{% include 'machines/aff_extension.html' with extension_list=extension_list %}
<h2>{% trans "List of DNAME records" %}</h2>
{% can_create DName %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-dname' %}">
<i class="fa fa-plus"></i> {% trans " Add a DNAME record" %}
</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-dname' %}">
<i class="fa fa-trash"></i> {% trans " Delete one or several DNAME records" %}
</a>
{% include 'machines/aff_dname.html' with dname_list=dname_list %}
<h2>{% trans "List of SRV records" %}</h2>
{% can_create Srv %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-srv' %}">
<i class="fa fa-plus"></i>{% trans " Add an SRV record" %}
</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-srv' %}">
<i class="fa fa-trash"></i>{% trans " Delete one or several SRV records" %}
</a>
{% include 'machines/aff_srv.html' with srv_list=srv_list %}
{% endblock %}
......@@ -42,12 +42,6 @@ urlpatterns = [
views.edit_extension,
name='edit-extension'),
url(r'^del_extension/$', views.del_extension, name='del-extension'),
url(r'^add_dname/$', views.add_dname, name='add-dname'),
url(r'^edit_dname/(?P<dnameid>[0-9]+)$', views.edit_dname, name='edit-dname'),
url(r'^del_dname/$', views.del_dname, name='del-dname'),
url(r'^add_srv/$', views.add_srv, name='add-srv'),
url(r'^edit_srv/(?P<srvid>[0-9]+)$', views.edit_srv, name='edit-srv'),
url(r'^del_srv/$', views.del_srv, name='del-srv'),
url(r'^new_sshfp/(?P<machineid>[0-9]+)$',
views.new_sshfp,
name='new-sshfp'),
......
......@@ -56,15 +56,11 @@ from .forms import (
DomainForm,
AliasForm,
DelAliasForm,
DNameForm,
DelDNameForm,
RoleForm,
DelRoleForm,
ServiceForm,
DelServiceForm,
SshFpForm,
SrvForm,
DelSrvForm,
Ipv6ListForm,
EditOuverturePortListForm,
EditOuverturePortConfigForm,
......@@ -620,121 +616,6 @@ def del_extension(request, instances):
)
@login_required
@can_create(DName)
def add_dname(request):
""" View used to add a DName object """
dname = DNameForm(request.POST or None)
if dname.is_valid():
dname.save()
messages.success(request, _("The DNAME record was created."))
return redirect(reverse('machines:index-extension'))
return form(
{'dnameform': dname, 'action_name': _("Create a DNAME record")},
'machines/machine.html',
request
)
@login_required
@can_edit(DName)
def edit_dname(request, dname_instance, **_kwargs):
""" View used to edit a DName object """
dname = DNameForm(request.POST or None, instance=dname_instance)
if dname.is_valid():
if dname.changed_data:
dname.save()
messages.success(request, _("The DNAME record was edited."))
return redirect(reverse('machines:index-extension'))
return form(
{'dnameform': dname, 'action_name': _("Edit")},
'machines/machine.html',
request
)
@login_required
@can_delete_set(DName)
def del_dname(request, instances):
""" View used to delete a DName object """
dname = DelDNameForm(request.POST or None, instances=instances)
if dname.is_valid():
dname_dels = dname.cleaned_data['dname']
for dname_del in dname_dels:
try:
dname_del.delete()
messages.success(request, _("The DNAME record was deleted."))
except ProtectedError:
messages.error(
request,
_("Error: the DNAME record %s can't be deleted.")
% dname_del
)
return redirect(reverse('machines:index-extension'))
return form(
{'dnameform': dname, 'action_name': _("Delete")},
'machines/machine.html',
request
)
@login_required
@can_create(Srv)
def add_srv(request):
""" View used to add a SRV object """
srv = SrvForm(request.POST or None)
if srv.is_valid():
srv.save()
messages.success(request, _("The SRV record was created."))
return redirect(reverse('machines:index-extension'))
return form(
{'srvform': srv, 'action_name': _("Create an SRV record")},
'machines/machine.html',
request
)
@login_required
@can_edit(Srv)
def edit_srv(request, srv_instance, **_kwargs):
""" View used to edit a SRV object """
srv = SrvForm(request.POST or None, instance=srv_instance)
if srv.is_valid():
if srv.changed_data:
srv.save()
messages.success(request, _("The SRV record was edited."))
return redirect(reverse('machines:1index-extension'))
return form(
{'srvform': srv, 'action_name': _("Edit")},
'machines/machine.html',
request
)
@login_required
@can_delete_set(Srv)
def del_srv(request, instances):
""" View used to delete a SRV object """
srv = DelSrvForm(request.POST or None, instances=instances)
if srv.is_valid():
srv_dels = srv.cleaned_data['srv']
for srv_del in srv_dels:
try:
srv_del.delete()
messages.success(request, _("The SRV record was deleted."))
except ProtectedError:
messages.error(
request,
(_("Error: the SRV record %s can't be deleted.") % srv_del)
)
return redirect(reverse('machines:index-extension'))
return form(
{'srvform': srv, 'action_name': _("Delete")},
'machines/machine.html',
request
)
@login_required
@can_create(Domain)
@can_edit(Interface)
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-06-24 15:54+0200\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-03-31 16:09+0002\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-06-24 20:10+0200\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-03-31 16:09+0002\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-06-25 14:53+0200\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"POT-Creation-Date: 2019-04-12 15:20+0200\n"
"PO-Revision-Date: 2018-06-27 23:35+0200\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
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