Source

django-endless-pagination-de / doc / usage.html

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
<title>Endless Pagination</title>
<style type="text/css">

/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:Date: $Date: 2005-05-26 12:51:39 +0200 (Thu, 26 May 2005) $
:Version: $Revision: 3368 $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
*/

/* "! important" is used here to override other ``margin-top`` and
   ``margin-bottom`` styles that are later in the stylesheet or 
   more specific.  See http://www.w3.org/TR/CSS1#the-cascade */
.first {
  margin-top: 0 ! important }

.last, .with-subtitle {
  margin-bottom: 0 ! important }

.hidden {
  display: none }

a.toc-backref {
  text-decoration: none ;
  color: black }

a[href]:hover {
  text-decoration: underline;
  color: blue;
}

blockquote.epigraph {
  margin: 2em 5em ; }

dl.docutils dd {
  margin-bottom: 0.5em }

/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
  font-weight: bold }
*/

div.abstract {
  margin: 2em 5em }

div.abstract p.topic-title {
  font-weight: bold ;
  text-align: center }

div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
  margin: 2em ;
  border: medium outset ;
  padding: 1em }

div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
  font-weight: bold ;
  font-family: sans-serif }

div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
  color: red ;
  font-weight: bold ;
  font-family: sans-serif }

/* Uncomment (and remove this text!) to get reduced vertical space in
   compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
  margin-bottom: 0.5em }

div.compound .compound-last, div.compound .compound-middle {
  margin-top: 0.5em }
*/

div.dedication {
  margin: 2em 5em ;
  text-align: center ;
  font-style: italic }

div.dedication p.topic-title {
  font-weight: bold ;
  font-style: normal }

div.figure {
  margin-left: 2em }

div.footer, div.header {
  font-size: smaller }

div.line-block {
  display: block ;
  margin-top: 1em ;
  margin-bottom: 1em }

div.line-block div.line-block {
  margin-top: 0 ;
  margin-bottom: 0 ;
  margin-left: 1.5em }

div.sidebar {
  margin-left: 1em ;
  border: medium outset ;
  padding: 1em ;
  background-color: #ffffee ;
  width: 40% ;
  float: right ;
  clear: right }

div.sidebar p.rubric {
  font-family: sans-serif ;
  font-size: medium }

div.system-messages {
  margin: 5em }

div.system-messages h1 {
  color: red }

div.system-message {
  border: medium outset ;
  padding: 1em }

div.system-message p.system-message-title {
  color: red ;
  font-weight: bold }

div.topic {
  margin: 2em }

h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
  margin-top: 0.4em }

h1.title {
  text-align: center }

h2.subtitle {
  text-align: center }

hr.docutils {
  width: 75% }

ol.simple, ul.simple {
  margin-bottom: 1em }

ol.arabic {
  list-style: decimal }

ol.loweralpha {
  list-style: lower-alpha }

ol.upperalpha {
  list-style: upper-alpha }

ol.lowerroman {
  list-style: lower-roman }

ol.upperroman {
  list-style: upper-roman }

p.attribution {
  text-align: right ;
  margin-left: 50% }

p.caption {
  font-style: italic }

p.credits {
  font-style: italic ;
  font-size: smaller }

p.label {
  white-space: nowrap }

p.rubric {
  font-weight: bold ;
  font-size: larger ;
  color: maroon ;
  text-align: center }

p.sidebar-title {
  font-family: sans-serif ;
  font-weight: bold ;
  font-size: larger }

p.sidebar-subtitle {
  font-family: sans-serif ;
  font-weight: bold }

p.topic-title {
  font-weight: bold }

pre.address {
  margin-bottom: 0 ;
  margin-top: 0 ;
  font-family: serif ;
  font-size: 100% }

pre.line-block {
  font-family: serif ;
  font-size: 100% }

pre.literal-block, pre.doctest-block {
  margin-left: 2em ;
  margin-right: 2em ;
  background-color: #eeeeee }

span.classifier {
  font-family: sans-serif ;
  font-style: oblique }

span.classifier-delimiter {
  font-family: sans-serif ;
  font-weight: bold }

span.interpreted {
  font-family: sans-serif }

span.option {
  white-space: nowrap }

span.pre {
  white-space: pre }

span.problematic {
  color: red }

span.section-subtitle {
  /* font-size relative to parent (<h#> element) */
  font-size: 80% }

table.citation {
  border-left: solid thin gray }

table.docinfo {
  margin: 2em 4em }

table.docutils {
  margin-top: 0.5em ;
  margin-bottom: 0.5em }

table.footnote {
  border-left: solid thin black }

table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
  padding-left: 0.5em ;
  padding-right: 0.5em ;
  vertical-align: top }

