From 71798526a88b3b2689a60eb565b2d469935070ae Mon Sep 17 00:00:00 2001 From: http Date: Wed, 10 May 2017 11:19:05 +0300 Subject: [PATCH 01/17] =?UTF-8?q?-=20=D0=B1=D0=B0=D0=BB=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/templates/abonapp/modal_abonamount.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/abonapp/templates/abonapp/modal_abonamount.html b/abonapp/templates/abonapp/modal_abonamount.html index f2defbe..954c77d 100644 --- a/abonapp/templates/abonapp/modal_abonamount.html +++ b/abonapp/templates/abonapp/modal_abonamount.html @@ -12,8 +12,7 @@
- +

From 4054ffbdf617007aabef1816268ac87779a79c62 Mon Sep 17 00:00:00 2001 From: http Date: Wed, 10 May 2017 11:19:50 +0300 Subject: [PATCH 02/17] =?UTF-8?q?=D0=BD=D0=B5=20=D0=B1=D1=83=D0=B4=D1=83?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D1=81=D0=B2=D0=BE=D1=91=20=D0=B8=D0=BC=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clientsideapp/templates/clientsideapp/ext.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clientsideapp/templates/clientsideapp/ext.html b/clientsideapp/templates/clientsideapp/ext.html index 972972d..5e2b2bd 100644 --- a/clientsideapp/templates/clientsideapp/ext.html +++ b/clientsideapp/templates/clientsideapp/ext.html @@ -11,9 +11,7 @@ - - - +/head>
+ {% if charts_data %} + {% else %} +

Данные не переданы

