Commits

Viorel Stirbu committed 3cece38

next/previous page and no link for current page

  • Participants
  • Parent commits 8c39961

Comments (0)

Files changed (2)

File atexpc/atex_web/templates/search.html

                     <div class="product-section">
                     	<span class="produse-gasite">Produsele de la {{ pagination.start }} la {{ pagination.stop }} din {{ pagination.total_count }} produse {% if category_name %}gasite in categoria <strong>{{ category_name }}</strong>{% endif %}</span>
                     	<div class="tab_d_holder_right">
-                        	<a class="prev"></a>
+                            {% if pagination.previous %}
+                                <a href="{{ pagination.previous.url }}" class="prev"></a>
+                            {% else %}
+                                <a class="prev"></a>
+                            {% endif %}
                                 <ul class="paginare">
                                     {% for page in pagination.pages %}
-                                    <li><a {% if page.is_current %}class="active"{% endif %} href="{{ page.url }}">{{ page.name }}</a></li>
+                                    <li>
+                                        {% if page.is_current %}
+                                        <a class="active">{{ page.name }}</a></li>
+                                        {% else %}
+                                        <a href="{{ page.url }}">{{ page.name }}</a></li>
+                                        {% endif %}
                                     {% endfor %}
                                 </ul>
-                            <a class="next"></a>
+                            {% if pagination.next %}
+                                <a href="{{ pagination.next.url }}" class="next"></a>
+                            {% else %}
+                                <a class="next"></a>
+                            {% endif %}
                         </div>
                     </div>
                 </div>

File atexpc/atex_web/views.py

     stop = min(stop, total_count)
 
     pages_count = int(math.ceil(float(total_count)/per_page))
-    pages = [{'name': number,
-              'url': _uri_with_args(base_url, pagina=number),
-              'is_current': number==current_page}
-             for number in range(1, pages_count + 1)]
+    page_info = lambda number: {
+        'name': number,
+        'url': _uri_with_args(base_url, pagina=number),
+        'is_current': number==current_page}
+    pages = [page_info(number) for number in range(1, pages_count + 1)]
+
+    previous_page = page_info(current_page - 1) if current_page > 1 else None
+    next_page = page_info(current_page + 1) if current_page < pages_count else None
 
     data['pagination'] = {'pages': pages,
+                          'previous': previous_page,
+                          'next': next_page,
                           'start': start,
                           'stop': stop,
                           'total_count': total_count}