Browse Source

Fix ordering

devel
bashmak 8 years ago
parent
commit
9b2c1171a6
  1. 3
      abonapp/templates/abonapp/group_list.html
  2. 12
      abonapp/templates/abonapp/peoples.html
  3. 0
      abonapp/templatetags/__init__.py
  4. 4
      abonapp/views.py
  5. 6
      devapp/templates/devapp/devices.html
  6. 7
      devapp/templates/devapp/devices_null_group.html
  7. 11
      devapp/views.py
  8. 12
      djing/global_base_views.py
  9. 1
      djing/settings.py
  10. 12
      djing/templatetags/dpagination.py
  11. 3
      group_app/templates/group_app/group_list.html
  12. 6
      group_app/views.py
  13. 9
      tariff_app/templates/tariff_app/tarifs.html
  14. 15
      tariff_app/views.py

3
abonapp/templates/abonapp/group_list.html

@ -1,5 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %} {% load i18n %}
{% load dpagination %}
{% block main %} {% block main %}
<ol class="breadcrumb"> <ol class="breadcrumb">
@ -17,7 +18,7 @@
<tr> <tr>
<th width="50">#</th> <th width="50">#</th>
<th> <th>
<a href="{% url 'abonapp:group_list' %}?order_by=title&dir={{ dir|default:'down' }}">
<a href="{% url 'abonapp:group_list' %}?{% url_order_by request order_by='title' %}">
{% trans 'Group title' %} {% trans 'Group title' %}
</a> </a>
{% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}

12
abonapp/templates/abonapp/peoples.html

@ -23,32 +23,32 @@
<tr> <tr>
<th>#</th> <th>#</th>
<th class="col-xs-1"> <th class="col-xs-1">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_replace request order_by='username' dir=dir|default:'down' %}">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_order_by request order_by='username' %}">
{% trans 'Sub' %} {% trans 'Sub' %}
</a> </a>
{% if order_by == 'username' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'username' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th class="hidden-xs">{% trans 'Last traffic' %}</th> <th class="hidden-xs">{% trans 'Last traffic' %}</th>
<th class="col-xs-1 hidden-md"> <th class="col-xs-1 hidden-md">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_replace request order_by='ip_address' dir=dir|default:'down' %}">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_order_by request order_by='ip_address' %}">
{% trans 'Ip address' %} {% trans 'Ip address' %}
</a> </a>
{% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th class="col-xs-2"> <th class="col-xs-2">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_replace request order_by='fio' dir=dir|default:'down' %}">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_order_by request order_by='fio' %}">
{% trans 'fio' %} {% trans 'fio' %}
</a> </a>
{% if order_by == 'fio' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'fio' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th class="col-xs-2"> <th class="col-xs-2">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_replace request order_by='street' dir=dir|default:'down' %}">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_order_by request order_by='street' %}">
{% trans 'Street' %} {% trans 'Street' %}
</a> </a>
{% if order_by == 'street' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'street' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th class="col-xs-1"> <th class="col-xs-1">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_replace request order_by='house' dir=dir|default:'down' %}">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_order_by request order_by='house' %}">
{% trans 'Apartment' %} {% trans 'Apartment' %}
</a> </a>
{% if order_by == 'house' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'house' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
@ -56,7 +56,7 @@
<th class="col-xs-1">{% trans 'Telephone' %}</th> <th class="col-xs-1">{% trans 'Telephone' %}</th>
<th class="col-xs-2">{% trans 'Service' %}</th> <th class="col-xs-2">{% trans 'Service' %}</th>
<th class="hidden-xs col-sm-1"> <th class="hidden-xs col-sm-1">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_replace request order_by='ballance' dir=dir|default:'down' %}">
<a href="{% url 'abonapp:people_list' group.pk %}?{% url_order_by request order_by='ballance' %}">
{% trans 'Balance' %} {% trans 'Balance' %}
</a> </a>
{% if order_by == 'ballance' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'ballance' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}

0
abonapp/templatetags/__init__.py

4
abonapp/views.py