+ {% endif %}
diff --git a/abonapp/views.py b/abonapp/views.py index 823b248..c9d81c5 100644 --- a/abonapp/views.py +++ b/abonapp/views.py @@ -745,7 +745,7 @@ def charts(request, gid, uid): return render(request, 'abonapp/charts.html', { 'abon_group': abongroup, 'abon': abon, - 'charts_data': ','.join(charts_data), + 'charts_data': ','.join(charts_data) if charts_data is not None else None, 'time_min': int(midnight.timestamp()), 'time_max': int((midnight + timedelta(hours=23, minutes=59, seconds=59)).timestamp()) }) From 14a41b01cf3c4b7a580df3d8ce70d8bbe3fc03ca Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:07:59 +0300 Subject: [PATCH 04/17] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/abonapp/models.py b/abonapp/models.py index 16bdd3e..01823b0 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -6,10 +6,10 @@ from django.db import models from django.core import validators from django.utils.translation import ugettext as _ from agent import Transmitter, AbonStruct, TariffStruct, NasFailedResult, NasNetworkError -from ip_pool.models import IpPoolItem from tariff_app.models import Tariff from accounts_app.models import UserProfile from .fields import MACAddressField +from mydefs import MyGenericIPAddressField class LogicError(Exception): @@ -207,7 +207,7 @@ class Abon(UserProfile): current_tariffs = models.ManyToManyField(Tariff, through=AbonTariff) group = models.ForeignKey(AbonGroup, models.SET_NULL, blank=True, null=True) ballance = models.FloatField(default=0.0) - ip_address = models.OneToOneField(IpPoolItem, on_delete=models.SET_NULL, null=True, blank=True) + ip_address = MyGenericIPAddressField(blank=True, null=True) description = models.TextField(null=True, blank=True) street = models.ForeignKey(AbonStreet, on_delete=models.SET_NULL, null=True, blank=True) house = models.CharField(max_length=12, null=True, blank=True) @@ -331,6 +331,13 @@ class Abon(UserProfile): agent_trf = TariffStruct() return AbonStruct(self.pk, user_ip, agent_trf, bool(self.is_active)) + def save(self, *args, **kwargs): + # проверяем не-ли у кого такого-же ip + if Abon.objects.filter(ip_address=self.ip_address).count() > 0: + self.is_bad_ip = True + raise LogicError(_('Ip address already exist')) + super(Abon, self).save(*args, **kwargs) + class AbonDevice(models.Model): abon = models.ForeignKey(Abon) From 1390de1dae1a875f7b823b060466448a3e8bf026 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:08:17 +0300 Subject: [PATCH 05/17] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/views.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/abonapp/views.py b/abonapp/views.py index c9d81c5..c25a18e 100644 --- a/abonapp/views.py +++ b/abonapp/views.py @@ -15,7 +15,6 @@ from tariff_app.models import Tariff from agent import NasFailedResult, Transmitter, NasNetworkError from . import forms from . import models -from ip_pool.models import IpPoolItem import mydefs from devapp.models import Device from datetime import datetime @@ -260,14 +259,7 @@ def abonhome(request, gid, uid): if abon.opt82 is None: ip_str = request.POST.get('ip') if ip_str: - try: - ip = IpPoolItem.objects.get(ip=ip_str) - abon.ip_address = ip - except MultipleObjectsReturned: - ips = models.IpPoolItem.objects.filter(ip=ip_str) - one_ip = ips[0] - models.IpPoolItem.objects.filter(pk__in=[ip.pk for ip in ips if ip != one_ip]).delete() - abon.ip_address = one_ip + abon.ip_address = ip_str else: abon.ip_address = None frm.save() @@ -278,14 +270,13 @@ def abonhome(request, gid, uid): passw = models.AbonRawPassword.objects.get(account=abon).passw_text frm = forms.AbonForm(instance=abon, initial={'password': passw}) abon_device = models.AbonDevice.objects.get(abon=abon) - except IntegrityError as e: - messages.error(request, _('Ip address already exist. %s') % e) + except models.LogicError as e: + messages.error(request, e) + passw = models.AbonRawPassword.objects.get(account=abon).passw_text frm = forms.AbonForm(instance=abon, initial={'password': passw}) except (NasFailedResult, NasNetworkError) as e: messages.error(request, e) - except IpPoolItem.DoesNotExist: - messages.error(request, _('Ip address not found')) except models.AbonRawPassword.DoesNotExist: messages.warning(request, _('User has not have password, and cannot login')) except models.AbonDevice.DoesNotExist: @@ -300,6 +291,7 @@ def abonhome(request, gid, uid): 'abon': abon, 'abon_group': abon_group, 'ip': abon.ip_address, + 'is_bad_ip': getattr(abon, 'is_bad_ip', False), 'tech_form': forms.Opt82Form(instance=abon.opt82), 'device': abon_device.device if abon_device is not None else None }) From 0499debc3dfac3cf5ebb8e3c3edf58620091b5b9 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:08:27 +0300 Subject: [PATCH 06/17] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/locale/ru/LC_MESSAGES/django.po | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/abonapp/locale/ru/LC_MESSAGES/django.po b/abonapp/locale/ru/LC_MESSAGES/django.po index c3cf66e..f6dffff 100644 --- a/abonapp/locale/ru/LC_MESSAGES/django.po +++ b/abonapp/locale/ru/LC_MESSAGES/django.po @@ -619,14 +619,8 @@ msgstr "Абонент успешно изменён" #: abonapp/views.py:258 #, python-format -msgid "Ip address already exist. %s" -msgstr "" -"Проверте введённые вами значения, скорее всего такой ip уже у кого-то есть. " -"А вообще: %s" - -#: abonapp/views.py:266 -msgid "Ip address not found" -msgstr "Указанный вами ip отсутствует в ip pool" +msgid "Ip address already exist" +msgstr "Такой ip уже у кого-то есть" #: abonapp/views.py:268 msgid "User has not have password, and cannot login" From 7939d5fd9076857e996ba3e661563eab0be59aef Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:16:16 +0300 Subject: [PATCH 07/17] fix bug --- abonapp/templates/abonapp/editAbon.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abonapp/templates/abonapp/editAbon.html b/abonapp/templates/abonapp/editAbon.html index 42ba153..5f311fb 100644 --- a/abonapp/templates/abonapp/editAbon.html +++ b/abonapp/templates/abonapp/editAbon.html @@ -32,7 +32,7 @@ -
+
From 8667518d4c15ebf1d2050690b4dba3968207eca7 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:16:38 +0300 Subject: [PATCH 08/17] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=BE=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/migrations/0019_abon_ip_address.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 abonapp/migrations/0019_abon_ip_address.py diff --git a/abonapp/migrations/0019_abon_ip_address.py b/abonapp/migrations/0019_abon_ip_address.py new file mode 100644 index 0000000..96c2613 --- /dev/null +++ b/abonapp/migrations/0019_abon_ip_address.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2017-05-10 23:17 +from __future__ import unicode_literals + +from django.db import migrations +import mydefs + + +class Migration(migrations.Migration): + + dependencies = [ + ('abonapp', '0018_auto_20170418_1236'), + ] + + operations = [ + migrations.AddField( + model_name='abon', + name='ip_address', + field=mydefs.MyGenericIPAddressField(blank=True, max_length=8, null=True, protocol='ipv4'), + ), + ] From eeef5aa1fd8abb281059142b816f618020b201d1 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:17:00 +0300 Subject: [PATCH 09/17] =?UTF-8?q?=D0=98=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dhcp_lever.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/dhcp_lever.py b/dhcp_lever.py index 9dcc4df..f499cc5 100755 --- a/dhcp_lever.py +++ b/dhcp_lever.py @@ -8,7 +8,6 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djing.settings") django.setup() from agent import NasFailedResult, NasNetworkError from abonapp.models import Abon, Opt82 -from ip_pool.models import IpPoolItem def die(text): @@ -27,17 +26,6 @@ def get_82_opts(switch_mac, switch_port): return opt82 -def get_or_create_pool_item(ip): - try: - ip_item = IpPoolItem.objects.get(ip=ip) - except IpPoolItem.DoesNotExist: - ip_item = IpPoolItem.objects.create(ip=ip) - except MultipleObjectsReturned: - IpPoolItem.objects.filter(ip=ip)[1:].delete() - return get_or_create_pool_item(ip) - return ip_item - - def dhcp_commit(client_ip, client_mac, switch_mac, switch_port): opt82 = get_82_opts(switch_mac, switch_port) if opt82 is None: @@ -45,7 +33,7 @@ def dhcp_commit(client_ip, client_mac, switch_mac, switch_port): return try: abon = Abon.objects.get(opt82=opt82) - abon.ip_address = get_or_create_pool_item(client_ip) + abon.ip_address = client_ip abon.is_dhcp = True abon.save(update_fields=['ip_address']) print(_('Ip address update for %s successfull') % abon.get_short_name()) @@ -55,13 +43,10 @@ def dhcp_commit(client_ip, client_mac, switch_mac, switch_port): def dhcp_expiry(client_ip): try: - ip_item = IpPoolItem.objects.get(ip=client_ip) - abon = Abon.objects.get(ip_address=ip_item) + abon = Abon.objects.get(ip_address=client_ip) abon.ip_address = None abon.is_dhcp = True abon.save(update_fields=['ip_address']) - except IpPoolItem.DoesNotExist: - pass except Abon.DoesNotExist: pass From 88cae90e89cc062ee68d3e70f545619211a5df8d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:17:26 +0300 Subject: [PATCH 10/17] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- djing/settings_example.py | 1 - 1 file changed, 1 deletion(-) diff --git a/djing/settings_example.py b/djing/settings_example.py index 01a6f7a..4e8660d 100644 --- a/djing/settings_example.py +++ b/djing/settings_example.py @@ -30,7 +30,6 @@ INSTALLED_APPS = [ 'photo_app', 'abonapp', 'tariff_app', - 'ip_pool', 'searchapp', 'devapp', 'mapapp', From 50167e049d988ef487ff65a06ceabeaa629d03a7 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:18:17 +0300 Subject: [PATCH 11/17] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- djing/urls.py | 1 - searchapp/views.py | 9 ++------- templates/base.html | 7 ------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/djing/urls.py b/djing/urls.py index a5dbe96..43bf88b 100644 --- a/djing/urls.py +++ b/djing/urls.py @@ -10,7 +10,6 @@ urlpatterns = [ url(r'^accounts/', include('accounts_app.urls', namespace='acc_app')), url(r'^abons/', include('abonapp.urls', namespace='abonapp')), url(r'^tarifs/', include('tariff_app.urls', namespace='tarifs')), - url(r'^ip_pool/', include('ip_pool.urls', namespace='ip_pool')), url(r'^search/', include('searchapp.urls', namespace='searchapp')), url(r'^dev/', include('devapp.urls', namespace='devapp')), url(r'^map/', include('mapapp.urls', namespace='mapapp')), diff --git a/searchapp/views.py b/searchapp/views.py index 5c01d63..260c4fb 100644 --- a/searchapp/views.py +++ b/searchapp/views.py @@ -1,10 +1,8 @@ import re - from django.db.models import Q from django.shortcuts import render from django.utils.html import escape - -from abonapp.models import Abon, IpPoolItem +from abonapp.models import Abon def replace_without_case(orig, old, new): @@ -15,10 +13,7 @@ def home(request): s = request.GET.get('s') if s: - ips = IpPoolItem.objects.filter(ip=s) - query = Q(fio__icontains=s) | Q(username__icontains=s) | Q(telephone__icontains=s) - if ips.count() > 0: - query |= Q(ip_address__in=ips) + query = Q(fio__icontains=s) | Q(username__icontains=s) | Q(telephone__icontains=s) | Q(ip_address=s) abons = Abon.objects.filter(query) else: abons = [] diff --git a/templates/base.html b/templates/base.html index 2532183..215217c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -63,13 +63,6 @@ внутренняя переписка - - {% url 'ip_pool:home' as ip_pool_home %} - - - ip пул - - {% url 'devapp:group_list' as devapp_groups %} From cfb36a307ba8fef291139675ae70bff1d5d32bdb Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:18:39 +0300 Subject: [PATCH 12/17] =?UTF-8?q?=D0=92=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=B5?= =?UTF-8?q?=D1=89=D1=91=20=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B7=D0=BD=D0=B0=D1=87=D1=91=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/message_block.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates/message_block.html b/templates/message_block.html index 4878cdb..037077b 100644 --- a/templates/message_block.html +++ b/templates/message_block.html @@ -3,12 +3,16 @@ {% if message.tags == 'error' %}
+ {% elif message.tags == 'warning' %}
+ {% elif message.tags == 'success' %}
+ {% elif message.tags == 'info' %}
+ {% endif %} From 5e1c6d960a637587b7769d363d8fc317c1a42f40 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:28:57 +0300 Subject: [PATCH 13/17] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=B2=D1=8F=D0=B7=D1=8C=20=D1=81=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/migrations/0001_initial.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/abonapp/migrations/0001_initial.py b/abonapp/migrations/0001_initial.py index 1e95fb1..7b1368f 100644 --- a/abonapp/migrations/0001_initial.py +++ b/abonapp/migrations/0001_initial.py @@ -13,7 +13,6 @@ class Migration(migrations.Migration): dependencies = [ ('accounts_app', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('ip_pool', '0001_initial'), ('tariff_app', '0001_initial'), ] @@ -102,12 +101,6 @@ class Migration(migrations.Migration): field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='abonapp.AbonGroup'), ), - migrations.AddField( - model_name='abon', - name='ip_address', - field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, - to='ip_pool.IpPoolItem'), - ), migrations.AlterUniqueTogether( name='abontariff', unique_together={('abon', 'tariff', 'tariff_priority')}, From 863008381e6b3b6c87d6752dcb8a8a15261d3661 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:29:22 +0300 Subject: [PATCH 14/17] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20ip?= =?UTF-8?q?=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ip_pool/__init__.py | 1 - ip_pool/admin.py | 6 -- ip_pool/apps.py | 6 -- ip_pool/forms.py | 22 ------- ip_pool/migrations/0001_initial.py | 23 ------- ip_pool/migrations/__init__.py | 0 ip_pool/models.py | 59 ------------------ ip_pool/templates/ip_pool/add_pool.html | 48 --------------- ip_pool/templates/ip_pool/index.html | 73 ---------------------- ip_pool/templates/ip_pool/ips.html | 59 ------------------ ip_pool/urls.py | 15 ----- ip_pool/views.py | 81 ------------------------- 12 files changed, 393 deletions(-) delete mode 100644 ip_pool/__init__.py delete mode 100644 ip_pool/admin.py delete mode 100644 ip_pool/apps.py delete mode 100644 ip_pool/forms.py delete mode 100644 ip_pool/migrations/0001_initial.py delete mode 100644 ip_pool/migrations/__init__.py delete mode 100644 ip_pool/models.py delete mode 100644 ip_pool/templates/ip_pool/add_pool.html delete mode 100644 ip_pool/templates/ip_pool/index.html delete mode 100644 ip_pool/templates/ip_pool/ips.html delete mode 100644 ip_pool/urls.py delete mode 100644 ip_pool/views.py diff --git a/ip_pool/__init__.py b/ip_pool/__init__.py deleted file mode 100644 index 8c4aa32..0000000 --- a/ip_pool/__init__.py +++ /dev/null @@ -1 +0,0 @@ -default_app_config = 'ip_pool.apps.IpPoolConfig' diff --git a/ip_pool/admin.py b/ip_pool/admin.py deleted file mode 100644 index e98d823..0000000 --- a/ip_pool/admin.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.contrib import admin - -from . import models - - -admin.site.register(models.IpPoolItem) diff --git a/ip_pool/apps.py b/ip_pool/apps.py deleted file mode 100644 index 8b8d232..0000000 --- a/ip_pool/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class IpPoolConfig(AppConfig): - name = 'ip_pool' - verbose_name = "Ip pool" diff --git a/ip_pool/forms.py b/ip_pool/forms.py deleted file mode 100644 index 0e6f43f..0000000 --- a/ip_pool/forms.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -from django import forms - -from mydefs import ip_addr_regex - - -class PoolForm(forms.Form): - start_ip = forms.GenericIPAddressField(protocol='ipv4', widget=forms.TextInput(attrs={ - 'pattern': ip_addr_regex, - 'placeholder': '127.0.0.1', - 'id': 'start_ip', - 'class': 'form-control', - 'required': '' - }), required=True) - - end_ip = forms.GenericIPAddressField(protocol='ipv4', widget=forms.TextInput(attrs={ - 'pattern': ip_addr_regex, - 'placeholder': '127.0.0.1', - 'id': 'end_ip', - 'class': 'form-control', - 'required': '' - }), required=True) diff --git a/ip_pool/migrations/0001_initial.py b/ip_pool/migrations/0001_initial.py deleted file mode 100644 index fa5fcad..0000000 --- a/ip_pool/migrations/0001_initial.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-06-28 23:51 - -from django.db import migrations, models - -import mydefs - - -class Migration(migrations.Migration): - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='IpPoolItem', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('ip', mydefs.MyGenericIPAddressField(max_length=8, protocol='ipv4')), - ], - ), - ] diff --git a/ip_pool/migrations/__init__.py b/ip_pool/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ip_pool/models.py b/ip_pool/models.py deleted file mode 100644 index d76e56b..0000000 --- a/ip_pool/models.py +++ /dev/null @@ -1,59 +0,0 @@ -from django.db import models, connection - -from mydefs import ip2int, MyGenericIPAddressField - - -class IpPoolItemManager(models.Manager): - def get_pools(self): - ips = self.raw(r'SELECT id, ip FROM ip_pool_ippoolitem ORDER BY id') - ips_len = len(list(ips)) - if ips_len < 1: - return - last_dg = ip2int(ips[0].ip) - start_pool = last_dg - res = list() - cnt = 0 - for ip in ips: - ipnt = ip2int(ip.ip) - if ipnt > last_dg + 1 or ipnt < last_dg - 1: - res.append((start_pool, last_dg, cnt)) - start_pool = ipnt - cnt = 0 - last_dg = ipnt - cnt += 1 - res.append((start_pool, last_dg, cnt)) - return res - - def add_pool(self, start_ip, end_ip): - start_ip = ip2int(start_ip) - end_ip = ip2int(end_ip) - - if (end_ip - start_ip) > 5000: - raise Exception('Not add over 5000 ip\'s') - - sql_strs = [r"(%d)" % tip for tip in range(start_ip, end_ip + 1)] - sql = r'INSERT INTO ip_pool_ippoolitem (ip) VALUES %s' % r",".join(sql_strs) - - cursor = connection.cursor() - cursor.execute(sql) - - def get_free_ip(self): - sql = r'SELECT ip_pool_ippoolitem.id as id, ip_pool_ippoolitem.ip as ip FROM ip_pool_ippoolitem ' \ - r'LEFT JOIN abonent ON abonent.ip_address_id = ip_pool_ippoolitem.id WHERE ' \ - r'abonent.ip_address_id IS NULL LIMIT 1' - - rs = self.raw(sql) - rs_len = len(list(rs)) - return None if rs_len is 0 else rs[0] - - -class IpPoolItem(models.Model): - ip = MyGenericIPAddressField() - - objects = IpPoolItemManager() - - def int_ip(self): - return ip2int(self.ip) - - def __str__(self): - return self.ip diff --git a/ip_pool/templates/ip_pool/add_pool.html b/ip_pool/templates/ip_pool/add_pool.html deleted file mode 100644 index 3f0fe69..0000000 --- a/ip_pool/templates/ip_pool/add_pool.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends 'base.html' %} -{% block main %} - - - - - {% include 'message_block.html' %} - -
-
-

