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 @@

График использования

+ {% if charts_data %} + {% else %} +

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

+ {% endif %}
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 @@ -
+
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 @@
- +

diff --git a/abonapp/views.py b/abonapp/views.py index 823b248..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 }) @@ -745,7 +737,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()) }) 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>