@ -30,10 +30,10 @@ from guardian.shortcuts import get_objects_for_user, assign_perm
from guardian.decorators import permission_required_or_403 as permission_required from guardian.decorators import permission_required_or_403 as permission_required
from djing import ping from djing import ping
from djing import lib from djing import lib
from djing.global_base_views import OrderingMixin, BaseListWithFiltering, SecureApiView
from djing.global_base_views import OrderedFilteredList, SecureApiView
class BaseAbonListView(OrderingMixin, BaseListWithFiltering):
class BaseAbonListView(OrderedFilteredList):
paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10) paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)
http_method_names = ('get',) http_method_names = ('get',)

6
devapp/templates/devapp/devices.html

@ -18,20 +18,20 @@
<tr> <tr>
<th>#</th> <th>#</th>
<th class="col-md-2"> <th class="col-md-2">
<a href="{% url 'devapp:devs' group.pk %}?{% url_replace request order_by='ip_address' dir=dir|default:'down' %}">
<a href="{% url 'devapp:devs' group.pk %}?{% url_order_by request order_by='ip_address' %}">
{% trans 'Ip address' %} {% trans 'Ip address' %}
</a> </a>
{% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th class="col-md-5"> <th class="col-md-5">
<a href="{% url 'devapp:devs' group.pk %}?{% url_replace request order_by='comment' dir=dir|default:'down' %}">
<a href="{% url 'devapp:devs' group.pk %}?{% url_order_by request order_by='comment' %}">
{% trans 'Comment' %} {% trans 'Comment' %}
</a> </a>
{% if order_by == 'comment' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'comment' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th class="col-md-3">{% trans 'Mac address' %}</th> <th class="col-md-3">{% trans 'Mac address' %}</th>
<th class="col-md-1"> <th class="col-md-1">
<a href="{% url 'devapp:devs' group.pk %}?{% url_replace request order_by='devtype' dir=dir|default:'down' %}">
<a href="{% url 'devapp:devs' group.pk %}?{% url_order_by request order_by='devtype' %}">
{% trans 'Device type' %} {% trans 'Device type' %}
</a> </a>
{% if order_by == 'devtype' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'devtype' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}

7
devapp/templates/devapp/devices_null_group.html

@ -1,5 +1,6 @@
{% extends request.is_ajax|yesno:'bajax.html,base.html' %} {% extends request.is_ajax|yesno:'bajax.html,base.html' %}
{% load i18n %} {% load i18n %}
{% load dpagination %}
{% block main %} {% block main %}
<ol class="breadcrumb"> <ol class="breadcrumb">
@ -16,19 +17,19 @@
<thead> <thead>
<tr> <tr>
<th> <th>
<a href="{% url 'devapp:devices_null_group' %}?order_by=ip_address&dir={{ dir|default:'down' }}">
<a href="{% url 'devapp:devices_null_group' %}?{% url_order_by request order_by='ip_address' %}">
{% trans 'Ip address' %} {% trans 'Ip address' %}
</a> </a>
{% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th> <th>
<a href="{% url 'devapp:devices_null_group' %}?order_by=comment&dir={{ dir|default:'down' }}">
<a href="{% url 'devapp:devices_null_group' %}?{% url_order_by request order_by='comment' %}">
{% trans 'Comment' %} {% trans 'Comment' %}
</a> </a>
{% if order_by == 'comment' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'comment' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th width="250"> <th width="250">
<a href="{% url 'devapp:devices_null_group' %}?order_by=devtype&dir={{ dir|default:'down' }}">
<a href="{% url 'devapp:devices_null_group' %}?{% url_order_by request order_by='devtype' %}">
{% trans 'Device type' %} {% trans 'Device type' %}
</a> </a>
{% if order_by == 'devtype' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'devtype' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}

11
devapp/views.py

@ -30,13 +30,8 @@ from .models import Device, Port, DeviceDBException, DeviceMonitoringException
from .forms import DeviceForm, PortForm, DeviceExtraDataForm from .forms import DeviceForm, PortForm, DeviceExtraDataForm
class BaseDeviceListView(global_base_views.BaseListWithFiltering):
http_method_names = ('get',)
paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)
@method_decorator((login_required, only_admins), name='dispatch') @method_decorator((login_required, only_admins), name='dispatch')
class DevicesListView(global_base_views.OrderingMixin, BaseDeviceListView):
class DevicesListView(global_base_views.OrderedFilteredList):
context_object_name = 'devices' context_object_name = 'devices'
template_name = 'devapp/devices.html' template_name = 'devapp/devices.html'
@ -63,7 +58,7 @@ class DevicesListView(global_base_views.OrderingMixin, BaseDeviceListView):
@method_decorator((login_required, only_admins), name='dispatch') @method_decorator((login_required, only_admins), name='dispatch')
class DevicesWithoutGroupsListView(global_base_views.OrderingMixin, BaseDeviceListView):
class DevicesWithoutGroupsListView(global_base_views.OrderedFilteredList):
context_object_name = 'devices' context_object_name = 'devices'
template_name = 'devapp/devices_null_group.html' template_name = 'devapp/devices_null_group.html'
queryset = Device.objects.filter(group=None).only('comment', 'devtype', 'pk', 'ip_address') queryset = Device.objects.filter(group=None).only('comment', 'devtype', 'pk', 'ip_address')
@ -516,7 +511,7 @@ def toggle_port(request, device_id: int, portid: int, status=0):
@method_decorator((login_required, only_admins), name='dispatch') @method_decorator((login_required, only_admins), name='dispatch')
class GroupsListView(BaseDeviceListView):
class GroupsListView(global_base_views.OrderedFilteredList):
context_object_name = 'groups' context_object_name = 'groups'
template_name = 'devapp/group_list.html' template_name = 'devapp/group_list.html'
model = Group model = Group

12
djing/global_base_views.py

@ -80,14 +80,6 @@ class OrderingMixin(object):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(OrderingMixin, self).get_context_data(**kwargs) context = super(OrderingMixin, self).get_context_data(**kwargs)
context['order_by'] = self.request.GET.get('order_by') context['order_by'] = self.request.GET.get('order_by')
direction = self.request.GET.get('dir')
if direction == 'down':
direction = 'up'
elif direction == 'up':
direction = 'down'
else:
direction = ''
context['dir'] = direction
return context return context
def get_ordering(self): def get_ordering(self):
@ -147,3 +139,7 @@ class BaseListWithFiltering(RedirectWhenErrorMixin, ListView):
'page_number': page_number, 'page_number': page_number,
'message': str(e) 'message': str(e)
}) })
class OrderedFilteredList(OrderingMixin, BaseListWithFiltering):
paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)

