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,14 +30,14 @@
{% 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',
user=user.username) }}> atom feed</a> user=user.username) }}>atom feed</a>
{% else %} {% else %}
{# This *should* not occur as the view makes sure we pass in a user. #} {# This *should* not occur as the view makes sure we pass in a user. #}
<p>Sorry, no such user found.<p/> <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/>. # 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 %}
{% endif %} {# 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> </div>
{% endblock %} {% endblock %}

View File

@ -15,31 +15,48 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # 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 pagination and pagination.pages > 1 %} {% if preserve_get_params %}
<div class="pagination"> {% set get_params = request.GET %}
<p> {% else %}
{% if pagination.has_prev %} {% set get_params = {} %}
<a href="{{ pagination.get_page_url(request, pagination.page-1) }}">&laquo; Prev</a> {% endif %}
{% endif %}
{%- for page in pagination.iter_pages() %} <div class="pagination">
{% if page %} <p>
{% if page != pagination.page %} {% if pagination.has_prev %}
<a href="{{ pagination.get_page_url(request, page) }}">{{ page }}</a> <a href="{{ pagination.get_page_url_explicit(
{% else %} base_url, get_params,
{{ page }} pagination.page - 1) }}">&laquo; Prev</a>
{% endif %}
{% else %}
<span class="ellipsis"></span>
{% endif %} {% endif %}
{%- endfor %}
{%- for page in pagination.iter_pages() %}
{% if pagination.has_next %} {% if page %}
<a href="{{ pagination.get_page_url(request, pagination.page + 1) }}">Next &raquo;</a> {% if page != pagination.page %}
{% endif %} <a href="{{ pagination.get_page_url_explicit(
</p> base_url, get_params,
</div> page) }}">{{ page }}</a>
{% endif %} {% else %}
{{ page }}
{% endif %}
{% else %}
<span class="ellipsis"></span>
{% endif %}
{%- endfor %}
{% if pagination.has_next %}
<a href="{{ pagination.get_page_url_explicit(
base_url, get_params,
pagination.page + 1) }}">Next &raquo;</a>
{% endif %}
</p>
</div>
{% 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})