Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Remove django-pagination dependency
Browse files Browse the repository at this point in the history
Replace django-pagination usage with "good old, boring pagination".
There's less magic (querysets have to be paginated manually by the
views), but the whole approach is simpler, requires less dependecies and
results in a net lines of code loss.
  • Loading branch information
Virgil Dupras committed Jan 13, 2016
1 parent 0925a1e commit 403ca3e
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 290 deletions.
12 changes: 5 additions & 7 deletions djangobb_forum/templates/djangobb_forum/delete_posts.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{% extends 'djangobb_forum/base.html' %}
{% load pagination_tags %}
{% load forum_extras %}
{% load i18n %}

{% block content %}
{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
<div class="linkst">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<ul><li><a href="{% url 'djangobb:index' %}">{% trans "Root" %} </a></li><li>&raquo; {% link topic.forum %} </li><li>&raquo; {{ topic }}
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}</div>
<ul><li><a href="{% url 'djangobb:index' %}">{% trans "Root" %} </a></li><li>&raquo; {% link topic.forum %} </li><li>&raquo; {{ topic }}
<a href="{% url 'djangobb:forum_topic_feed' topic.id %}"><img src="{{ STATIC_URL }}djangobb_forum/img/feed-icon-small.png" alt="[RSS Feed]" title="[RSS Feed]" style="vertical-align:middle;" /></a>
</li></ul>
<div class="clearer"></div>
Expand All @@ -17,7 +15,7 @@

<form method="post">
{% csrf_token %}
{% for post in posts %}
{% for post in posts_page %}
<div id="p{{ post.id }}" class="blockpost roweven firstpost">
<a name="post-{{ post.id }}"></a>
<h2><span><span class="conr">#{{ forloop.counter }}&nbsp;</span><a href="{{ post.get_absolute_url }}">{% forum_time post.created %}</a></span></h2>
Expand All @@ -37,7 +35,7 @@ <h3>{{ post.topic.name }}</h3>
<p class="postedit"><em>{% trans "Edited" %} {{ post.user.username }} ({% forum_time post.updated %})</em></p>
{% endif %}
</div>
{% if not forloop.first %}
{% if not forloop.first %}
<p class="multidelete"><label><strong>{% trans "Select" %}</strong>&nbsp;&nbsp;<input type="checkbox" name="post" value="{{ post.id }}" /></label></p>
{% endif %}
</div>
Expand All @@ -49,7 +47,7 @@ <h3>{{ post.topic.name }}</h3>

<div class="postlinksb">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}</div>
<p class="conr"><input type="submit" value="{% trans "Delete" %}" /></p>
<div class="clearer"></div>
</div>
Expand Down
54 changes: 25 additions & 29 deletions djangobb_forum/templates/djangobb_forum/forum.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{% extends 'djangobb_forum/base.html' %}
{% load forum_extras %}
{% load pagination_tags %}
{% load i18n %}

{% block title %}{{ forum.name }} / {% endblock %}
{% block content %}
{% autopaginate topics forum_settings.FORUM_PAGE_SIZE %}
<div class="linkst">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}</div>
{% if user.is_authenticated %}
<p class="postlink conr"><a href="{% url 'djangobb:add_topic' forum.id %}">{% trans "New topic" %}</a></p>
{% endif %}
Expand All @@ -33,40 +31,38 @@ <h2>
</tr>
</thead>
<tbody>
{% if topics %}
{% for topic in topics %}
<tr>
<td class="tcl">
<div class="intd">
<div {% if topic.sticky %}class="sticky"{% else %}{% if topic.closed %}class="closed"{% else %}{% if topic|has_unreads:user %}class="inew"{% else %}class="icon"{% endif %}{% endif %}{% endif %}><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic.sticky %}
{% trans "Sticky:" %}
{% endif %}
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
{% endif %}
</div>
</div>
</td>
<td class="tc2">{{ topic.reply_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.last_post.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user.username }}</span></td>
</tr>
{% endfor %}
{% else %}
{% for topic in topics_page %}
<tr>
<td class="tcl">
<div class="intd">
<div {% if topic.sticky %}class="sticky"{% else %}{% if topic.closed %}class="closed"{% else %}{% if topic|has_unreads:user %}class="inew"{% else %}class="icon"{% endif %}{% endif %}{% endif %}><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic.sticky %}
{% trans "Sticky:" %}
{% endif %}
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
{% endif %}
</div>
</div>
</td>
<td class="tc2">{{ topic.reply_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.last_post.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user.username }}</span></td>
</tr>
{% empty %}
<tr><td class="djangobbcon1" colspan="4">{% trans "Forum is empty." %}</td></tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="linkst">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}</div>
{% if user.is_authenticated %}
<p class="postlink conr"><a href="{% url 'djangobb:add_topic' forum.id %}">{% trans "New topic" %}</a></p>
{% endif %}
Expand Down
6 changes: 2 additions & 4 deletions djangobb_forum/templates/djangobb_forum/lofi/forum.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends 'djangobb_forum/lofi/base.html' %}
{% load pagination_tags %}
{% load forum_extras %}
{% load i18n %}