1
djing/settings.py

@ -89,6 +89,7 @@ TEMPLATES = [
], ],
'libraries': { 'libraries': {
'globaltags': 'djing.templatetags.globaltags', 'globaltags': 'djing.templatetags.globaltags',
'dpagination': 'djing.templatetags.dpagination'
} }
}, },
}, },

12
abonapp/templatetags/dpagination.py → djing/templatetags/dpagination.py

@ -11,8 +11,18 @@ def url_page_replace(request, field, value):
@register.simple_tag @register.simple_tag
def url_replace(request, *args, **kwargs):
def url_order_by(request, **kwargs):
dict_ = request.GET.copy() dict_ = request.GET.copy()
for k, v in kwargs.items(): for k, v in kwargs.items():
dict_[k] = v dict_[k] = v
direction = dict_.get('dir')
if direction is None:
direction = dict_.get('default_direction', 'up')
if direction == 'down':
direction = 'up'
elif direction == 'up':
direction = 'down'
else:
direction = ''
dict_['dir'] = direction
return dict_.urlencode() return dict_.urlencode()

3
group_app/templates/group_app/group_list.html

@ -1,5 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %} {% load i18n %}
{% load dpagination %}
{% block main %} {% block main %}
<ol class="breadcrumb"> <ol class="breadcrumb">
@ -18,7 +19,7 @@
<th width="50">#</th> <th width="50">#</th>
<th width="50">{% trans 'TeCo' %}</th> <th width="50">{% trans 'TeCo' %}</th>
<th> <th>
<a href="{% url 'group_app:group_list' %}?order_by=title&dir={{ dir|default:'down' }}">
<a href="{% url 'group_app:group_list' %}?{% url_order_by request order_by='title' %}">
{% trans 'Title' %} {% trans 'Title' %}
</a> </a>
{% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}

6
group_app/views.py

