26 changed files with 329 additions and 492 deletions
-
20abonapp/locale/ru/LC_MESSAGES/django.po
-
51abonapp/migrations/0006_change_ip.py
-
46abonapp/models.py
-
55abonapp/templates/abonapp/editAbon.html
-
24abonapp/templates/abonapp/modal_add_lease.html
-
4abonapp/urls.py
-
155abonapp/views.py
-
6accounts_app/templatetags/acc_tags.py
-
27agent/commands/dhcp.py
-
8djing/lib/auth_backends.py
-
9djing/lib/mixins.py
-
1ip_pool/admin.py
-
33ip_pool/forms.py
-
37ip_pool/migrations/0003_add_leases_history_model.py
-
31ip_pool/models.py
-
44ip_pool/templates/ip_pool/ip_leases_list.html
-
4ip_pool/templates/ip_pool/net_edit.html
-
6ip_pool/templates/ip_pool/network_list.html
-
1ip_pool/urls.py
-
17ip_pool/views.py
-
36nas_app/nas_managers/core.py
-
66nas_app/nas_managers/mod_mikrotik.py
-
30nas_app/nas_managers/structs.py
-
10periodic.py
-
2searchapp/views.py
@ -0,0 +1,51 @@ |
|||
# Generated by Django 2.1 on 2018-10-10 16:11 |
|||
# from json import dump |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
TMP_FILE = '/tmp/migrate_ip.json' |
|||
|
|||
DUMP = [] |
|||
|
|||
|
|||
def backup_info(apps, _): |
|||
Abon = apps.get_model('abonapp', 'Abon') |
|||
abons = Abon.objects.annotate( |
|||
addr_count=models.Count('ip_addresses') |
|||
).filter(addr_count__gt=0).only('ip_addresses').iterator() |
|||
global DUMP |
|||
for abon in abons: |
|||
ip_addr = abon.ip_addresses.first() |
|||
DUMP.append({ |
|||
'pk': abon.pk, |
|||
'addr': ip_addr.ip |
|||
}) |
|||
# with open(TMP_FILE, 'w') as f: |
|||
# dump(r, f, indent=2) |
|||
|
|||
|
|||
def restore_ips(apps, _): |
|||
Abon = apps.get_model('abonapp', 'Abon') |
|||
for abon in DUMP: |
|||
Abon.objects.filter(pk=abon.get('pk')).update(ip_address=abon.get('addr')) |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('abonapp', '0005_current_tariff'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(backup_info), |
|||
migrations.RemoveField( |
|||
model_name='abon', |
|||
name='ip_addresses', |
|||
), |
|||
migrations.AddField( |
|||
model_name='abon', |
|||
name='ip_address', |
|||
field=models.GenericIPAddressField(blank=True, null=True, unique=True, verbose_name='Ip address'), |
|||
), |
|||
migrations.RunPython(restore_ips) |
|||
] |
|||
@ -1,24 +0,0 @@ |
|||
{% extends request.is_ajax|yesno:'nullcont.htm,abonapp/ext.htm' %} |
|||
{% load i18n bootstrap3 %} |
|||
{% block content %} |
|||
<form role="form" action="{% url 'abonapp:lease_add' group.id uname %}" method="post"> {% csrf_token %} |
|||
<div class="modal-header primary"> |
|||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
|||
<h4 class="modal-title"><span class="glyphicon glyphicon-compressed"></span>{% trans 'Add ip lease' %}</h4> |
|||
</div> |
|||
|
|||
<div class="modal-body"> |
|||
{% bootstrap_form form %} |
|||
|
|||
<div class="btn-group"> |
|||
<button type="submit" class="btn btn-success"> |
|||
<span class="glyphicon glyphicon-plus"></span> {% trans 'Add' %} |
|||
</button> |
|||
<button type="reset" class="btn btn-default"> |
|||
<span class="glyphicon glyphicon-remove-circle"></span> {% trans 'Reset' %} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
|
|||
</form> |
|||
{% endblock %} |
|||
@ -0,0 +1,9 @@ |
|||
from django.contrib.auth.mixins import AccessMixin |
|||
|
|||
|
|||
class OnlyAdminsMixin(AccessMixin): |
|||
"""Verify that the current user is admin.""" |
|||
def dispatch(self, request, *args, **kwargs): |
|||
if not request.user.is_admin: |
|||
return self.handle_no_permission() |
|||
return super().dispatch(request, *args, **kwargs) |
|||
@ -0,0 +1,37 @@ |
|||
# Generated by Django 2.1 on 2018-10-11 11:55 |
|||
|
|||
from django.db import migrations, models |
|||
import djing.fields |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('ip_pool', '0002_change_unique'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='LeasesHistory', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('ip', models.GenericIPAddressField(verbose_name='Ip address')), |
|||
('lease_time', models.DateTimeField(auto_now_add=True, verbose_name='Lease time')), |
|||
('mac_addr', djing.fields.MACAddressField(blank=True, integer=True, null=True, verbose_name='Mac address')), |
|||
], |
|||
options={ |
|||
'verbose_name': 'History lease', |
|||
'verbose_name_plural': 'Leases history', |
|||
'db_table': 'ip_pool_leases_history', |
|||
'ordering': ('-lease_time',), |
|||
}, |
|||
), |
|||
migrations.RemoveField( |
|||
model_name='ipleasemodel', |
|||
name='is_active', |
|||
), |
|||
migrations.RemoveField( |
|||
model_name='ipleasemodel', |
|||
name='is_dynamic', |
|||
), |
|||
] |
|||
@ -1,44 +0,0 @@ |
|||
{% extends 'base.html' %} |
|||
{% load i18n %} |
|||
|
|||
{% block breadcrumb %} |
|||
<ol class="breadcrumb"> |
|||
<li><span class="glyphicon glyphicon-home"></span></li> |
|||
<li><a href="{% url 'ip_pool:networks' %}">{% trans 'Ip pool' %}</a></li> |
|||
<li><a href="{% url 'ip_pool:net_edit' net.id %}">{{ net }}</a></li> |
|||
<li class="active">{% trans 'Ip leases list' %}</li> |
|||
</ol> |
|||
{% endblock %} |
|||
|
|||
{% block page-header %} |
|||
{% trans 'Ip leases list' %} |
|||
{% endblock %} |
|||
|
|||
{% block main %} |
|||
<div class="table-responsive"> |
|||
<table class="table table-striped table-bordered"> |
|||
<thead> |
|||
<tr> |
|||
<th class="col-sm-5">{% trans 'Ip' %}</th> |
|||
<th class="col-sm-3">{% trans 'Lease time' %}</th> |
|||
<th class="col-sm-3">{% trans 'Network' %}</th> |
|||
<th class="col-sm-1">{% trans 'Is dynamic' %}</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{% for ip in object_list %} |
|||
<tr> |
|||
<td>{{ ip.ip }}</td> |
|||
<td>{{ ip.lease_time|date:'j:n H:i:s' }}</td> |
|||
<td>{{ ip.get_network }}</td> |
|||
<td><input type="checkbox" {{ ip.is_dynamic|yesno:'checked,' }}></td> |
|||
</tr> |
|||
{% empty %} |
|||
<tr> |
|||
<td colspan="4">{% trans 'You have not any available dedicated ips in this network' %}</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
{% endblock %} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue