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" 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')}, 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'), + ), + ] diff --git a/abonapp/models.py b/abonapp/models.py index 16bdd3e..a9433b2 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, ip2int 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) @@ -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() @@ -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).exclude(pk=self.pk).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) diff --git a/abonapp/templates/abonapp/charts.html b/abonapp/templates/abonapp/charts.html index 7c9373e..1be60c3 100644 --- a/abonapp/templates/abonapp/charts.html +++ b/abonapp/templates/abonapp/charts.html @@ -9,6 +9,7 @@