@ -1,6 +1,6 @@
from django.db.models import Count from django.db.models import Count
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.views.generic import ListView, UpdateView, CreateView, DeleteView
from django.views.generic import UpdateView, CreateView, DeleteView
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
@ -8,12 +8,14 @@ from django.urls import reverse_lazy
from django.contrib import messages from django.contrib import messages
from django.conf import settings from django.conf import settings
from guardian.decorators import permission_required_or_403 as permission_required from guardian.decorators import permission_required_or_403 as permission_required
from djing.global_base_views import OrderedFilteredList
from . import models from . import models
from . import forms from . import forms
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
class GroupListView(ListView):
class GroupListView(OrderedFilteredList):
http_method_names = ('get',) http_method_names = ('get',)
paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10) paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)
template_name = 'group_app/group_list.html' template_name = 'group_app/group_list.html'

9
tariff_app/templates/tariff_app/tarifs.html

@ -1,5 +1,6 @@
{% extends request.is_ajax|yesno:'nullcont.htm,tariff_app/ext.html' %} {% extends request.is_ajax|yesno:'nullcont.htm,tariff_app/ext.html' %}
{% load i18n %} {% load i18n %}
{% load dpagination %}
{% block content %} {% block content %}
<div class="table-responsive"> <div class="table-responsive">
@ -7,25 +8,25 @@
<thead> <thead>
<tr> <tr>
<th> <th>
<a href="{% url 'tarifs:home' %}?order_by=title&dir={{ dir|default:'down' }}">
<a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='title' %}">
{% trans 'tariff' %} {% trans 'tariff' %}
</a> </a>
{% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th> <th>
<a href="{% url 'tarifs:home' %}?order_by=speedIn&dir={{ dir|default:'down' }}">
<a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='speedIn' %}">
{% trans 'Speed In' %} {% trans 'Speed In' %}
</a> </a>
{% if order_by == 'speedIn' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'speedIn' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th> <th>
<a href="{% url 'tarifs:home' %}?order_by=speedOut&dir={{ dir|default:'down' }}">
<a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='speedOut' %}">
{% trans 'Speed Out' %} {% trans 'Speed Out' %}
</a> </a>
{% if order_by == 'speedOut' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'speedOut' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th> </th>
<th> <th>
<a href="{% url 'tarifs:home' %}?order_by=amount&dir={{ dir|default:'down' }}">
<a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='amount' %}">
{% trans 'Price' %} {% trans 'Price' %}
</a> </a>
{% if order_by == 'amount' %}<span class="glyphicon glyphicon-filter"></span>{% endif %} {% if order_by == 'amount' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}

15
tariff_app/views.py

@ -1,28 +1,21 @@
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.gis.shortcuts import render_to_text
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.views.generic import ListView, DeleteView
from django.conf import settings
from django.views.generic import DeleteView
from guardian.decorators import permission_required_or_403 as permission_required from guardian.decorators import permission_required_or_403 as permission_required
from djing.global_base_views import OrderingMixin
from djing.global_base_views import OrderedFilteredList
from .models import Tariff, PeriodicPay from .models import Tariff, PeriodicPay
from djing import lib from djing import lib
from . import forms from . import forms
class BaseServiceListView(ListView):
http_method_names = ('get',)
paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)
@method_decorator((login_required, lib.decorators.only_admins), name='dispatch') @method_decorator((login_required, lib.decorators.only_admins), name='dispatch')
class TariffsListView(BaseServiceListView, OrderingMixin):
class TariffsListView(OrderedFilteredList):
""" """
Show Services(Tariffs) list Show Services(Tariffs) list
""" """
@ -80,7 +73,7 @@ class TariffDeleteView(DeleteView):
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
@method_decorator(permission_required('tariff_app.delete_tariff'), name='dispatch') @method_decorator(permission_required('tariff_app.delete_tariff'), name='dispatch')
class PeriodicPaysListView(BaseServiceListView):
class PeriodicPaysListView(OrderedFilteredList):
context_object_name = 'pays' context_object_name = 'pays'
model = PeriodicPay model = PeriodicPay
template_name = 'tariff_app/periodic_pays/list.html' template_name = 'tariff_app/periodic_pays/list.html'

Loading…
Cancel
Save