table.docutils th.field-name, table.docinfo th.docinfo-name {
  font-weight: bold ;
  text-align: left ;
  white-space: nowrap ;
  padding-left: 0 }

h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
  font-size: 100% }

/*
tt.docutils {
  background-color: #eeeeee }
*/

ul.auto-toc {
  list-style-type: none }

</style>
</head>
<body>
<div class="document" id="endless-pagination">
<h1 class="title">Endless Pagination</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr class="field"><th class="docinfo-name">Author:</th><td class="field-body">Francesco Banconi &lt;<a class="reference external" href="mailto:francesco.banconi&#64;gmail.com">francesco.banconi&#64;gmail.com</a>&gt;</td>
</tr>
</tbody>
</table>
<div class="contents topic" id="index">
<p class="topic-title first">Index</p>
<ul class="auto-toc simple">
<li><a class="reference internal" href="#introduction" id="id1">1   Introduction</a></li>
<li><a class="reference internal" href="#installation" id="id2">2   Installation</a><ul class="auto-toc">
<li><a class="reference internal" href="#requirements" id="id3">2.1   Requirements</a></li>
</ul>
</li>
<li><a class="reference internal" href="#usage" id="id4">3   Usage</a><ul class="auto-toc">
<li><a class="reference internal" href="#settings" id="id5">3.1   Settings</a></li>
<li><a class="reference internal" href="#let-s-start" id="id6">3.2   Let's start</a></li>
<li><a class="reference internal" href="#split-the-template" id="id7">3.3   Split the template</a></li>
<li><a class="reference internal" href="#a-shortcut-for-ajaxed-views" id="id8">3.4   A shortcut for ajaxed views</a></li>
<li><a class="reference internal" href="#pagination" id="id9">3.5   Pagination</a></li>
</ul>
</li>
<li><a class="reference internal" href="#digg-style-pagination" id="id10">4   Digg-style pagination</a><ul class="auto-toc">
<li><a class="reference internal" href="#adding-ajax" id="id11">4.1   Adding ajax</a></li>
</ul>
</li>
<li><a class="reference internal" href="#multiple-pagination-in-the-same-page" id="id12">5   Multiple pagination in the same page</a><ul class="auto-toc">
<li><a class="reference internal" href="#adding-ajax-for-multiple-pagination" id="id13">5.1   Adding ajax for multiple pagination</a></li>
</ul>
</li>
<li><a class="reference internal" href="#templatetags-reference" id="id14">6   Templatetags reference</a><ul class="auto-toc">
<li><a class="reference internal" href="#paginate" id="id15">6.1   paginate</a></li>
<li><a class="reference internal" href="#show-more" id="id16">6.2   show_more</a></li>
<li><a class="reference internal" href="#get-pages" id="id17">6.3   get_pages</a></li>
<li><a class="reference internal" href="#show-pages" id="id18">6.4   show_pages</a></li>
<li><a class="reference internal" href="#show-current-number" id="id19">6.5   show_current_number</a></li>
</ul>
</li>
<li><a class="reference internal" href="#customization" id="id20">7   Customization</a><ul class="auto-toc">
<li><a class="reference internal" href="#template-and-css" id="id21">7.1   Template and css</a></li>
</ul>
</li>
<li><a class="reference internal" href="#related-projects" id="id22">8   Related projects</a></li>
</ul>
</div>
<div class="section" id="introduction">
<h1>1   Introduction</h1>
<p>This app can be used to provide ajaxed Twitter-style or Digg-style pagination.</p>
<p>The initial idea, which has guided the development of this application,
is to allow ajax pagination of web contents in very few steps, as done by
the excellent tool <em>django-pagination</em>
(see <a class="reference external" href="http://github.com/ericflo/django-pagination/tree/master">http://github.com/ericflo/django-pagination/tree/master</a>).</p>
</div>
<div class="section" id="installation">
<h1>2   Installation</h1>
<p>The <tt class="docutils literal">endless_pagination</tt> package, included in the distribution, should be
placed on the <em>Python path</em>.</p>
<p>Or just <tt class="docutils literal">easy_install <span class="pre">django-endless-pagination</span></tt>.</p>
<div class="section" id="requirements">
<h2>2.1   Requirements</h2>
<ul class="simple">
<li>Python &gt;= 2.5</li>
<li>Django &gt;= 1.0</li>
<li>jQuery &gt;= 1.3</li>
</ul>
</div>
</div>
<div class="section" id="usage">
<h1>3   Usage</h1>
<div class="section" id="settings">
<h2>3.1   Settings</h2>
<p>Add the request context processor in your <em>settings.py</em>, e.g.:</p>
<pre class="literal-block">
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
     'django.core.context_processors.request',
)
</pre>
<p>Add <tt class="docutils literal">'endless_pagination'</tt> to the <tt class="docutils literal">INSTALLED_APPS</tt> in your <em>settings.py</em>.</p>
<p>See <em>Customization</em> section in this documentation for other settings options.</p>
</div>
<div class="section" id="let-s-start">
<h2>3.2   Let's start</h2>
<p>As creative example, the developer wants pagination of entries of a blog post.</p>
<p>In <em>views.py</em> we have:</p>
<pre class="literal-block">
def entry_index(request, template=&quot;myapp/entry_index.html&quot;):
    context = {
        'objects': Entry.objects.all(),
    }
    return render_to_response(template, context,
        context_instance=RequestContext(request))
