diff --git a/accounts/views.py b/accounts/views.py index e4eb1243..c6cc53b5 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -8,7 +8,8 @@ from django.contrib.auth.decorators import login_required from django.utils.translation import ugettext as _, get_language from django.utils import timezone from django_messages.forms import SendForm -from django.views.generic import TemplateView, FormView, ListView +from django.views.generic import TemplateView, FormView +from functions.custom_views import ListView from sorl.thumbnail import get_thumbnail from .forms import ChangePasswordForm, EmailAnnouncementForm, FeedFilterForm from company.forms import CreateCompanyForm diff --git a/article/views.py b/article/views.py index 4b421db2..53dbdb6e 100644 --- a/article/views.py +++ b/article/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import json -from django.views.generic import DetailView, ListView +from django.views.generic import DetailView +from functions.custom_views import ListView from django.http import HttpResponse from models import Article from forms import ArticleFilterForm diff --git a/company/views.py b/company/views.py index d82401a8..d77a6ca2 100644 --- a/company/views.py +++ b/company/views.py @@ -2,7 +2,8 @@ import json from django.http import HttpResponse from django.conf import settings -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView +from functions.custom_views import ListView from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext as _, get_language from haystack.query import EmptySearchQuerySet diff --git a/conference/views.py b/conference/views.py index bbbc63c6..c5a854e8 100644 --- a/conference/views.py +++ b/conference/views.py @@ -6,7 +6,8 @@ from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpRespons from django.contrib import messages from django.shortcuts import get_object_or_404 from django.contrib.contenttypes.models import ContentType -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView +from functions.custom_views import ListView from django.views.generic.edit import FormMixin from django.utils.translation import ugettext as _ from django.utils import translation diff --git a/core/views.py b/core/views.py index 0ec0cb16..1ad5be9a 100644 --- a/core/views.py +++ b/core/views.py @@ -3,7 +3,8 @@ from country.models import Country from city.models import City from place_exposition.models import PlaceExposition from place_conference.models import PlaceConference -from django.views.generic import ListView, CreateView, DeleteView, UpdateView, DetailView +from django.views.generic import CreateView, DeleteView, UpdateView, DetailView +from functions.custom_views import ListView from django.core.urlresolvers import reverse_lazy from functions.views_help import split_params from django.utils.translation import ugettext as _ diff --git a/exposition/views.py b/exposition/views.py index fa7eff6a..b35e42a6 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -4,7 +4,8 @@ import datetime from django.http import HttpResponseRedirect, HttpResponse, HttpResponsePermanentRedirect from django.contrib.contenttypes.models import ContentType from django.conf import settings -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView +from functions.custom_views import ListView from django.utils.translation import ugettext as _ from django.shortcuts import get_object_or_404 from django.http import Http404 diff --git a/functions/custom_views.py b/functions/custom_views.py index dfbc9071..781626cc 100644 --- a/functions/custom_views.py +++ b/functions/custom_views.py @@ -18,9 +18,23 @@ from hvad.utils import get_translation_aware_manager #python import random +from django.views.generic import ListView as OldListView -from country.models import Country - +class ListView(OldListView): + """ + List of modules, where overrided ListView is used: + - accounts.views + - article.views + - company.views + - conference.views + - core.views + - exposition.views + - photologue.views + - place_exposition.views + - specialist_catalog.views + - translator.views + """ + paginator_class = settings.DEFAULT_PAGINATOR @login_required def filtered_list(request, objects, template, item_per_page=settings.ADMIN_PAGINATION): @@ -186,7 +200,7 @@ def delete_object(request, Model, Form, url, prev_page,): return render_to_response('delete.html', args) #-----class------------------ -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView from functions.views_help import split_params from city.models import City diff --git a/functions/overrides.py b/functions/overrides.py new file mode 100644 index 00000000..8a132cb7 --- /dev/null +++ b/functions/overrides.py @@ -0,0 +1,19 @@ +from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage + +class SeoPaginator(Paginator): + + def validate_number(self, number): + "Validates the given 1-based page number." + try: + number = int(number) + except (TypeError, ValueError): + raise PageNotAnInteger('That page number is not an integer') + if number < 1: + raise EmptyPage('That page number is less than 1') + if number > self.num_pages: + if number == 1 and self.allow_empty_first_page: + pass + else: + number = 1 + return number + diff --git a/photologue/views.py b/photologue/views.py index a0ebb335..fb2e9589 100644 --- a/photologue/views.py +++ b/photologue/views.py @@ -3,7 +3,7 @@ import warnings from django.conf import settings from django.views.generic.dates import ArchiveIndexView, DateDetailView, DayArchiveView, MonthArchiveView, YearArchiveView from django.views.generic.detail import DetailView -from django.views.generic.list import ListView +from functions.custom_views import ListView from .models import Photo, Gallery # Number of galleries to display per page. diff --git a/place_exposition/views.py b/place_exposition/views.py index a40f28d7..ba8f939a 100644 --- a/place_exposition/views.py +++ b/place_exposition/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from django.shortcuts import render_to_response -from django.views.generic import ListView, DetailView, FormView +from django.views.generic import DetailView, FormView +from functions.custom_views import ListView from django.utils import translation from django.http import HttpResponseRedirect, HttpResponse from django.template import RequestContext diff --git a/proj/settings.py b/proj/settings.py index 9fdca037..f7fb9c17 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -422,10 +422,14 @@ THUMBNAIL_DEBUG = DEBUG CALLBACK_EMAIL = 'kotzilla@ukr.net' BOOKING_AID = '333667' - - +try: + from functions.overrides import SeoPaginator as Paginator +except ImportError: + from django.core.paginator import Paginator +DEFAULT_PAGINATOR = Paginator ADMIN_PAGINATION = 20 CLIENT_PAGINATION = 15 + TEMPLATE_DEBUG = DEBUG NO_LOGO = '/static/client/img/no-logo.png' @@ -504,4 +508,6 @@ if DEBUG: # 'INTERCEPT_REDIRECTS': False, #} -""" \ No newline at end of file +""" + +# -- PAGINATION -- # diff --git a/specialist_catalog/views.py b/specialist_catalog/views.py index 49ff483d..c3a17a20 100644 --- a/specialist_catalog/views.py +++ b/specialist_catalog/views.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -from django.views.generic import CreateView, UpdateView, DeleteView, ListView, FormView, DetailView +from django.views.generic import CreateView, UpdateView, DeleteView, FormView, DetailView +from functions.custom_views import ListView from django.views.generic.detail import SingleObjectMixin from django.utils.translation import ugettext as _ from .forms import * @@ -11,6 +12,8 @@ from django.http import HttpResponseRedirect, Http404 from .models import _city, _country + + # =========== ADMIN VIEWS =========== # Specialist views @@ -70,11 +73,12 @@ class CatalogCreateView(CreateView): success_url = reverse_lazy("catalog_all") + class CatalogListView(ListView): model = SpecialistCatalog template_name = 'admin/specialist/catalog_all.html' paginate_by = settings.ADMIN_PAGINATION - + paginator_class = settings.DEFAULT_PAGINATOR def get_queryset(self): _GET = self.request.GET query, city, country, only_cntry = _GET.get('query'), _GET.get('city'), _GET.get('country'), _GET.get('only_countries') diff --git a/translator/views.py b/translator/views.py index a6884462..30d277c5 100644 --- a/translator/views.py +++ b/translator/views.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView +from functions.custom_views import ListView from django.shortcuts import get_object_or_404 from django.views.generic.detail import SingleObjectMixin from django.utils.translation import ugettext as _