From 881d7f8c4000a31c32c5c145f52a6a3fedd9f65c Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Fri, 5 Apr 2019 17:07:56 +0300 Subject: [PATCH] add page to view services users --- install/install_debian.sh | 2 +- tariff_app/locale/ru/LC_MESSAGES/django.po | 97 ++++++++++--------- .../templates/tariff_app/service_users.html | 52 ++++++++++ tariff_app/templates/tariff_app/tarifs.html | 6 +- tariff_app/urls.py | 1 + tariff_app/views.py | 43 ++++++-- 6 files changed, 145 insertions(+), 56 deletions(-) create mode 100644 tariff_app/templates/tariff_app/service_users.html diff --git a/install/install_debian.sh b/install/install_debian.sh index ce5f5c7..b7e6450 100644 --- a/install/install_debian.sh +++ b/install/install_debian.sh @@ -48,7 +48,7 @@ find . -type d \( -path ./venv -o -path ./src -o -path ./.git \) -prune -o -type # files find . -type d \( -path ./venv -o -path ./src -o -path ./.git \) -prune -o -type f -exec chmod 640 {} \; # exec scripts -chmod 750 dhcp_lever.py manage.py periodic.py devapp/expect_scripts/dlink_DGS1100_reboot.exp +chmod 750 dhcp_lever.py manage.py periodic.py devapp/expect_scripts/dlink_DGS1100_reboot.exp agent/netflow/netflow_handler.py chmod 400 djing/settings.py rm /etc/nginx/sites-enabled/default diff --git a/tariff_app/locale/ru/LC_MESSAGES/django.po b/tariff_app/locale/ru/LC_MESSAGES/django.po index e7bd886..461d9b2 100644 --- a/tariff_app/locale/ru/LC_MESSAGES/django.po +++ b/tariff_app/locale/ru/LC_MESSAGES/django.po @@ -1,5 +1,3 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # Dmitry Novikov nerosketch@gmail.com, 2017. # @@ -8,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-09 15:01+0300\n" +"POT-Creation-Date: 2019-04-05 17:02+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Dmitry Novikov nerosketch@gmail.com\n" "Language: ru\n" @@ -47,15 +45,15 @@ msgstr "Название тарифа" msgid "Service description" msgstr "Описание тарифа" -#: models.py:20 templates/tariff_app/tarifs.html:18 +#: models.py:20 templates/tariff_app/tarifs.html:17 msgid "Speed In" msgstr "Входящая скорость" -#: models.py:21 templates/tariff_app/tarifs.html:24 +#: models.py:21 templates/tariff_app/tarifs.html:23 msgid "Speed Out" msgstr "Исходящая скорость" -#: models.py:22 templates/tariff_app/tarifs.html:30 +#: models.py:22 templates/tariff_app/tarifs.html:29 msgid "Price" msgstr "Стоимость" @@ -73,7 +71,8 @@ msgstr "Услуга" #: models.py:56 templates/tariff_app/ext.html:7 #: templates/tariff_app/ext.html:12 templates/tariff_app/ext.html:21 -#: templates/tariff_app/periodic_pays/add_edit.html:8 +#: templates/tariff_app/periodic_pays/add_edit.html:7 +#: templates/tariff_app/service_users.html:7 msgid "Services" msgstr "Тарифы" @@ -93,56 +92,56 @@ msgstr "Алгоритм расчёта" msgid "Total amount" msgstr "Стоимость" -#: models.py:106 +#: models.py:103 msgid "Periodic pay" msgstr "Периодический платёж" -#: models.py:107 templates/tariff_app/ext.html:28 +#: models.py:104 templates/tariff_app/ext.html:28 msgid "Periodic pays" msgstr "Периодические платежи" -#: templates/tariff_app/editTarif.html:8 +#: templates/tariff_app/editTarif.html:7 msgid "Tarifs" msgstr "Тарифы" -#: templates/tariff_app/editTarif.html:11 +#: templates/tariff_app/editTarif.html:10 #: templates/tariff_app/periodic_pays/list.html:50 -#: templates/tariff_app/tarifs.html:78 +#: templates/tariff_app/tarifs.html:83 msgid "Add" msgstr "Добавить" -#: templates/tariff_app/editTarif.html:13 -#: templates/tariff_app/editTarif.html:22 +#: templates/tariff_app/editTarif.html:12 +#: templates/tariff_app/editTarif.html:21 #: templates/tariff_app/periodic_pays/list.html:17 msgid "Edit" msgstr "Редактировать" -#: templates/tariff_app/editTarif.html:22 templates/tariff_app/tarifs.html:65 +#: templates/tariff_app/editTarif.html:21 templates/tariff_app/tarifs.html:70 msgid "Create" msgstr "Создать" -#: templates/tariff_app/editTarif.html:22 templates/tariff_app/tarifs.html:12 +#: templates/tariff_app/editTarif.html:21 templates/tariff_app/tarifs.html:11 msgid "tariff" msgstr "тариф" -#: templates/tariff_app/editTarif.html:51 -#: templates/tariff_app/periodic_pays/add_edit.html:47 +#: templates/tariff_app/editTarif.html:50 +#: templates/tariff_app/periodic_pays/add_edit.html:46 msgid "Save" msgstr "Сохранить" -#: templates/tariff_app/editTarif.html:54 +#: templates/tariff_app/editTarif.html:53 msgid "Reset" msgstr "Сбросить" -#: templates/tariff_app/periodic_pays/add_edit.html:10 +#: templates/tariff_app/periodic_pays/add_edit.html:9 msgid "Change periodic pay" msgstr "Может редактировать периодический платёж" -#: templates/tariff_app/periodic_pays/add_edit.html:12 +#: templates/tariff_app/periodic_pays/add_edit.html:11 msgid "Add new periodic pay" msgstr "Добавить периодический платёж" -#: templates/tariff_app/periodic_pays/add_edit.html:32 +#: templates/tariff_app/periodic_pays/add_edit.html:31 msgid "Pay details" msgstr "Подробности платежа" @@ -150,6 +149,28 @@ msgstr "Подробности платежа" msgid "The list is empty" msgstr "Список пуст" +#: templates/tariff_app/service_users.html:8 +msgid "Service users" +msgstr "Пользователи услуг" + +#: templates/tariff_app/service_users.html:13 +#, python-format +msgid "'%(service_name)s' tariff users" +msgstr "Пользователи услуги '%(service_name)s'" + +#: templates/tariff_app/service_users.html:14 +msgid "Total:" +msgstr "Всего" + +#: templates/tariff_app/service_users.html:25 +#: templates/tariff_app/service_users.html:31 +msgid "Username" +msgstr "Логин" + +#: templates/tariff_app/service_users.html:46 +msgid "Customers that uses this service not found." +msgstr "Не найдены абоненты использующие эту услугу." + #: templates/tariff_app/tariff_confirm_delete.html:9 msgid "Delete service" msgstr "Удалить тарифный план" @@ -167,46 +188,34 @@ msgstr "" "сразу потеряют услугу по этому тарифу. Так что сначала убедитесь что уже " "никто не пользуется тарифом, и только после этого удалите его." +#: templates/tariff_app/tarifs.html:33 +msgid "Users count" +msgstr "Кол. пользователей" + #: templates/tariff_app/tarifs.html:51 msgid "currency" msgstr "руб." -#: templates/tariff_app/tarifs.html:63 +#: templates/tariff_app/tarifs.html:68 msgid "Services does not exist yet" msgstr "Ещё нет созданных тарифов" -#: views.py:44 +#: views.py:60 msgid "Service has been saved" msgstr "Тариф успешно сохранён" -#: views.py:47 views.py:103 +#: views.py:63 views.py:123 msgid "Some fields were filled incorrect, please try again" msgstr "Не все поля заполнены правильно, проверте и попробуйте ещё раз" -#: views.py:66 +#: views.py:86 msgid "Service has been deleted" msgstr "Тарифный план успешно удалён" -#: views.py:97 +#: views.py:117 msgid "New periodic pay successfully created" msgstr "Новый периодический платёж создан" -#: views.py:99 +#: views.py:119 msgid "Periodic pay has been changed" msgstr "Периодический платёж изменён" - -msgid "Attention" -msgstr "Внимание" - -msgid "Delete" -msgstr "Удалить" - -msgid "Not have a confirmations of delete" -msgstr "Нет подтверждения удаления" - -msgid "" -"Service with this Speed In, Speed Out, Price and Script already exists." -msgstr "Услуга с такой скоростью, ценой и логикой уже есть" - -msgid "Users count" -msgstr "Кол. пользователей" \ No newline at end of file diff --git a/tariff_app/templates/tariff_app/service_users.html b/tariff_app/templates/tariff_app/service_users.html new file mode 100644 index 0000000..8d5d9c1 --- /dev/null +++ b/tariff_app/templates/tariff_app/service_users.html @@ -0,0 +1,52 @@ +{% extends 'base.html' %} +{% load i18n dpagination %} + +{% block breadcrumb %} + +{% endblock %} + +{% block page-header %} + {% blocktrans with service_name=tariff.title %}'{{ service_name }}' tariff users{% endblocktrans %}. + {% trans 'Total:' %} {{ total }} +{% endblock %} + +{% block main %} + +
+ + + + + + + + + + {% for customer in object_list %} + + + + + {% empty %} + + + + {% endfor %} + +
+ + {% trans 'Username' %} + + {% if order_by == 'username' %}{% endif %} + + + {% trans 'Username' %} + + {% if order_by == 'fio' %}{% endif %} + #
{{ customer.username }}{{ customer.fio }}
{% trans 'Customers that uses this service not found.' %}
+
+{% endblock %} diff --git a/tariff_app/templates/tariff_app/tarifs.html b/tariff_app/templates/tariff_app/tarifs.html index db8abbe..2074235 100644 --- a/tariff_app/templates/tariff_app/tarifs.html +++ b/tariff_app/templates/tariff_app/tarifs.html @@ -49,7 +49,11 @@ {{ tar.speedIn }} {{ tar.speedOut }} {{ tar.amount }} {% trans 'currency' %} - {{ tar.usercount }} + + {% if tar.usercount > 0 %} + {{ tar.usercount }} + {% else %}0{% endif %} + {{ tar.get_calc_type_display }} {% if can_del_trf %} diff --git a/tariff_app/urls.py b/tariff_app/urls.py index 470c16a..c0e260c 100644 --- a/tariff_app/urls.py +++ b/tariff_app/urls.py @@ -7,6 +7,7 @@ app_name = 'tariff_app' urlpatterns = [ path('', views.TariffsListView.as_view(), name='home'), path('/', views.edit_tarif, name='edit'), + path('/users/', views.ServiceUsers.as_view(), name='service_users'), path('add/', views.edit_tarif, name='add'), path('del//', views.TariffDeleteView.as_view(), name='del'), diff --git a/tariff_app/views.py b/tariff_app/views.py index 4394849..a3a9ffb 100644 --- a/tariff_app/views.py +++ b/tariff_app/views.py @@ -1,7 +1,7 @@ from django.contrib.auth.decorators import login_required +from django.contrib.auth.mixins import PermissionRequiredMixin from django.db.models import Count from django.urls import reverse_lazy -from django.utils.decorators import method_decorator from django.utils.translation import ugettext as _ from django.shortcuts import render, get_object_or_404, redirect from django.contrib import messages @@ -10,6 +10,8 @@ from django.views.generic import DeleteView from guardian.decorators import permission_required_or_403 as permission_required from djing.global_base_views import OrderedFilteredList +from djing.lib.mixins import LoginAdminMixin +from abonapp.models import Abon from .models import Tariff, PeriodicPay from djing import lib from djing.lib.decorators import only_admins @@ -19,12 +21,11 @@ from . import forms login_decs = login_required, only_admins -@method_decorator(login_decs, name='dispatch') -@method_decorator(permission_required('tariff_app.view_tariff'), name='dispatch') -class TariffsListView(OrderedFilteredList): +class TariffsListView(LoginAdminMixin, PermissionRequiredMixin, OrderedFilteredList): """ Show Services(Tariffs) list """ + permission_required = 'tariff_app.view_tariff' template_name = 'tariff_app/tarifs.html' context_object_name = 'tariflist' model = Tariff @@ -69,9 +70,8 @@ def edit_tarif(request, tarif_id=0): }) -@method_decorator(login_decs, name='dispatch') -@method_decorator(permission_required('tariff_app.delete_tariff'), name='dispatch') -class TariffDeleteView(DeleteView): +class TariffDeleteView(LoginAdminMixin, PermissionRequiredMixin, DeleteView): + permission_required = 'tariff_app.delete_tariff' model = Tariff pk_url_kwarg = 'tid' success_url = reverse_lazy('tarifs:home') @@ -91,9 +91,8 @@ class TariffDeleteView(DeleteView): return super().get_context_data(**kwargs) -@method_decorator(login_decs, name='dispatch') -@method_decorator(permission_required('tariff_app.view_periodicpay'), name='dispatch') -class PeriodicPaysListView(OrderedFilteredList): +class PeriodicPaysListView(LoginAdminMixin, PermissionRequiredMixin, OrderedFilteredList): + permission_required = 'tariff_app.view_periodicpay' context_object_name = 'pays' model = PeriodicPay template_name = 'tariff_app/periodic_pays/list.html' @@ -129,3 +128,27 @@ def periodic_pay(request, pay_id=0): 'pay_instance': pay_inst, 'form': frm }) + + +class ServiceUsers(LoginAdminMixin, OrderedFilteredList): + template_name = 'tariff_app/service_users.html' + model = Abon + + def get_queryset(self): + tarif_id = self.kwargs.get('tarif_id') + return Abon.objects.filter(current_tariff__tariff__id=tarif_id).select_related('group') + + def get_context_data(self, **kwargs): + if hasattr(self, 'tariff'): + tariff = getattr(self, 'tariff') + else: + tarif_id = self.kwargs.get('tarif_id') + tariff = get_object_or_404(Tariff, pk=tarif_id) + setattr(self, 'tariff', tariff) + self.tariff = tariff + context = { + 'tariff': tariff, + 'total': self.object_list.count() + } + context.update(kwargs) + return super().get_context_data(**context)