</pre>
<p>In <em>myapp/entry_index.html</em>:</p>
<pre class="literal-block">
&lt;h2&gt;Entries:&lt;/h2&gt;
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
</pre>
</div>
<div class="section" id="split-the-template">
<h2>3.3   Split the template</h2>
<p>A response to an AJAX request should not return the entire template,
but only the portion of the page to update or add.
So it is convenient to extrapolate from the template the part containing entries
and use the new one to render the context if the request is AJAX.
The main template will include the other, so it is convenient to put
the page template in the context.</p>
<p><em>views.py</em> becomes:</p>
<pre class="literal-block">
def entry_index(request,
    template=&quot;myapp/entry_index.html&quot;,
    page_template=&quot;myapp/entry_index_page.html&quot;):
    context = {
        'objects': Entry.objects.all(),
        'page_template': page_template,
    }
    if request.is_ajax():
        template = page_template
    return render_to_response(template, context,
        context_instance=RequestContext(request))
</pre>
<p>See below how to obtain the same result <strong>just decorating the view</strong>
(in a way compatible with generic views too).</p>
<p><em>myapp/entry_index.html</em> becomes:</p>
<pre class="literal-block">
&lt;h2&gt;Entries:&lt;/h2&gt;
{% include page_template %}
</pre>
<p><em>myapp/entry_index_page.html</em> becomes:</p>
<pre class="literal-block">
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
</pre>
</div>
<div class="section" id="a-shortcut-for-ajaxed-views">
<h2>3.4   A shortcut for ajaxed views</h2>
<p>A good practice in writing views is to allow other developers to inject
the template name and extra data to be added to the context.
This allows the view to be easily reused. Let's resume the original view
with extra context injection:</p>
<p><em>views.py</em>:</p>
<pre class="literal-block">
def entry_index(request, template=&quot;myapp/entry_index.html&quot;,
    extra_context=None):
    context = {
        'objects': Entry.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(template, context,
        context_instance=RequestContext(request))
</pre>
<p>Splitting templates and putting the ajax template name in the context
is easily achievable at this point (using a builtin decorator).</p>
<p><em>views.py</em> becomes:</p>
<pre class="literal-block">
from endless_pagination.decorators import page_template

&#64;page_template(&quot;myapp/entry_index_page.html&quot;) # just add this decorator
def entry_index(request, template=&quot;myapp/entry_index.html&quot;,
    extra_context=None):
    context = {
        'objects': Entry.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(template, context,
        context_instance=RequestContext(request))
</pre>
<p>This way, <em>endless-pagination</em> can be included in <strong>generic views</strong> too.</p>
</div>
<div class="section" id="pagination">
<h2>3.5   Pagination</h2>
<p>Nothing remains but to change the page template, loading endless templatetags,
the jQuery library and the javascript file <em>endless.js</em> included
in the distribution under <tt class="docutils literal">/media/js/</tt>.</p>
<p><em>myapp/entry_index.html</em> becomes:</p>
<pre class="literal-block">
{% block js %}
    {{ block.super }}
    &lt;script src=&quot;/path/to/jquery.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;/path/to/endless.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
{% endblock %}

&lt;h2&gt;Entries:&lt;/h2&gt;
{% include page_template %}
</pre>
<p><em>myapp/entry_index_page.html</em> becomes:</p>
<pre class="literal-block">
{% load endless %}

{% paginate objects %}
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_more %}
</pre>
<p>That's all. Read the next section of the documentation to improve the use of
included templatetags.</p>
</div>
</div>
<div class="section" id="digg-style-pagination">
<h1>4   Digg-style pagination</h1>
<p>Digg-style pagination of queryset objects is really easy to implement.
If AJAX pagination is not needed, all you have to do is modify the template, e.g.:</p>
<pre class="literal-block">
{% load endless %}

{% paginate objects %}
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_pages %}
</pre>
<p>That's it!
If you want to display only previous and next links (in a page-by-page pagination)
you need to use the lower level <em>get_pages</em> templatetag (see reference below),
e.g.:</p>
<pre class="literal-block">
{% load endless %}