Expand All @@ -9,15 +8,14 @@
<a href="{% url 'djangobb:lofi_index' %}">{% trans "Root" %}</a> &raquo; {% lofi_link forum %}
</div>

{% autopaginate topics forum_settings.FORUM_PAGE_SIZE %}
<div class="djangobbpagespan">
{% lofi_pagination %}
{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}
</div>

<div id="djangobbcontent">
<div class="topicwrap">
<ol>
{% for topic in topics %}
{% for topic in topics_page %}
<li>{% if topic.sticky %}<span style="color: red;"><strong>{% trans "IMPORTANT:" %}</strong></span>{% endif %}{% lofi_link topic %} <span class="desc">({{ topic.reply_count }} {% trans "replies" %})</span></li>
{% endfor %}
</ol>
Expand Down
4 changes: 0 additions & 4 deletions djangobb_forum/templates/djangobb_forum/lofi/pagination.html

This file was deleted.

6 changes: 2 additions & 4 deletions djangobb_forum/templates/djangobb_forum/lofi/topic.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends 'djangobb_forum/lofi/base.html' %}
{% load pagination_tags %}
{% load forum_extras %}
{% load i18n %}

Expand All @@ -9,13 +8,12 @@
<a href="{% url 'djangobb:lofi_index' %}">{% trans "Root" %}</a> &raquo; {% lofi_link topic.forum %} &raquo; {% lofi_link topic %}
</div>

{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
<div class="djangobbpagespan">
{% lofi_pagination %}
{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}
</div>

<div id='djangobbcontent'>
{% for post in posts %}
{% for post in posts_page %}
<div class='postwrapper'>
<div class='posttopbar'>
<div class='postname'>{{ post.user.username }}</div>
Expand Down
56 changes: 26 additions & 30 deletions djangobb_forum/templates/djangobb_forum/moderate.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{% extends 'djangobb_forum/base.html' %}
{% load pagination_tags %}
{% load forum_extras %}
{% load i18n %}

{% block content %}
{% autopaginate topics forum_settings.FORUM_PAGE_SIZE %}
<div class="linkst">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}</div>
<ul><li><a href="{% url 'djangobb:index' %}">{% trans "Root" %}</a> </li><li>&raquo; {{ forum }}</li></ul>
<div class="clearer"></div>
</div>
Expand All @@ -30,41 +28,39 @@ <h2><span>{{ forum }}</span></h2>
</tr>
</thead>
<tbody>
{% if topics %}
{% for topic in topics %}
<tr>
<td class="tcl">
<div class="intd">
<div {% if topic.sticky %}class="sticky"{% else %}{% if topic.closed %}class="closed"{% else %}{% if topic|has_unreads:user %}class="inew"{% else %}class="icon"{% endif %}{% endif %}{% endif %}><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic.sticky %}
{% trans "Sticky:" %}
{% endif %}
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
{% endif %}
</div>
</div>
</td>
<td class="tc2">{{ topic.reply_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user.username }}</span></td>
<td class="tcmod"><input type="checkbox" name="topic_id" value="{{ topic.id }}" /></td>
</tr>
{% endfor %}
{% else %}
{% for topic in topics_page %}
<tr>
<td class="tcl">
<div class="intd">
<div {% if topic.sticky %}class="sticky"{% else %}{% if topic.closed %}class="closed"{% else %}{% if topic|has_unreads:user %}class="inew"{% else %}class="icon"{% endif %}{% endif %}{% endif %}><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic.sticky %}
{% trans "Sticky:" %}
{% endif %}
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
{% endif %}
</div>
</div>
</td>
<td class="tc2">{{ topic.reply_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user.username }}</span></td>
<td class="tcmod"><input type="checkbox" name="topic_id" value="{{ topic.id }}" /></td>
</tr>
{% empty %}
<tr><td class="djangobbcon1" colspan="4">{% trans "Forum is empty." %}</td></tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="linksb">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}</div>
<p class="conr">
<input type="submit" name="move_topics" value="{% trans "Move" %}" />&nbsp;&nbsp;
<input type="submit" name="delete_topics" value="{% trans "Delete" %}" />&nbsp;&nbsp;
Expand Down
21 changes: 0 additions & 21 deletions djangobb_forum/templates/djangobb_forum/pagination.html

This file was deleted.