Добавить IP пул

-
-
- -
{% csrf_token %} -
- - -
- - {{ form.start_ip }}{{ form.start_ip.errors }} -
-
-
- - -
- - {{ form.end_ip }}{{ form.end_ip.errors }} -
-
-
- - -
-
-
-
- -{% endblock %} \ No newline at end of file diff --git a/ip_pool/templates/ip_pool/index.html b/ip_pool/templates/ip_pool/index.html deleted file mode 100644 index 01e6a44..0000000 --- a/ip_pool/templates/ip_pool/index.html +++ /dev/null @@ -1,73 +0,0 @@ -{% extends 'base.html' %} -{% block main %} - - - - - {% include 'message_block.html' %} - -

Пулы ip адресов

-
- - - - - - - - - - - - {% for pl in pools %} - - - - - - - {% empty %} - - - - {% endfor %} - - - {% if perms.ip_pool.add_ippoolitem %} - - - - - - {% endif %} - -
Начальный IPКонечный IPКоличествоРед.Уд.
{{ pl.0 }}{{ pl.1 }}{{ pl.2 }} - - - - - - {% if perms.ip_pool.delete_ippoolitem %} - - - - {% endif %} - -
Нет ни одного пула зарезервированных ip адресов. - {% if perms.ip_pool.add_ippoolitem %} - Создать - {% endif %} -
- - - -
-
- - {% include 'toolbar_page.html' with pag=pools %} - -{% endblock %} \ No newline at end of file diff --git a/ip_pool/templates/ip_pool/ips.html b/ip_pool/templates/ip_pool/ips.html deleted file mode 100644 index bc12475..0000000 --- a/ip_pool/templates/ip_pool/ips.html +++ /dev/null @@ -1,59 +0,0 @@ -{% extends 'base.html' %} -{% block main %} - - - - - -

