Dmitry Novikov 8 years ago
parent
commit
fd203d6f28
  1. 4
      abonapp/locale/ru/LC_MESSAGES/django.po
  2. 7
      abonapp/models.py
  3. 13
      abonapp/views.py
  4. 15
      accounts_app/templates/accounts/login.html
  5. 2
      agent/mod_mikrotik.py
  6. 3
      periodic.py

4
abonapp/locale/ru/LC_MESSAGES/django.po

@ -207,8 +207,8 @@ msgid "Buy service default log"
msgstr "Покупка тарифного плана через админку"
#: models.py:233
msgid "Account has no one ips"
msgstr "Учётная запись не имеет ни одного ip адреса"
msgid "Account has no one active ips"
msgstr "Учётная запись не имеет ни одного активного ip адреса"
#: models.py:257
msgid "Pasport serial"

7
abonapp/models.py

@ -225,13 +225,12 @@ class Abon(BaseAccount):
agent_trf = TariffStruct(trf.id, trf.speedIn, trf.speedOut)
if len(abon_addresses) > 0:
return AbonStruct(self.pk, abon_addresses, agent_trf, self.is_access())
raise LogicError(_('You have not any active leases'))
def sync_with_nas(self, created: bool) -> Optional[Exception]:
agent_abon = self.build_agent_struct()
if agent_abon is None:
return
if len(agent_abon.ips) < 1:
return _('Account has no one ips')
if agent_abon is None or len(agent_abon.ips) < 1:
return _('Account has no one active ips')
try:
tm = Transmitter()
if created:

13
abonapp/views.py

@ -1102,20 +1102,21 @@ def user_session_toggle(request, gid, uname, lease_id, action=None):
abon = get_object_or_404(models.Abon, username=uname)
lease = abon.ip_addresses.get(pk=lease_id)
tm = Transmitter()
abon_nas_obj = abon.build_agent_struct()
try:
if action == 'free':
if abon.ip_addresses.filter(is_active=True).count() > 1:
try:
abon_nas_obj = abon.build_agent_struct()
tm.lease_free(abon_nas_obj, ip_address(lease.ip))
lease.free()
messages.success(request, _('Ip lease has been freed'))
else:
lease.free()
except lib.LogicError:
messages.error(request, _('You cannot disable last session'))
elif action == 'start':
tm.lease_start(abon_nas_obj, ip_address(lease.ip))
lease.start()
abon_nas_obj = abon.build_agent_struct()
tm.lease_start(abon_nas_obj, ip_address(lease.ip))
messages.success(request, _('Ip lease has been started'))
except NasFailedResult as e:
except (NasFailedResult, lib.LogicError) as e:
messages.error(request, e)
return redirect('abonapp:abon_home', gid, uname)

15
accounts_app/templates/accounts/login.html

@ -1,4 +1,4 @@
<!DOCTYPE html>{% load i18n %}
<!DOCTYPE html>{% load i18n %}{% load acc_tags %}
<html lang="{{ LANGUAGE_CODE }}">
<head>
<meta charset="UTF-8">
@ -51,13 +51,16 @@
</div>
</div>
<div class="btn-group">
<button type="submit" class="btn btn-sm btn-primary">
<div class="btn-group btn-group-sm">
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-log-in"></span> {% trans 'Login' %}
</button>
<button type="reset" class="btn btn-sm btn-default">
<span class="glyphicon glyphicon-remove-sign"></span> {% trans 'Reset' %}
</button>
{% is_abon request as is_private_abon %}
{% if is_private_abon %}
<a href="{% url 'abonapp:login_nopassw' %}" class="btn btn-default">
<span class="glyphicon glyphicon-screenshot"></span> {% trans 'Login without password' %}
</a>
{% endif %}
</div>
</form>

2
agent/mod_mikrotik.py

@ -496,6 +496,8 @@ class MikrotikTransmitter(BaseTransmitter, ApiRos, metaclass=type('_ABC_Lazy_mcs
def lease_start(self, user: AbonStruct, lease):
if not issubclass(lease.__class__, _BaseAddress):
lease = ip_address(lease)
if not isinstance(user, AbonStruct):
raise TypeError
ip = self.find_ip(lease, LIST_USERS_ALLOWED)
if ip is None:
self.add_ip(LIST_USERS_ALLOWED, lease)

3
periodic.py

@ -40,10 +40,9 @@ def main():
try:
tm = Transmitter()
users = Abon.objects\
.filter(is_active=True)\
.filter(is_active=True, ips_count__gt=0)\
.exclude(current_tariff=None)\
.annotate(ips_count=Count('ip_addresses'))\
.filter(ips_count__gt=0)\
.prefetch_related('ip_addresses')\
.iterator()
tm.sync_nas(users)

Loading…
Cancel
Save