From c008c9d9f8842ee6b339ed2f6829d6b25b859d0a Mon Sep 17 00:00:00 2001 From: nerosketch Date: Thu, 24 May 2018 10:34:52 +0300 Subject: [PATCH] fix dhcp commit command, and little bit refactoring --- abonapp/views.py | 2 +- agent/commands/dhcp.py | 11 +++++------ agent/mod_mikrotik.py | 2 +- devapp/dev_types.py | 2 +- devapp/locale/ru/LC_MESSAGES/django.po | 3 +++ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/abonapp/views.py b/abonapp/views.py index 5b30982..7c1333f 100644 --- a/abonapp/views.py +++ b/abonapp/views.py @@ -71,7 +71,7 @@ class PeoplesListView(BaseAbonListView): def get_context_data(self, **kwargs): gid = mydefs.safe_int(self.kwargs.get('gid')) - if gid == 0: + if gid < 1: return HttpResponseBadRequest('group id is broken') group = get_object_or_404(Group, pk=gid) if not self.request.user.has_perm('group_app.can_view_group', group): diff --git a/agent/commands/dhcp.py b/agent/commands/dhcp.py index 65c517c..92051a8 100644 --- a/agent/commands/dhcp.py +++ b/agent/commands/dhcp.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from typing import Optional from django.core.exceptions import MultipleObjectsReturned from abonapp.models import Abon @@ -19,13 +18,13 @@ def dhcp_commit(client_ip: str, client_mac: str, switch_mac: str, switch_port: i if not abon.is_dynamic_ip: print('D:', 'User settings is not dynamic') return - if not abon.is_access(): - print('D:', 'User %s is not access to service' % abon.username) - return if abon.ip_address != client_ip: abon.ip_address = client_ip abon.save(update_fields=('ip_address',)) - abon.sync_with_nas(created=False) + if abon.is_access(): + abon.sync_with_nas(created=False) + else: + print('D:', 'User %s is not access to service' % abon.username) except Abon.DoesNotExist: return "User with device with mac '%s' does not exist" % switch_mac except Device.DoesNotExist: @@ -36,7 +35,7 @@ def dhcp_commit(client_ip: str, client_mac: str, switch_mac: str, switch_port: i 'switch_mac': switch_mac } except MultipleObjectsReturned as e: - return 'MultipleObjectsReturned:' + ' '.join(type(e), e, str(switch_port)) + return 'MultipleObjectsReturned:' + ' '.join((type(e), e, str(switch_port))) def dhcp_expiry(client_ip) -> Optional[str]: diff --git a/agent/mod_mikrotik.py b/agent/mod_mikrotik.py index fbeb7e0..03adb24 100644 --- a/agent/mod_mikrotik.py +++ b/agent/mod_mikrotik.py @@ -405,7 +405,7 @@ class MikrotikTransmitter(QueueManager, IpAddressListManager): self.add_user(usr) def remove_user_range(self, users: VectorAbon): - if not isinstance(users, (tuple, list)): + if not isinstance(users, (tuple, list, set)): raise ValueError('*users* is used twice, generator does not fit') queue_ids = (usr.queue_id for usr in users if usr is not None) QueueManager.remove_range(self, queue_ids) diff --git a/devapp/dev_types.py b/devapp/dev_types.py index 3bc369c..31f97b5 100644 --- a/devapp/dev_types.py +++ b/devapp/dev_types.py @@ -163,7 +163,7 @@ class OnuDevice(DevBase, SNMPBaseWorker): if parent_device is not None and parent_device.ip_address: dev_ip_addr = parent_device.ip_address if dev_ip_addr is None: - raise DeviceImplementationError('Ip address or parent device with ip address required for ONU device') + raise DeviceImplementationError(gettext('Ip address or parent device with ip address required for ONU device')) SNMPBaseWorker.__init__(self, dev_ip_addr, dev_instance.man_passw, 2) @staticmethod diff --git a/devapp/locale/ru/LC_MESSAGES/django.po b/devapp/locale/ru/LC_MESSAGES/django.po index 260048e..b9f1eef 100644 --- a/devapp/locale/ru/LC_MESSAGES/django.po +++ b/devapp/locale/ru/LC_MESSAGES/django.po @@ -532,3 +532,6 @@ msgstr "%(device_name)s недостижим" msgid "Device %(device_name)s getting undefined status code" msgstr "Устройство %(device_name)s получило не определённый код состояния" + +msgid "Ip address or parent device with ip address required for ONU device" +msgstr "Необходим ip адрес. Или родительское устройство с назначенным ip адресом необходимо."