История абонента

-
- - - - - - - - - - - {% for pi in pool_ips %} - - - - - - - {% empty %} - - - - {% endfor %} - -
IdIpКлиентУд.
{{ pi.id }}{{ pi.ip }}{% if pi.abon %} - {{ pi.abon.username }} - {% else %}---{% endif %} - - {% if pi.abon %} - - {% elif perms.ip_pool.delete_ippoolitem %} - - - - {% endif %} -
Нет ни одного пула зарезервированных ip адресов. - {% if perms.ip_pool.add_ippoolitem %} - Создать - {% endif %} -
-
- - {% include 'toolbar_page.html' with pag=pool_ips %} - -{% endblock %} \ No newline at end of file diff --git a/ip_pool/urls.py b/ip_pool/urls.py deleted file mode 100644 index de54c47..0000000 --- a/ip_pool/urls.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding:utf-8 -*- -from django.conf.urls import url - -from . import views - - -urlpatterns = [ - - url(r'^$', views.home, name='home'), - url(r'^range$', views.ips, name='ips'), - url(r'^del$', views.del_pool, name='ips_del'), - url(r'^add$', views.add_pool, name='add'), - - url(r'^delip$', views.delip, name='del_ip') -] diff --git a/ip_pool/views.py b/ip_pool/views.py deleted file mode 100644 index 001bf03..0000000 --- a/ip_pool/views.py +++ /dev/null @@ -1,81 +0,0 @@ -# -*- coding: utf-8 -*- -from django.contrib.auth.decorators import login_required, permission_required -from django.shortcuts import render, redirect, get_object_or_404 -from django.contrib import messages - -from .forms import PoolForm -from .models import IpPoolItem -import mydefs - - -@login_required -@mydefs.only_admins -def home(request): - pools = IpPoolItem.objects.get_pools() - - if pools: - pools = [(mydefs.int2ip(ip[0]), mydefs.int2ip(ip[1]), ip[2]) for ip in pools] - pools = mydefs.pag_mn(request, pools) - - return render(request, 'ip_pool/index.html', { - 'pools': pools - }) - - -@login_required -@mydefs.only_admins -def ips(request): - ip_start = request.GET.get('ips') - ip_end = request.GET.get('ipe') - - pool_ips = IpPoolItem.objects.filter(ip__gte=ip_start) - pool_ips = pool_ips.filter(ip__lte=ip_end) - - pool_ips = mydefs.pag_mn(request, pool_ips) - - return render(request, 'ip_pool/ips.html', { - 'pool_ips': pool_ips, - 'ips': ip_start, - 'ipe': ip_end - }) - - -@login_required -@permission_required('ip_pool.delete_ippoolitem') -def del_pool(request): - ip_start = request.GET.get('ips') - ip_end = request.GET.get('ipe') - - pool_ips = IpPoolItem.objects.filter(ip__gte=ip_start) - pool_ips = pool_ips.filter(ip__lte=ip_end) - pool_ips = pool_ips.filter() - - pool_ips.delete() - - return mydefs.res_success(request, 'ip_pool:home') - - -@login_required -@permission_required('ip_pool.add_ippoolitem') -def add_pool(request): - if request.method == 'POST': - frm = PoolForm(request.POST) - if frm.is_valid(): - cd = frm.cleaned_data - IpPoolItem.objects.add_pool(cd['start_ip'], cd['end_ip']) - return redirect('ip_pool:home') - else: - messages.error(request, 'Исправьте ошибки') - else: - frm = PoolForm() - return render(request, 'ip_pool/add_pool.html', { - 'form': frm - }) - - -@login_required -@permission_required('ip_pool.delete_ippoolitem') -def delip(request): - ipid = request.GET.get('id') - get_object_or_404(IpPoolItem, id=ipid).delete() - return mydefs.res_success(request, 'ip_pool:home') From 684906af11c51cabd753fd0bcf6cf35f900b55ac Mon Sep 17 00:00:00 2001 From: http Date: Thu, 11 May 2017 01:53:46 +0300 Subject: [PATCH 15/17] fix bug --- abonapp/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/abonapp/models.py b/abonapp/models.py index 01823b0..8adae59 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -9,7 +9,7 @@ from agent import Transmitter, AbonStruct, TariffStruct, NasFailedResult, NasNet from tariff_app.models import Tariff from accounts_app.models import UserProfile from .fields import MACAddressField -from mydefs import MyGenericIPAddressField +from mydefs import MyGenericIPAddressField, ip2int class LogicError(Exception): @@ -321,7 +321,7 @@ class Abon(UserProfile): # создаём абонента из структуры агента def build_agent_struct(self): if self.ip_address: - user_ip = self.ip_address.int_ip() + user_ip = ip2int(self.ip_address) else: return inst_tariff = self.active_tariff() From 9479a0346cac9760f69019f09299664344caf63e Mon Sep 17 00:00:00 2001 From: http Date: Thu, 11 May 2017 01:54:22 +0300 Subject: [PATCH 16/17] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20ip=20integer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mydefs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mydefs.py b/mydefs.py index 413f8f3..eb48d3a 100644 --- a/mydefs.py +++ b/mydefs.py @@ -93,6 +93,9 @@ class MyGenericIPAddressField(models.GenericIPAddressField): def from_db_value(value, expression, connection, context): return int2ip(value) + def int_ip(self): + return ip2int(self) + # Предназначен для Django CHOICES чтоб можно было передавать классы вместо просто описания поля, # классы передавать для того чтоб по значению кода из базы понять какой класс нужно взять для нужной функциональности. From fe03f6091e1a5a34882c224a5ee837b6b9b22ef5 Mon Sep 17 00:00:00 2001 From: http Date: Thu, 11 May 2017 01:58:23 +0300 Subject: [PATCH 17/17] fix bug --- abonapp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abonapp/models.py b/abonapp/models.py index 8adae59..a9433b2 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -333,7 +333,7 @@ class Abon(UserProfile): def save(self, *args, **kwargs): # проверяем не-ли у кого такого-же ip - if Abon.objects.filter(ip_address=self.ip_address).count() > 0: + if Abon.objects.filter(ip_address=self.ip_address).exclude(pk=self.pk).count() > 0: self.is_bad_ip = True raise LogicError(_('Ip address already exist')) super(Abon, self).save(*args, **kwargs)