how to generate numbers for pagination?
<p>I made a function that returns the number displayed for pagination. I want to get something like this (parentheses is the only show where the active site):</p>

<p>if pages &lt; 10</p>

<pre><code>1 2 3 4 5 6 7 8 9 10
</code></pre>

<p>if pages > 10</p>

<pre><code>1 2 3 ... 20 [30] 40 ... 78 79 80
</code></pre>

<p>where [30] is active page. If active page &lt; 3</p>

<pre><code>1 2 [3] 4 ... 20 30 40 ... 78 79 80
</code></pre>

<p>etc. My code:</p>

<pre><code>    count_all - number of all items
    items_on_page - items displayed on one page
    page - current page

    countpages = int(float(count_all+(items_on_page-1))/float(items_on_page))
    linkitems = 10

    if countpages &gt; (linkitems-1):
        countpagesstr = list()
        for i in range(1,int(float(linkitems+(2))/float(3))):
            countpagesstr += [str(i)]

        countpagesstr += ['...']
        sr = int(countpages/2)
        for i in range(sr-1, sr+1):
            countpagesstr += [str(i)]

        countpagesstr += ['...']
        for i in range(countpages-3, countpages):
            countpagesstr += [str(i)]
    else:
        cp = list()
        for c in range(1,countpages+1):
            cp.append(str(c))
        countpagesstr = cp

    return countpagesstr
</code></pre>

<p>How to do it better?</p>