{% paginate objects %}
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
{% get_pages %}
{{ pages.previous }} {{ pages.next }}
</pre>
<p>See the paragraph <em>Customization</em> that explains how to customize arrows
of previous and next pages.</p>
<div class="section" id="adding-ajax">
<h2>4.1   Adding ajax</h2>
<p>The view is exactly the same as in <em>show_more</em> twitter-style pagination:</p>
<pre class="literal-block">
from endless_pagination.decorators import page_template

&#64;page_template(&quot;myapp/entry_index_page.html&quot;) # just add this decorator
def entry_index(request, template=&quot;myapp/entry_index.html&quot;,
    extra_context=None):
    context = {
        'objects': Entry.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(template, context,
        context_instance=RequestContext(request))
</pre>
<p>Of course you have to split templates, but this time a container for
page template is needed too, and must have a class named <em>endless_page_template</em>.</p>
<p><em>myapp/entry_index.html</em> becomes:</p>
<pre class="literal-block">
{% block js %}
    {{ block.super }}
    &lt;script src=&quot;/path/to/jquery.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;/path/to/endless.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
{% endblock %}

&lt;h2&gt;Entries:&lt;/h2&gt;
&lt;div class=&quot;endless_page_template&quot;&gt;
    {% include page_template %}
&lt;/div&gt;
</pre>
<p><em>myapp/entry_index_page.html</em> becomes:</p>
<pre class="literal-block">
{% load endless %}

{% paginate objects %}
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_pages %}
</pre>
<p>Done.</p>
</div>
</div>
<div class="section" id="multiple-pagination-in-the-same-page">
<h1>5   Multiple pagination in the same page</h1>
<p><strong>New in version 0.4</strong></p>
<p>Sometimes it is necessary to show different types of paginated objects in the
same page. In this case we have to associate to every pagination a different
querystring key.
Normally, the key used is the one specified in <em>ENDLESS_PAGINATION_PAGE_LABEL</em>,
but in the case of multiple pagination the application provides a simple way to
override the settings.
If you do not need ajax, the only file you need to edit
is the template. Here is a usecase example with 2 different paginations
(<em>objects</em> and <em>other_objects</em>) in the same page, but there is no limit to the
number of different paginations in a page:</p>
<pre class="literal-block">
{% load endless %}

{% paginate objects %}
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_pages %}

