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

View File

@ -30,14 +30,14 @@
{% include "mediagoblin/utils/profile.html" %}
{% set pagination_base_url = user_gallery_url %}
{% include "mediagoblin/utils/object_gallery.html" %}
<p><a href="{{ request.urlgen('mediagoblin.user_pages.user_gallery',
user=user['username']) }}">View all of {{ user.username }}'s media</a></p>
<p><a href="user_gallery_url">View all of {{ user.username }}'s media</a></p>
<a href={{ request.urlgen(
'mediagoblin.user_pages.atom_feed',
user=user.username) }}> atom feed</a>
user=user.username) }}>atom feed</a>
{% else %}
{# This *should* not occur as the view makes sure we pass in a user. #}
<p>Sorry, no such user found.<p/>

View File

@ -16,6 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% from "mediagoblin/utils/pagination.html" import render_pagination %}
{% block object_gallery_content -%}
<div>
{% if media_entries %}
@ -28,8 +30,12 @@
</li>
{% endfor %}
</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 %}
</div>
{% endblock %}

View File

@ -15,19 +15,34 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{# only display if {{pagination}} is defined #}
{% macro render_pagination(request, pagination,
base_url=None, preserve_get_params=True) %}
{# only display if {{pagination}} is defined #}
{% 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 %}
{% if pagination and pagination.pages > 1 %}
<div class="pagination">
<p>
{% 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 %}
{%- for page in pagination.iter_pages() %}
{% if 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 %}
{{ page }}
{% endif %}
@ -37,9 +52,11 @@
{%- endfor %}
{% 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 %}
</p>
</div>
{% endif %}
{% endif %}
{% endmacro %}

View File

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