Mercurial > public > sg101
changeset 21:884839ddbfde
Webinks: added a navigation template tag so views don't have to keep constructing the searc form. Also provided a count of search results on the template.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 19 Apr 2009 21:00:06 +0000 |
parents | c0d0779b266f |
children | 42f22c56ab05 |
files | gpp/templates/weblinks/base.html gpp/templates/weblinks/navigation.html gpp/templates/weblinks/search_results.html gpp/weblinks/templatetags/weblinks_tags.py gpp/weblinks/views.py |
diffstat | 5 files changed, 29 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/templates/weblinks/base.html Sun Apr 19 20:41:37 2009 +0000 +++ b/gpp/templates/weblinks/base.html Sun Apr 19 21:00:06 2009 +0000 @@ -1,27 +1,12 @@ {% extends 'base.html' %} +{% load weblinks_tags %} {% block custom_css %} <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/weblinks.css" /> {% block weblinks_css %}{% endblock %} {% endblock %} {% block content %} <h2>Web Links</h2> - -<div class="weblinks-search"> -<form action="{% url weblinks-search page=1 %}" method="post"> - <p>{{ search_form.text }} <input type="submit" value="Search" /></p> -</form> -</div> - -<ul class="app-menu"> -<li><a href="{% url weblinks.views.link_index %}">Categories</a></li> -<li><a href="{% url weblinks.views.new_links %}">New</a></li> -<li><a href="{% url weblinks.views.popular_links %}">Popular</a></li> -<li><a href="{% url weblinks.views.random_link %}" target="_blank">Random</a></li> -{% if user.is_authenticated %} -<li><a href="{% url weblinks.views.add_link %}">Add</a></li> -{% endif %} -</ul> - +{% weblinks_navigation %} <div class="weblinks-content"> {% block weblinks_content %} {% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/weblinks/navigation.html Sun Apr 19 21:00:06 2009 +0000 @@ -0,0 +1,15 @@ +<div class="weblinks-search"> +<form action="{% url weblinks-search page=1 %}" method="post"> + <p>{{ search_form.text }} <input type="submit" value="Search" /></p> +</form> +</div> + +<ul class="app-menu"> +<li><a href="{% url weblinks.views.link_index %}">Categories</a></li> +<li><a href="{% url weblinks.views.new_links %}">New</a></li> +<li><a href="{% url weblinks.views.popular_links %}">Popular</a></li> +<li><a href="{% url weblinks.views.random_link %}" target="_blank">Random</a></li> +{% if user.is_authenticated %} +<li><a href="{% url weblinks.views.add_link %}">Add</a></li> +{% endif %} +</ul>
--- a/gpp/templates/weblinks/search_results.html Sun Apr 19 20:41:37 2009 +0000 +++ b/gpp/templates/weblinks/search_results.html Sun Apr 19 21:00:06 2009 +0000 @@ -4,7 +4,7 @@ <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/pagination.css" /> {% endblock %} {% block weblinks_content %} -<h3>Search Results: {{ query }}</h3> +<h3>Search Results: {{ query }} - {{ page.paginator.count }} result{{ page.paginator.count|pluralize }}</h3> {% include 'core/pagination_query.html' %}
--- a/gpp/weblinks/templatetags/weblinks_tags.py Sun Apr 19 20:41:37 2009 +0000 +++ b/gpp/weblinks/templatetags/weblinks_tags.py Sun Apr 19 21:00:06 2009 +0000 @@ -2,10 +2,21 @@ Template tags for the weblinks application. """ from django import template + from weblinks.models import Link +from weblinks.forms import SearchForm + register = template.Library() +@register.inclusion_tag('weblinks/navigation.html', takes_context=True) +def weblinks_navigation(context): + return { + 'search_form': SearchForm(), + 'user': context['user'], + } + + @register.inclusion_tag('weblinks/latest_tag.html') def latest_weblinks(): links = Link.public_objects.order_by('-date_added')[:10]
--- a/gpp/weblinks/views.py Sun Apr 19 20:41:37 2009 +0000 +++ b/gpp/weblinks/views.py Sun Apr 19 21:00:06 2009 +0000 @@ -34,11 +34,9 @@ def link_index(request): categories = Category.objects.all() total_links = Link.public_objects.all().count() - form = SearchForm() return render_to_response('weblinks/index.html', { 'categories': categories, 'total_links': total_links, - 'search_form': form, }, context_instance = RequestContext(request)) @@ -49,7 +47,6 @@ return render_to_response('weblinks/link_summary.html', { 'links': links, 'title': 'Newest Links', - 'search_form': SearchForm(), }, context_instance = RequestContext(request)) @@ -60,7 +57,6 @@ return render_to_response('weblinks/link_summary.html', { 'links': links, 'title': 'Popular Links', - 'search_form': SearchForm(), }, context_instance = RequestContext(request)) @@ -84,7 +80,6 @@ add_form = AddLinkForm() return render_to_response('weblinks/add_link.html', { - 'search_form': SearchForm(), 'add_form': add_form, }, context_instance = RequestContext(request)) @@ -94,7 +89,6 @@ @login_required def add_thanks(request): return render_to_response('weblinks/add_link.html', { - 'search_form': SearchForm(), }, context_instance = RequestContext(request)) @@ -131,7 +125,6 @@ 's' : sort, 'category' : cat, 'page' : the_page, - 'search_form': SearchForm(), }, context_instance = RequestContext(request)) @@ -173,7 +166,6 @@ return render_to_response('weblinks/report_link.html', { 'link': link, - 'search_form': SearchForm(), 'report_thanks': False, }, context_instance = RequestContext(request)) @@ -186,7 +178,6 @@ link = get_object_or_404(Link, pk = link_id) return render_to_response('weblinks/report_link.html', { 'link': link, - 'search_form': SearchForm(), 'report_thanks': True, }, context_instance = RequestContext(request)) @@ -221,7 +212,6 @@ return render_to_response('weblinks/search_results.html', { 'query': query_text, 'page': the_page, - 'search_form': SearchForm(), }, context_instance = RequestContext(request)) @@ -231,6 +221,5 @@ link = get_object_or_404(Link, pk=id) return render_to_response('weblinks/link_detail.html', { 'link': link, - 'search_form': SearchForm(), }, context_instance = RequestContext(request))