{% paginate other_objects using other_objects_page %} {# &lt;-- a new querystring key #}
{% for object in other_objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_pages %}
</pre>
<p>The <em>using</em> argument of the <em>paginate</em> template tag allows you to choose the
name of the querystring key used to track the page number.
If not specified the system falls back to <em>settings.ENDLESS_PAGINATION_PAGE_LABEL</em>.
In the example above, the url <em>http://example.com?page=2&amp;other_objects_page=3</em>
requests the second page of <em>objects</em> and the third page of <em>other_objects</em>.</p>
<p>You can use any style of pagination: <em>show_pages</em>, <em>get_pages</em>, <em>show_more</em> etc...</p>
<div class="section" id="adding-ajax-for-multiple-pagination">
<h2>5.1   Adding ajax for multiple pagination</h2>
<p>Obviously each pagination needs a template for the page content.
Remember to box each page in a div with a class called <em>endless_page_template</em>.</p>
<p><em>myapp/entry_index.html</em>:</p>
<pre class="literal-block">
{% block js %}
    {{ block.super }}
    &lt;script src=&quot;/path/to/jquery.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;/path/to/endless.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
{% endblock %}

&lt;h2&gt;Entries:&lt;/h2&gt;
&lt;div class=&quot;endless_page_template&quot;&gt;
    {% include &quot;myapp/entries_page.html&quot; %}
&lt;/div&gt;

&lt;h2&gt;Other entries:&lt;/h2&gt;
&lt;div class=&quot;endless_page_template&quot;&gt;
    {% include &quot;myapp/other_entries_page.html&quot; %}
&lt;/div&gt;
</pre>
<p><em>myapp/entries_page.html</em>:</p>
<pre class="literal-block">
{% load endless %}

{% paginate objects %}
{% for object in objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_pages %}
</pre>
<p><em>myapp/other_entries_page.html</em>:</p>
<pre class="literal-block">
{% load endless %}

{% paginate other_objects using other_objects_page %}
{% for object in other_objects %}
    {# your code to show the entry #}
{% endfor %}
{% show_pages %}
</pre>
<p>Again the decorator <em>page_template</em> simplifies the management of ajax requests
in views. You must, however, map different paginations to different page templates.
You can chain decorator's calls relating a template with the associated
querystring key, e.g.:</p>
<pre class="literal-block">
from endless_pagination.decorators import page_template

&#64;page_template(&quot;myapp/entries_page.html&quot;)
&#64;page_template(&quot;myapp/other_entries_page.html&quot;, key=&quot;other_objects_page&quot;)
def entry_index(request, template=&quot;myapp/entry_index.html&quot;,
    extra_context=None):
    context = {
        'objects': Entry.objects.all(),
        'other_objects': OtherEntry.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(template, context,
        context_instance=RequestContext(request))
</pre>
<p>As seen in previous examples, if you do not specify the <em>key</em> kwarg in the
decorator, then the page template is associated to the querystring key
defined in the settings.</p>
<p>You can use the <em>page_templates</em> (note the trailing <em>s</em>) decorator in
substitution of a decorator chain when you need multiple ajax pagination.
The previous example can be written:</p>
<pre class="literal-block">
from endless_pagination.decorators import page_templates

&#64;page_templates({
    &quot;myapp/entries_page.html&quot;: None,
    &quot;myapp/other_entries_page.html&quot;: &quot;other_objects_page&quot;,
})
def entry_index() ...
</pre>
</div>
</div>
<div class="section" id="templatetags-reference">
<h1>6   Templatetags reference</h1>
<div class="section" id="paginate">
<h2>6.1   paginate</h2>
<p>Usage:</p>
<pre class="literal-block">
{% paginate objects %}
</pre>
<p>After this call, in the template context the <em>objects</em> variable is replaced
with only the objects of the current page.</p>
<p>You can also mantain your <em>objects</em> original variable (commonly a queryset)
and add to context another name referring to objects of the current page,
e.g.:</p>
<pre class="literal-block">
{% paginate objects as page_objects %}
</pre>
<p>The number of paginated object is taken from settings, but you can
override the default, e.g.:</p>
<pre class="literal-block">
{% paginate 20 objects %}
</pre>
<p>Of course you can mix it all:</p>
<pre class="literal-block">
{% paginate 20 objects as paginated_objects %}
</pre>
<p>By default, the first page is displayed the first time you load the page,
but you can easily change this, e.g.:</p>
<pre class="literal-block">
{% paginate objects starting from page 3 %}
</pre>
<p>This can be also achieved using a template variable you passed in the
context, e.g.:</p>
<pre class="literal-block">
{% paginate objects starting from page page_number %}
</pre>
<p>If the passed page number does not exist then first page is displayed.</p>
<p>If you have multiple paginations in the same page, you can change the
querydict key for the single pagination, e.g.:</p>
<pre class="literal-block">
{% paginate objects using article_page %}
</pre>
<p>Again, you can mix it all (the order of arguments is important):</p>
<pre class="literal-block">
{% paginate 20 objects starting from page 3 using page_key as paginated_objects %}
</pre>
<p>You must use this tag before calling the {% show_more %} one.</p>
</div>
<div class="section" id="show-more">
<h2>6.2   show_more</h2>
<p>Show the link to get the next page in a Twitter-like pagination.
Usage:</p>
<pre class="literal-block">
{% show_more %}
</pre>
<p>Must be called after <tt class="docutils literal">{% paginate objects %}</tt>.</p>
</div>
<div class="section" id="get-pages">
<h2>6.3   get_pages</h2>
<p>Usage:</p>
<pre class="literal-block">
{% get_pages %}
</pre>
<p>This is mostly used for digg-style pagination.
This call inserts in the template context a <em>pages</em> variable, as a sequence
of page links. You can use <em>pages</em> in different ways:</p>
<p>just print <em>pages</em> and you will get digg-style pagination displayed:</p>
<pre class="literal-block">
{{ pages }}
</pre>
<p>display pages count:</p>
<pre class="literal-block">
{{ pages|length }}
</pre>
<p>get a specific page:</p>
<pre class="literal-block">
{# the current selected page #}
{{ pages.current }}

{# the first page #}
{{ pages.first }}

{# the last page #}
{{ pages.last }}

{# the previous page (or nothing if you are on first page) #}
{{ pages.previous }}

{# the next page (or nothing if you are in last page) #}
{{ pages.next }}

{# the third page #}
{{ pages.3 }}
{# this means page.1 is the same as page.first #}
</pre>
<p>iterate over <em>pages</em> to get all pages:</p>
<pre class="literal-block">
{% for page in pages %}
    {# display page link #}
    {{ page }}

    {# the page url (beginning with &quot;?&quot;) #}
    {{ page.url }}

    {# the page path #}
    {{ page.path }}

    {# the page number #}
    {{ page.number }}

    {# a string representing the page (commonly the page number) #}
    {{ page.label }}

    {# check if the page is the current one #}
    {{ page.is_current }}

    {# check if the page is the first one #}
    {{ page.is_first }}

    {# check if the page is the last one #}
    {{ page.is_last }}
{% endfor %}
</pre>
<p>You can change the variable name, e.g.:</p>
<pre class="literal-block">
{% get_pages as page_links %}
</pre>
<p>Must be called after <tt class="docutils literal">{% paginate objects %}</tt>.</p>
</div>
<div class="section" id="show-pages">
<h2>6.4   show_pages</h2>
<p>Show page links.
Usage:</p>
<pre class="literal-block">
{% show_pages %}
</pre>
<p>It is only a shortcut for:</p>
<pre class="literal-block">
{% get_pages %}
{{ pages }}
</pre>
<p>You can set <em>ENDLESS_PAGE_LIST_CALLABLE</em> in your settings.py as a callable
used to customize the pages that are displayed.
The callable takes the current page number and the total number of pages
and must return a sequence of page numbers that will be displayed.
The sequence can contain other values:</p>
<blockquote>
<ul class="simple">
<li><em>&quot;previous&quot;</em>: will display the previous page in that position</li>
<li><em>&quot;next&quot;</em>: will display the next page in that position</li>
<li><em>None</em>: a separator will be displayed in that position</li>
</ul>
</blockquote>
<p>Here is an example of custom callable that displays previous page, then
first page, then a separator, then current page, then next page:</p>
<pre class="literal-block">
def get_page_numbers(current_page, num_pages):
    return (&quot;previous&quot;, 1, &quot;...&quot;, current_page, &quot;next&quot;)
</pre>
<p>If <em>ENDLESS_PAGE_LIST_CALLABLE</em> is <em>None</em> an internal callable is used,
generating a digg-style pagination.</p>
<p>Must be called after <tt class="docutils literal">{% paginate objects %}</tt>.</p>
</div>
<div class="section" id="show-current-number">
<h2>6.5   show_current_number</h2>
<p>Just show current page number (useful in page titles).
Usage:</p>
<pre class="literal-block">
{% show_current_number %}
</pre>
<p>If you use multiple paginations in the same page you can get the page
number for a specific pagination using the querystring key, e.g.:</p>
<pre class="literal-block">
{% show_current_number using mykey %}
</pre>
<p>Default page when no querystring is specified is 1. If you changed in the
<em>paginate</em> template tag, you have to call  <em>show_current_number</em>
according to your choice, e.g.:</p>
<pre class="literal-block">
{% show_current_number starting from page 3 %}
</pre>
<p>This can be also achieved using a template variable you passed in the
context, e.g.:</p>
<pre class="literal-block">
{% show_current_number starting from page page_number %}
</pre>
<p>Of course, you can mix it all (the order of arguments is important):</p>
<pre class="literal-block">
{% show_current_number starting from page 3 using mykey %}
</pre>
</div>
</div>
<div class="section" id="customization">
<h1>7   Customization</h1>
<p>You can customize the application using <tt class="docutils literal">settings.py</tt>.</p>
<ul class="simple">
<li><em>ENDLESS_PAGINATION_PER_PAGE</em> (default=10):
How many objects are normally displayed in a page (overwriteable by templatetag).</li>
<li><em>ENDLESS_PAGINATION_PAGE_LABEL</em> (default=&quot;page&quot;):
The querystring key of the page number (e.g. <tt class="docutils literal"><span class="pre">http://example.com?page=2</span></tt>)</li>
<li><em>ENDLESS_PAGINATION_ORPHANS</em> (default=0):
See django <em>Paginator</em> definition of orphans.</li>
<li><em>ENDLESS_PAGINATION_LOADING</em> (default=&quot;loading&quot;):
If you use the default <em>show_more</em> template, here you can customize
the content of the loader hidden element
Html is safe here, e.g. you can show your pretty animated gif</li>
</ul>
<pre class="literal-block">
ENDLESS_PAGINATION_LOADING = &quot;&quot;&quot;
    &lt;img src=&quot;/site_media/img/loader.gif&quot; alt=&quot;loading&quot; /&gt;
&quot;&quot;&quot;
</pre>
<ul>
<li><p class="first"><em>ENDLESS_PAGINATION_PREVIOUS_LABEL</em> (default=u&quot;&amp;lt;&amp;lt;&quot;) and <em>NEXT_LABEL</em> (default=u&quot;&amp;gt;&amp;gt;&quot;):
Labels for previous and next page links.</p>
</li>
<li><p class="first"><em>ENDLESS_PAGINATION_ADD_NOFOLLOW</em> (default=False):  #
Set to True if your seo alchemist wants search engines not to follow
pagination links.</p>
</li>
<li><p class="first"><em>ENDLESS_PAGINATION_PAGE_LIST_CALLABLE</em> (default=None):
Callable that returns pages to be displayed.
If None a default callable is used (that produces digg-style pagination).</p>
<p>Default callable returns pages for digg-style pagination, and depends
on the settings below:</p>
</li>
<li><p class="first"><em>ENDLESS_PAGINATION_DEFAULT_CALLABLE_EXTREMES</em> (default=3)</p>
</li>
<li><p class="first"><em>ENDLESS_PAGINATION_DEFAULT_CALLABLE_AROUNDS</em> (default=2)</p>
</li>
<li><p class="first"><em>ENDLESS_PAGINATION_TEMPLATE_VARNAME</em> (default=&quot;template&quot;):
Template variable name used by <em>page_template</em> decorator.</p>
</li>
</ul>
<div class="section" id="template-and-css">
<h2>7.1   Template and css</h2>
<p>You can override the default template for <em>show_more</em> templatetag following
some rules:</p>
<ul class="simple">
<li><em>more</em> link is showed only if variable <tt class="docutils literal">querystring</tt> is not False</li>
<li>the container (most external html element) class is <em>endless_container</em></li>
<li>the <em>more</em> link and the loader hidden element live inside the container</li>
<li>the <em>more</em> link class is <em>endless_more</em></li>
<li>the <em>more</em> link rel attribute is <em>{{ querystring_key }}</em></li>
<li>the loader hidden element class is <em>endless_loading</em></li>
</ul>
<p>Application comes with English and Italian i18n.</p>
</div>
</div>
<div class="section" id="related-projects">
<h1>8   Related projects</h1>
<p>Try out <a class="reference external" href="http://code.google.com/p/django-yafinder/">http://code.google.com/p/django-yafinder/</a> if you need to add filter
and sort capabilities to your index page.</p>
</div>
</div>
</body>
</html>