From: Zygmunt Krynicki Date: Tue, 14 Jun 2011 09:21:54 +0000 (+0200) Subject: PEP8 fixes X-Git-Tag: release-2.0~8 X-Git-Url: https://git.mdrn.pl/django-pagination.git/commitdiff_plain/301bedcc8073d960a6cb88515cabcc4e472be2a4?ds=sidebyside PEP8 fixes --- diff --git a/linaro_django_pagination/middleware.py b/linaro_django_pagination/middleware.py index ad00fb2..73d2713 100644 --- a/linaro_django_pagination/middleware.py +++ b/linaro_django_pagination/middleware.py @@ -1,11 +1,11 @@ # Copyright (c) 2008, Eric Florenzano # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR diff --git a/linaro_django_pagination/models.py b/linaro_django_pagination/models.py index 8b13789..e69de29 100644 --- a/linaro_django_pagination/models.py +++ b/linaro_django_pagination/models.py @@ -1 +0,0 @@ - diff --git a/linaro_django_pagination/paginator.py b/linaro_django_pagination/paginator.py index 69d5a86..cd3a0f7 100644 --- a/linaro_django_pagination/paginator.py +++ b/linaro_django_pagination/paginator.py @@ -1,11 +1,11 @@ # Copyright (c) 2008, Eric Florenzano # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -35,8 +35,8 @@ from django.core.paginator import Paginator, Page, PageNotAnInteger, EmptyPage class InfinitePaginator(Paginator): """ Paginator designed for cases when it's not important to know how many total - pages. This is useful for any object_list that has no count() method or can - be used to improve performance for MySQL by removing counts. + pages. This is useful for any object_list that has no count() method or + can be used to improve performance for MySQL by removing counts. The orphans parameter has been removed for simplicity and there's a link template string for creating the links to the next and previous pages. @@ -44,7 +44,7 @@ class InfinitePaginator(Paginator): def __init__(self, object_list, per_page, allow_empty_first_page=True, link_template='/page/%d/'): - orphans = 0 # no orphans + orphans = 0 # no orphans super(InfinitePaginator, self).__init__(object_list, per_page, orphans, allow_empty_first_page) # no count or num pages diff --git a/linaro_django_pagination/settings.py b/linaro_django_pagination/settings.py index 197ce06..ff74fd3 100644 --- a/linaro_django_pagination/settings.py +++ b/linaro_django_pagination/settings.py @@ -1,11 +1,11 @@ # Copyright (c) 2008, Eric Florenzano # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -32,14 +32,23 @@ from django.conf import settings -DEFAULT_PAGINATION = getattr(settings, 'PAGINATION_DEFAULT_PAGINATION', 20) -DEFAULT_WINDOW = getattr(settings, 'PAGINATION_DEFAULT_WINDOW', 4) -DEFAULT_MARGIN = getattr(settings, 'PAGINATION_DEFAULT_MARGIN', DEFAULT_WINDOW) -DEFAULT_ORPHANS = getattr(settings, 'PAGINATION_DEFAULT_ORPHANS', 0) -INVALID_PAGE_RAISES_404 = getattr(settings, - 'PAGINATION_INVALID_PAGE_RAISES_404', False) -DISPLAY_PAGE_LINKS = getattr(settings, 'PAGINATION_DISPLAY_PAGE_LINKS', True) -PREVIOUS_LINK_DECORATOR = getattr(settings, 'PAGINATION_PREVIOUS_LINK_DECORATOR', "‹‹ ") -NEXT_LINK_DECORATOR = getattr(settings, 'PAGINATION_NEXT_LINK_DECORATOR', " ››") -DISPLAY_DISABLED_PREVIOUS_LINK = getattr(settings, 'PAGINATION_DISPLAY_DISABLED_PREVIOUS_LINK', False) -DISPLAY_DISABLED_NEXT_LINK = getattr(settings, 'PAGINATION_DISPLAY_DISABLED_NEXT_LINK', False) +DEFAULT_PAGINATION = getattr( + settings, 'PAGINATION_DEFAULT_PAGINATION', 20) +DEFAULT_WINDOW = getattr( + settings, 'PAGINATION_DEFAULT_WINDOW', 4) +DEFAULT_MARGIN = getattr( + settings, 'PAGINATION_DEFAULT_MARGIN', DEFAULT_WINDOW) +DEFAULT_ORPHANS = getattr( + settings, 'PAGINATION_DEFAULT_ORPHANS', 0) +INVALID_PAGE_RAISES_404 = getattr( + settings, 'PAGINATION_INVALID_PAGE_RAISES_404', False) +DISPLAY_PAGE_LINKS = getattr( + settings, 'PAGINATION_DISPLAY_PAGE_LINKS', True) +PREVIOUS_LINK_DECORATOR = getattr( + settings, 'PAGINATION_PREVIOUS_LINK_DECORATOR', "‹‹ ") +NEXT_LINK_DECORATOR = getattr( + settings, 'PAGINATION_NEXT_LINK_DECORATOR', " ››") +DISPLAY_DISABLED_PREVIOUS_LINK = getattr( + settings, 'PAGINATION_DISPLAY_DISABLED_PREVIOUS_LINK', False) +DISPLAY_DISABLED_NEXT_LINK = getattr( + settings, 'PAGINATION_DISPLAY_DISABLED_NEXT_LINK', False) diff --git a/linaro_django_pagination/templatetags/__init__.py b/linaro_django_pagination/templatetags/__init__.py index 8b13789..e69de29 100644 --- a/linaro_django_pagination/templatetags/__init__.py +++ b/linaro_django_pagination/templatetags/__init__.py @@ -1 +0,0 @@ - diff --git a/linaro_django_pagination/templatetags/pagination_tags.py b/linaro_django_pagination/templatetags/pagination_tags.py index a78c790..815cb7f 100644 --- a/linaro_django_pagination/templatetags/pagination_tags.py +++ b/linaro_django_pagination/templatetags/pagination_tags.py @@ -1,11 +1,11 @@ # Copyright (c) 2008, Eric Florenzano # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -93,24 +93,23 @@ def do_autopaginate(parser, token): raise TemplateSyntaxError( "Invalid syntax. Proper usage of this tag is: " "{%% autopaginate QUERYSET [PAGINATE_BY] [ORPHANS]" - " [as CONTEXT_VAR_NAME] %%}" - ) + " [as CONTEXT_VAR_NAME] %%}") return AutoPaginateNode(queryset_var, multiple_paginations, paginate_by, orphans, context_var) class AutoPaginateNode(Node): """ Emits the required objects to allow for Digg-style pagination. - + First, it looks in the current context for the variable specified, and using - that object, it emits a simple ``Paginator`` and the current page object + that object, it emits a simple ``Paginator`` and the current page object into the context names ``paginator`` and ``page_obj``, respectively. - + It will then replace the variable specified with only the objects for the current page. - + .. note:: - + It is recommended to use *{% paginate %}* after using the autopaginate tag. If you choose not to use *{% paginate %}*, make sure to display the list of available pages, or else the application may seem to be buggy. @@ -138,7 +137,7 @@ class AutoPaginateNode(Node): page_suffix = '_%s' % self.queryset_var else: page_suffix = '' - + key = self.queryset_var.var value = self.queryset_var.resolve(context) if isinstance(self.paginate_by, int): @@ -179,23 +178,23 @@ class PaginateNode(Node): def __init__(self, template=None): self.template = template - + def render(self, context): template_list = ['pagination/pagination.html'] to_return = paginate(context) if self.template: template_list.insert(0, self.template) t = select_template(template_list) - if not t: + if not t: return None context = Context(to_return) return t.render(context) - + def do_paginate(parser, token): """ {% paginate [using] [template] %} - + {% paginate %} {% paginate using paginations/custom_pagination.html %} """ @@ -216,31 +215,31 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN): Digg-like display of the available pages, given the current page. If there are too many pages to be displayed before and after the current page, then elipses will be used to indicate the undisplayed gap between page numbers. - + Requires one argument, ``context``, which should be a dictionary-like data structure and must contain the following keys: - + ``paginator`` A ``Paginator`` or ``QuerySetPaginator`` object. - + ``page_obj`` - This should be the result of calling the page method on the + This should be the result of calling the page method on the aforementioned ``Paginator`` or ``QuerySetPaginator`` object, given the current page. - + This same ``context`` dictionary-like data structure may also include: - + ``getvars`` A dictionary of all of the **GET** parameters in the current request. This is useful to maintain certain types of state, even when requesting a different page. - + Argument ``window`` is number to pages before/after current page. If window exceeds pagination border (1 and end), window is moved to left or right. - Argument ``margin``` is number of pages on start/end of pagination. + Argument ``margin``` is number of pages on start/end of pagination. Example: - window=2, margin=1, current=6 1 ... 4 5 [6] 7 8 ... 11 + window=2, margin=1, current=6 1 ... 4 5 [6] 7 8 ... 11 window=2, margin=0, current=1 [1] 2 3 4 5 ... window=2, margin=0, current=5 ... 3 4 [5] 6 7 ... window=2, margin=0, current=11 ... 7 8 9 10 [11] diff --git a/linaro_django_pagination/test_project/example/urls.py b/linaro_django_pagination/test_project/example/urls.py index 015da39..f3fc5ae 100644 --- a/linaro_django_pagination/test_project/example/urls.py +++ b/linaro_django_pagination/test_project/example/urls.py @@ -1,10 +1,10 @@ # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -34,5 +34,4 @@ from django.conf.urls.defaults import ( urlpatterns = patterns( 'example.views', url(r'^list/$', 'list'), - url(r'^complex-list/$', 'complex_list'), -) + url(r'^complex-list/$', 'complex_list')) diff --git a/linaro_django_pagination/test_project/example/views.py b/linaro_django_pagination/test_project/example/views.py index ab7a66e..a2284d0 100644 --- a/linaro_django_pagination/test_project/example/views.py +++ b/linaro_django_pagination/test_project/example/views.py @@ -1,10 +1,10 @@ # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR diff --git a/linaro_django_pagination/test_project/manage.py b/linaro_django_pagination/test_project/manage.py index 564a5a4..cabc3de 100755 --- a/linaro_django_pagination/test_project/manage.py +++ b/linaro_django_pagination/test_project/manage.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR diff --git a/linaro_django_pagination/test_project/settings.py b/linaro_django_pagination/test_project/settings.py index 47da7e4..e0a3708 100644 --- a/linaro_django_pagination/test_project/settings.py +++ b/linaro_django_pagination/test_project/settings.py @@ -1,10 +1,10 @@ # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -42,15 +42,10 @@ locals().update( gen_settings( INSTALLED_APPS=[ 'example', - 'linaro_django_pagination', - ], + 'linaro_django_pagination'], MIDDLEWARE_CLASSES=[ - 'linaro_django_pagination.middleware.PaginationMiddleware', - ], + 'linaro_django_pagination.middleware.PaginationMiddleware'], TEMPLATE_CONTEXT_PROCESSORS=[ # Request processor needs to be enabled - 'django.core.context_processors.request' - ], - ROOT_URLCONF="linaro_django_pagination.test_project.urls" - ) -) + 'django.core.context_processors.request'], + ROOT_URLCONF="linaro_django_pagination.test_project.urls")) diff --git a/linaro_django_pagination/test_project/tests.py b/linaro_django_pagination/test_project/tests.py index 0950199..97e7e5d 100644 --- a/linaro_django_pagination/test_project/tests.py +++ b/linaro_django_pagination/test_project/tests.py @@ -1,10 +1,10 @@ # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR diff --git a/linaro_django_pagination/test_project/urls.py b/linaro_django_pagination/test_project/urls.py index fe86f74..cfdf466 100644 --- a/linaro_django_pagination/test_project/urls.py +++ b/linaro_django_pagination/test_project/urls.py @@ -1,10 +1,10 @@ # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -32,7 +32,4 @@ from django.conf.urls.defaults import ( patterns, url, include, handler500, handler404) # Empty patterns so that test project can be started and would work normally -urlpatterns = patterns( - '', - url('', include('example.urls')), -) +urlpatterns = patterns('', url('', include('example.urls'))) diff --git a/linaro_django_pagination/tests.py b/linaro_django_pagination/tests.py index c440339..00bfa6d 100644 --- a/linaro_django_pagination/tests.py +++ b/linaro_django_pagination/tests.py @@ -1,11 +1,11 @@ # Copyright (c) 2008, Eric Florenzano # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR diff --git a/setup.py b/setup.py index 2c23e80..f1ce26d 100755 --- a/setup.py +++ b/setup.py @@ -2,11 +2,11 @@ # Copyright (c) 2008, Eric Florenzano # Copyright (c) 2010, 2011 Linaro Limited # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: -# +# # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above @@ -16,7 +16,7 @@ # * Neither the name of the author nor the names of other # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR