Mercurial > public > sg101
changeset 242:7e8d2dda99e3
For #93: fix url scheme for weblinks.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 15 Sep 2010 03:24:01 +0000 |
parents | 27bee3ac85e6 |
children | 7ddd60164245 |
files | gpp/downloads/views.py gpp/templates/weblinks/base.html gpp/templates/weblinks/index.html gpp/templates/weblinks/link.html gpp/templates/weblinks/link_summary.html gpp/templates/weblinks/navigation.html gpp/templates/weblinks/search_results.html gpp/templates/weblinks/view_links.html gpp/weblinks/admin.py gpp/weblinks/fixtures/weblinks_categories.json gpp/weblinks/forms.py gpp/weblinks/models.py gpp/weblinks/templatetags/weblinks_tags.py gpp/weblinks/urls.py gpp/weblinks/views.py |
diffstat | 15 files changed, 125 insertions(+), 169 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/downloads/views.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/downloads/views.py Wed Sep 15 03:24:01 2010 +0000 @@ -26,7 +26,7 @@ ####################################################################### -DLS_PER_PAGE = 1 +DLS_PER_PAGE = 10 def create_paginator(dls): return DiggPaginator(dls, DLS_PER_PAGE, body=5, tail=3, margin=3, padding=2)
--- a/gpp/templates/weblinks/base.html Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/templates/weblinks/base.html Wed Sep 15 03:24:01 2010 +0000 @@ -7,7 +7,7 @@ {% endblock %} {% block content %} <h2>Web Links</h2> -{% weblinks_navigation %} +{% include 'weblinks/navigation.html' %} <div class="weblinks-content"> {% block weblinks_content %} {% endblock %}
--- a/gpp/templates/weblinks/index.html Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/templates/weblinks/index.html Wed Sep 15 03:24:01 2010 +0000 @@ -6,7 +6,7 @@ <p>We have {{ total_links }} links in {{ categories.count }} categories.</p> <dl> {% for category in categories %} - <dt><a href="{% url weblinks-view_links category=category.id sort="title" page=1 %}">{{ category.title }}</a> + <dt><a href="{% url weblinks-view_links slug=category.slug sort="title" %}">{{ category.title }}</a> ({{ category.count }})</dt> <dd><p>{{ category.description }}</p></dd> {% endfor %}
--- a/gpp/templates/weblinks/link.html Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/templates/weblinks/link.html Wed Sep 15 03:24:01 2010 +0000 @@ -7,6 +7,7 @@ <table class="link-stats"> <tr> <th>Added by:</th><td><a href="{% url bio-view_profile link.user.username %}">{{ link.user.username }}</a></td> + <th>Category:</th><td><a href="{% url weblinks-view_links slug=link.category.slug sort='date' %}">{{ link.category.title }}</a></td> </tr> <tr> <th>Date Added:</th><td>{{ link.date_added|date:"M d, Y" }}</td>
--- a/gpp/templates/weblinks/link_summary.html Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/templates/weblinks/link_summary.html Wed Sep 15 03:24:01 2010 +0000 @@ -1,12 +1,21 @@ {% extends 'weblinks/base.html' %} {% block title %}Web Links: {{ title }}{% endblock %} +{% block weblinks_css %} +<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/tab-nav.css" /> +<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/pagination.css" /> +{% endblock %} +{% block weblinks_js %} +<script type="text/javascript" src="{{ MEDIA_URL }}js/weblinks.js"></script> +{% endblock %} {% block weblinks_content %} - <h3>{{ title }}</h3> - {% if links %} +<h3>{{ title }}</h3> +{% if page.object_list %} + {% include 'core/pagination.html' %} <dl> - {% for link in links %} + {% for link in page.object_list %} {% include 'weblinks/link.html' %} {% endfor %} </dl> - {% endif %} + {% include 'core/pagination.html' %} +{% endif %} {% endblock %}
--- a/gpp/templates/weblinks/navigation.html Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/templates/weblinks/navigation.html Wed Sep 15 03:24:01 2010 +0000 @@ -1,22 +1,16 @@ <div class="app-logo"> <img src="{{ MEDIA_URL }}icons/weblinks-logo.jpg" alt="Links Logo" title="Links" /> </div> -<div class="weblinks-search"> -<form action="{% url weblinks-search page=1 %}" method="post">{% csrf_token %} - <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-main %}">Categories</a></li> +<li><a href="{% url weblinks-new_links %}">New</a></li> +<li><a href="{% url weblinks-popular_links %}">Popular</a></li> {% if user.is_authenticated %} -<li><a href="{% url weblinks.views.add_link %}">Add Link</a></li> +<li><a href="{% url weblinks-add_link %}">Add Link</a></li> {% endif %} </ul> <center> - <form action="{% url weblinks.views.random_link %}" method="post">{% csrf_token %} + <form action="{% url weblinks-random_link %}" method="post">{% csrf_token %} <input type="submit" value="Visit a Random Link" /> </form> </center>
--- a/gpp/templates/weblinks/search_results.html Wed Sep 15 01:01:40 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -{% extends 'weblinks/base.html' %} -{% block title %}Web Links: Search Results{% endblock %} -{% block weblinks_css %} -<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/pagination.css" /> -{% endblock %} -{% block weblinks_content %} -<h3>Search Results: {{ query }} - {{ page.paginator.count }} result{{ page.paginator.count|pluralize }}</h3> - -{% include 'core/pagination_query.html' %} - -{% if page.object_list %} -<dl> -{% for link in page.object_list %} - {% include 'weblinks/link.html' %} -{% endfor %} -</dl> - -{% include 'core/pagination_query.html' %} - -{% else %} -<p>No results found.</p> -{% endif %} -{% endblock %}
--- a/gpp/templates/weblinks/view_links.html Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/templates/weblinks/view_links.html Wed Sep 15 03:24:01 2010 +0000 @@ -12,11 +12,11 @@ {% if page.object_list %} <ul class="tab-nav"> - <li><a href="{% url weblinks-view_links category=category.id sort="title" page="1" %}" + <li><a href="{% url weblinks-view_links slug=category.slug sort="title" %}" {% ifequal s "title" %}class="active" {% endifequal %}>Title</a></li> - <li><a href="{% url weblinks-view_links category=category.id sort="date" page="1" %}" + <li><a href="{% url weblinks-view_links slug=category.slug sort="date" %}" {% ifequal s "date" %}class="active"{% endifequal %}>Date</a></li> - <li><a href="{% url weblinks-view_links category=category.id sort="hits" page="1" %}" + <li><a href="{% url weblinks-view_links slug=category.slug sort="hits" %}" {% ifequal s "hits" %}class="active"{% endifequal %}>Hits</a></li> </ul>
--- a/gpp/weblinks/admin.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/admin.py Wed Sep 15 03:24:01 2010 +0000 @@ -9,7 +9,8 @@ class CategoryAdmin(admin.ModelAdmin): - list_display = ('title', 'description', 'count') + list_display = ('title', 'slug', 'description', 'count') + prepopulated_fields = {'slug': ('title', )} readonly_fields = ('count', )
--- a/gpp/weblinks/fixtures/weblinks_categories.json Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/fixtures/weblinks_categories.json Wed Sep 15 03:24:01 2010 +0000 @@ -1,101 +1,112 @@ [ { - "pk": 1, - "model": "weblinks.category", + "pk": 1, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 215, + "description": "", + "slug": "bands", "title": "Bands" } - }, + }, { - "pk": 5, - "model": "weblinks.category", + "pk": 5, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 21, + "description": "", + "slug": "fan-sites", "title": "Fan Sites" } - }, + }, { - "pk": 4, - "model": "weblinks.category", + "pk": 4, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 28, + "description": "", + "slug": "gear", "title": "Gear" } - }, + }, { - "pk": 2, - "model": "weblinks.category", + "pk": 2, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 7, + "description": "", + "slug": "music-merchants", "title": "Music Merchants" } - }, + }, { - "pk": 8, - "model": "weblinks.category", + "pk": 8, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 6, + "description": "", + "slug": "other", "title": "Other" } - }, + }, { - "pk": 11, - "model": "weblinks.category", + "pk": 11, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "Do you have a photo gallery of surf bands somewhere on the web? Why not add a link to it here?", + "count": 17, + "description": "Do you have a photo gallery of surf bands somewhere on the web? Why not add a link to it here?", + "slug": "photo-galleries", "title": "Photo Galleries" } - }, + }, { - "pk": 10, - "model": "weblinks.category", + "pk": 10, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 4, + "description": "", + "slug": "podcasts", "title": "Podcasts" } - }, + }, { - "pk": 6, - "model": "weblinks.category", + "pk": 6, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 8, + "description": "", + "slug": "radio", "title": "Radio" } - }, + }, { - "pk": 3, - "model": "weblinks.category", + "pk": 3, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 13, + "description": "", + "slug": "record-labels", "title": "Record Labels" } - }, + }, { - "pk": 7, - "model": "weblinks.category", + "pk": 7, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "", + "count": 4, + "description": "", + "slug": "tablature", "title": "Tablature" } - }, + }, { - "pk": 9, - "model": "weblinks.category", + "pk": 9, + "model": "weblinks.category", "fields": { - "count": 0, - "description": "Links to surf videos on the web", + "count": 31, + "description": "Links to surf videos on the web", + "slug": "videos", "title": "Videos" } } -] +] \ No newline at end of file
--- a/gpp/weblinks/forms.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/forms.py Wed Sep 15 03:24:01 2010 +0000 @@ -5,13 +5,6 @@ from django import forms from weblinks.models import PendingLink, Link -class SearchForm(forms.Form): - '''Weblinks search form''' - text = forms.CharField(max_length = 30) - - def query(self): - return self.cleaned_data['text'] - class AddLinkForm(forms.ModelForm): title = forms.CharField(widget = forms.TextInput(attrs = {'size': 52}))
--- a/gpp/weblinks/models.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/models.py Wed Sep 15 03:24:01 2010 +0000 @@ -10,6 +10,7 @@ class Category(models.Model): """Links belong to categories""" title = models.CharField(max_length=64) + slug = models.SlugField(max_length=64) description = models.TextField(blank=True) count = models.IntegerField(default=0)
--- a/gpp/weblinks/templatetags/weblinks_tags.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/templatetags/weblinks_tags.py Wed Sep 15 03:24:01 2010 +0000 @@ -4,19 +4,10 @@ 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'], - 'MEDIA_URL': context['MEDIA_URL'], - } - @register.inclusion_tag('weblinks/latest_tag.html') def latest_weblinks():
--- a/gpp/weblinks/urls.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/urls.py Wed Sep 15 03:24:01 2010 +0000 @@ -3,20 +3,17 @@ urlpatterns = patterns('weblinks.views', url(r'^$', 'link_index', name='weblinks-main'), - (r'^add/$', 'add_link'), - (r'^add/thanks/$', 'add_thanks'), - url(r'^category/(?P<category>\d+)/(?P<sort>title|date|rating|hits)/page/(?P<page>\d+)/$', + url(r'^add/$', 'add_link', name='weblinks-add_link'), + url(r'^add/thanks/$', 'add_thanks', name='weblinks-add_thanks'), + url(r'^category/(?P<slug>[\w\d-]+)/(?P<sort>title|date|rating|hits)/$', 'view_links', name='weblinks-view_links'), url(r'^detail/(\d+)/$', 'link_detail', name='weblinks-link_detail'), - (r'^new/$', 'new_links'), - (r'^popular/$', 'popular_links'), - (r'^random/$', 'random_link'), - (r'^report/(\d+)/$', 'report_link'), - url(r'^search/page/(?P<page>\d+)/$', - 'search_links', - name="weblinks-search"), + url(r'^new/$', 'new_links', name='weblinks-new_links'), + url(r'^popular/$', 'popular_links', name='weblinks-popular_links'), + url(r'^random/$', 'random_link', name='weblinks-random_link'), + url(r'^report/(\d+)/$', 'report_link', name='weblinks-report_link'), url(r'^visit/(\d+)/$', 'visit', name="weblinks-visit"), )
--- a/gpp/weblinks/views.py Wed Sep 15 01:01:40 2010 +0000 +++ b/gpp/weblinks/views.py Wed Sep 15 03:24:01 2010 +0000 @@ -20,10 +20,10 @@ from core.paginator import DiggPaginator from core.functions import email_admins +from core.functions import get_page from weblinks.models import Category from weblinks.models import Link from weblinks.models import FlaggedLink -from weblinks.forms import SearchForm from weblinks.forms import AddLinkForm ####################################################################### @@ -47,9 +47,16 @@ ####################################################################### def new_links(request): - links = Link.public_objects.order_by('-date_added')[:LINKS_PER_PAGE] + links = Link.public_objects.order_by('-date_added') + paginator = create_paginator(links) + page = get_page(request.GET) + try: + the_page = paginator.page(page) + except InvalidPage: + raise Http404 + return render_to_response('weblinks/link_summary.html', { - 'links': links, + 'page': the_page, 'title': 'Newest Links', }, context_instance = RequestContext(request)) @@ -57,9 +64,15 @@ ####################################################################### def popular_links(request): - links = Link.public_objects.order_by('-hits')[:LINKS_PER_PAGE] + links = Link.public_objects.order_by('-hits') + paginator = create_paginator(links) + page = get_page(request.GET) + try: + the_page = paginator.page(page) + except InvalidPage: + raise Http404 return render_to_response('weblinks/link_summary.html', { - 'links': links, + 'page': the_page, 'title': 'Popular Links', }, context_instance = RequestContext(request)) @@ -78,7 +91,7 @@ A user has added a new link for your approval. """) - return HttpResponseRedirect(reverse('weblinks.views.add_thanks')) + return HttpResponseRedirect(reverse('weblinks-add_thanks')) else: add_form = AddLinkForm() @@ -105,9 +118,9 @@ 'hits': '-hits' } -def view_links(request, category, sort='title', page='1'): +def view_links(request, slug, sort='title'): try: - cat = Category.objects.get(pk=category) + cat = Category.objects.get(slug=slug) except Category.DoesNotExist: raise Http404 @@ -117,10 +130,11 @@ sort = 'title' order_by = LINK_FIELD_MAP['title'] - links = Link.public_objects.filter(category = category).order_by(order_by) + links = Link.public_objects.filter(category=cat).order_by(order_by) paginator = create_paginator(links) + page = get_page(request.GET) try: - the_page = paginator.page(int(page)) + the_page = paginator.page(page) except InvalidPage: raise Http404 @@ -178,39 +192,6 @@ ####################################################################### -def search_links(request, page=1): - if request.method == 'POST': - form = SearchForm(request.POST) - if form.is_valid(): - query_text = form.query() - page = 1 - else: - return HttpResponseRedirect(reverse('weblinks.views.link_index')) - else: - if 'query' in request.GET: - query_text = request.GET['query'] - else: - return HttpResponseRedirect(reverse('weblinks.views.link_index')) - - links = Link.public_objects.filter( - Q(title__icontains = query_text) | - Q(description__icontains = query_text)).order_by('title').select_related() - paginator = create_paginator(links) - try: - the_page = paginator.page(int(page)) - except EmptyPage: - links = Link.public_objects.none() - except InvalidPage: - raise Http404 - - return render_to_response('weblinks/search_results.html', { - 'query': query_text, - 'page': the_page, - }, - context_instance = RequestContext(request)) - -####################################################################### - def link_detail(request, id): link = get_object_or_404(Link, pk=id) return render_to_response('weblinks/link_detail.html', {