Browse Source

Refactoring listed views to ClassBasedViews

devel
bashmak 8 years ago
parent
commit
bfe17719d3
  1. 2
      dialing_app/views.py
  2. 2
      mapapp/templates/maps/options.html
  3. 2
      mapapp/urls.py
  4. 28
      mapapp/views.py

2
dialing_app/views.py

@ -12,7 +12,7 @@ from django.db.models import Q
from django.conf import settings
from abonapp.models import Abon
from mydefs import only_admins, pag_mn
from mydefs import only_admins
from .models import AsteriskCDR, SMSModel
from .forms import SMSOutForm

2
mapapp/templates/maps/options.html

@ -69,5 +69,5 @@
</div>
{% endwith %}
{% include 'toolbar_page.html' with pag=dots %}
{% include 'pagination.html' %}
{% endblock %}

2
mapapp/urls.py

@ -9,7 +9,7 @@ app_name = 'mapapp'
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^options$', views.options, name='options'),
url(r'^options$', views.OptionsListView.as_view(), name='options'),
url(r'^options/add$', views.dot, name='add_dot'),
url(r'^options/(?P<did>\d+)/edit$', views.dot, name='edit_dot'),
url(r'^options/(?P<did>\d+)/remove$', views.remove, name='remove_dot'),

28
mapapp/views.py

@ -5,16 +5,24 @@ from django.core.exceptions import PermissionDenied
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from django.shortcuts import render, redirect, get_object_or_404, resolve_url
from django.utils.translation import gettext_lazy as _
from django.utils.decorators import method_decorator
from django.db.models import Count
from django.views.generic import ListView
from django.conf import settings
from .models import Dot
from .forms import DotForm
from mydefs import pag_mn, safe_int
from mydefs import safe_int
from devapp.models import Device
from guardian.decorators import permission_required
from abonapp.models import AbonGroup
from json import dumps
class BaseListView(ListView):
http_method_names = ['get']
paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)
@login_required
def home(request):
if not request.user.is_superuser:
@ -27,16 +35,16 @@ def home(request):
})
@login_required
def options(request):
if not request.user.is_superuser:
return redirect('/')
dots = Dot.objects.all()
dots = pag_mn(request, dots)
return render(request, 'maps/options.html', {
'dots': dots
})
@method_decorator(login_required, name='dispatch')
class OptionsListView(BaseListView):
template_name = 'maps/options.html'
model = Dot
context_object_name = 'dots'
def get(self, request, *args, **kwargs):
if not request.user.is_superuser:
return redirect('/')
return super(OptionsListView, self).get(request, *args, **kwargs)
@login_required
def dot(request, did=0):

Loading…
Cancel
Save