19 changes: 19 additions & 0 deletions djangobb_forum/templates/djangobb_forum/paginator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load i18n %}
{% load forum_extras %}
{% if page.has_other_pages %}
{% trans "Pages" %}:
{% if page.has_previous %}
<a href="?{% url_replace request 'page' page.previous_page_number %}">&laquo;</a>
{% endif %}
{% for number in page.paginator.page_range %}
{% if number == page.number %}
<strong>{{ number }}</strong>
{% else %}
<a href="?{% url_replace request 'page' number %}">{{ number }}</a>
{% endif %}
{% endfor %}
{% if page.has_next %}
<a href="?{% url_replace request 'page' page.next_page_number %}">&raquo;</a>
{% endif %}
{% endif %}

8 changes: 3 additions & 5 deletions djangobb_forum/templates/djangobb_forum/search_posts.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{% extends 'djangobb_forum/base.html' %}
{% load forum_extras %}
{% load i18n %}
{% load pagination_tags %}

{% block content %}
{% autopaginate posts forum_settings.FORUM_PAGE_SIZE %}
<div class="linkst">
<div class="inbox">
<p class="pagelink">{% paginate %}</p>
<p class="pagelink">{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}</p>
<div class="clearer"></div>
</div>
</div>
Expand All @@ -21,7 +19,7 @@ <h2><span>{% trans "Search type" %}</span></h2>
</div>
</div>

{% for post in posts %}
{% for post in posts_page %}
{% if post.object %}
{% with post=post.object %}
{% include "djangobb_forum/includes/post_in_search_page.html" %}
Expand All @@ -44,7 +42,7 @@ <h2><span>{% trans "Info" %}</span></h2>

<div class="postlinksb">
<div class="inbox">
<p class="pagelink">{% paginate %}</p>
<p class="pagelink">{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}</p>
<div class="clearer"></div>
</div>
</div>
Expand Down
8 changes: 3 additions & 5 deletions djangobb_forum/templates/djangobb_forum/search_topics.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{% extends 'djangobb_forum/base.html' %}
{% load pagination_tags %}
{% load forum_extras %}
{% load i18n %}

{% block content %}
{% autopaginate topics forum_settings.SEARCH_PAGE_SIZE %}
<div class="linkst">
<div class="inbox">
<p class="pagelink">{% paginate %}</p>
<p class="pagelink">{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}</p>
<div class="clearer"></div>
</div>
</div>
Expand Down Expand Up @@ -35,7 +33,7 @@ <h2><span>{% trans "Search results" %}</span></h2>
</tr>
</thead>
<tbody>
{% for topic in topics %}
{% for topic in topics_page %}
<tr {% if topic|has_unreads:user %}class="inew"{% endif %} {% if topic.closed %}class="iclosed"{% endif %}>
<td class="tcl">
<div class="intd">
Expand Down Expand Up @@ -66,7 +64,7 @@ <h2><span>{% trans "Search results" %}</span></h2>

<div class="linksb">
<div class="inbox">
<p class="pagelink">{% paginate %}</p>
<p class="pagelink">{% include 'djangobb_forum/paginator.html' with page=topics_page request=request only %}</p>
<div class="clearer"></div>
</div>
</div>
Expand Down
8 changes: 3 additions & 5 deletions djangobb_forum/templates/djangobb_forum/topic.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{% extends 'djangobb_forum/base.html' %}
{% load forum_extras %}
{% load pagination_tags %}
{% load i18n %}

{% block title %}{{ topic.forum.name }} / {{ topic.name }} / {% endblock %}
{% block content %}
{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
<div class="linkst">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}</div>
<ul>
<li>
<a href="{% url 'djangobb:index' %}">{% trans "Root" %} </a></li><li>&raquo; {% link topic.forum %} </li><li>&raquo; {{ topic.name }}
Expand Down Expand Up @@ -49,7 +47,7 @@ <h2><span>{% trans "Poll" %}</span></h2>
</div>
{% endif %}

{% for post in posts %}
{% for post in posts_page %}
<div id="p{{ post.id }}" class="blockpost roweven firstpost">
<a name="post-{{ post.id }}"></a>
<h2><span><span class="conr">#{{ forloop.counter }}&nbsp;</span><a href="{{ post.get_absolute_url }}">{% forum_time post.created %}</a></span></h2>
Expand Down Expand Up @@ -166,7 +164,7 @@ <h3>{{ post.topic.name }}</h3>
{% endfor %}
<div class="postlinksb">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
<div class="pagelink conl">{% include 'djangobb_forum/paginator.html' with page=posts_page request=request only %}</div>
<ul>
<li><a href="{% url 'djangobb:index' %}">{% trans "Root" %} </a></li>
<li>&raquo; {% link topic.forum %} </li>
Expand Down
Loading

1 comment on commit 403ca3e

@ZaEzzz
Copy link
Contributor

@ZaEzzz ZaEzzz commented on 403ca3e Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole approach is simpler, but the result is terrible.

Please sign in to comment.