# 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
# * 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
# 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
# * 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
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.
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
# 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
# * 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
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)
# 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
# * 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
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.
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):
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 %}
"""
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]
# 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
# * 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
urlpatterns = patterns(
'example.views',
url(r'^list/$', 'list'),
- url(r'^complex-list/$', 'complex_list'),
-)
+ url(r'^complex-list/$', 'complex_list'))
# 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
# * 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
#!/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
# * 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
# 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
# * 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
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"))
# 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
# * 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
# 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
# * 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
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')))
# 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
# * 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
# 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
# * 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