Make pagination on user profile point to the user gallery

This required a couple of changes:
 - making a new render_pagination macro
 - switching things over to use that
This commit is contained in:
Christopher Allan Webber 2011-07-02 22:09:46 -05:00
parent d729012dd9
commit 5949be9ad6
5 changed files with 61 additions and 32 deletions

View File

@ -18,6 +18,7 @@
{% extends "mediagoblin/base.html" %} {% extends "mediagoblin/base.html" %}
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
{% from "mediagoblin/utils/pagination.html" import render_pagination %}
{% block mediagoblin_content %} {% block mediagoblin_content %}
{% if media %} {% if media %}
@ -87,7 +88,7 @@
</div> </div>
{% endfor %} {% endfor %}
{% include "mediagoblin/utils/pagination.html" %} {{ render_pagination(request, pagination) }}
</div> </div>
{% endif %} {% endif %}
<div class="grid_4 omega media_sidebar"> <div class="grid_4 omega media_sidebar">

View File

@ -30,10 +30,10 @@
{% include "mediagoblin/utils/profile.html" %} {% include "mediagoblin/utils/profile.html" %}
{% set pagination_base_url = user_gallery_url %}
{% include "mediagoblin/utils/object_gallery.html" %} {% include "mediagoblin/utils/object_gallery.html" %}
<p><a href="{{ request.urlgen('mediagoblin.user_pages.user_gallery', <p><a href="user_gallery_url">View all of {{ user.username }}'s media</a></p>
user=user['username']) }}">View all of {{ user.username }}'s media</a></p>
<a href={{ request.urlgen( <a href={{ request.urlgen(
'mediagoblin.user_pages.atom_feed', 'mediagoblin.user_pages.atom_feed',

View File

@ -16,6 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
{% from "mediagoblin/utils/pagination.html" import render_pagination %}
{% block object_gallery_content -%} {% block object_gallery_content -%}
<div> <div>
{% if media_entries %} {% if media_entries %}
@ -28,8 +30,12 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% include "mediagoblin/utils/pagination.html" %} {% if pagination_base_url %}
{# different url, so set that and don't keep the get params #}
{{ render_pagination(request, pagination, pagination_base_url, False) }}
{% else %}
{{ render_pagination(request, pagination) }}
{% endif %}
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -15,19 +15,34 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
{% macro render_pagination(request, pagination,
base_url=None, preserve_get_params=True) %}
{# only display if {{pagination}} is defined #} {# only display if {{pagination}} is defined #}
{% if pagination and pagination.pages > 1 %} {% if pagination and pagination.pages > 1 %}
{% if not base_url %}
{% set base_url = request.path_info %}
{% endif %}
{% if preserve_get_params %}
{% set get_params = request.GET %}
{% else %}
{% set get_params = {} %}
{% endif %}
<div class="pagination"> <div class="pagination">
<p> <p>
{% if pagination.has_prev %} {% if pagination.has_prev %}
<a href="{{ pagination.get_page_url(request, pagination.page-1) }}">&laquo; Prev</a> <a href="{{ pagination.get_page_url_explicit(
base_url, get_params,
pagination.page - 1) }}">&laquo; Prev</a>
{% endif %} {% endif %}
{%- for page in pagination.iter_pages() %} {%- for page in pagination.iter_pages() %}
{% if page %} {% if page %}
{% if page != pagination.page %} {% if page != pagination.page %}
<a href="{{ pagination.get_page_url(request, page) }}">{{ page }}</a> <a href="{{ pagination.get_page_url_explicit(
base_url, get_params,
page) }}">{{ page }}</a>
{% else %} {% else %}
{{ page }} {{ page }}
{% endif %} {% endif %}
@ -37,9 +52,11 @@
{%- endfor %} {%- endfor %}
{% if pagination.has_next %} {% if pagination.has_next %}
<a href="{{ pagination.get_page_url(request, pagination.page + 1) }}">Next &raquo;</a> <a href="{{ pagination.get_page_url_explicit(
base_url, get_params,
pagination.page + 1) }}">Next &raquo;</a>
{% endif %} {% endif %}
</p> </p>
</div> </div>
{% endif %} {% endif %}
{% endmacro %}

View File

@ -48,10 +48,15 @@ def user_home(request, page):
if media_entries == None: if media_entries == None:
return exc.HTTPNotFound() return exc.HTTPNotFound()
user_gallery_url = request.urlgen(
'mediagoblin.user_pages.user_gallery',
user=user['username'])
return render_to_response( return render_to_response(
request, request,
'mediagoblin/user_pages/user.html', 'mediagoblin/user_pages/user.html',
{'user': user, {'user': user,
'user_gallery_url': user_gallery_url,
'media_entries': media_entries, 'media_entries': media_entries,
'pagination': pagination}) 'pagination': pagination})