# HG changeset patch # User Brian Neal # Date 1240173697 0 # Node ID c0d0779b266fdc3b93fdb1d49ae8b2a6a537f9bb # Parent aa2b41c5212baa0d5831dee2dfa229bf0d96ed48 Created a template tag for the latest weblinks: latest_weblinks. This necessitated adding a get_absolute_url function for the Link model along with a new view for it. diff -r aa2b41c5212b -r c0d0779b266f gpp/templates/home.html --- a/gpp/templates/home.html Sun Apr 19 20:10:00 2009 +0000 +++ b/gpp/templates/home.html Sun Apr 19 20:41:37 2009 +0000 @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% load weblinks_tags %} {% block title %}Home{% endblock %} {% block content %}

Welcome to SurfGuitar101!

@@ -15,7 +16,7 @@ Also, I hope that the look and feel of this site can be greatly improved to something really cool! I'll need lots of help for this aspect, as I'm more of a coder than a designer.

- Some stuff. + {% latest_weblinks %}
Some more stuff. diff -r aa2b41c5212b -r c0d0779b266f gpp/templates/weblinks/latest_tag.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/weblinks/latest_tag.html Sun Apr 19 20:41:37 2009 +0000 @@ -0,0 +1,10 @@ +

New Links

+{% if links %} +
    + {% for link in links %} +
  1. {{ link.title }}
  2. + {% endfor %} +
+{% else %} +

No links at this time.

+{% endif %} diff -r aa2b41c5212b -r c0d0779b266f gpp/templates/weblinks/link_detail.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/weblinks/link_detail.html Sun Apr 19 20:41:37 2009 +0000 @@ -0,0 +1,8 @@ +{% extends 'weblinks/base.html' %} +{% block title %}Web Links: {{ link.title }}{% endblock %} +{% block weblinks_content %} +

Link Details: {{ link.title }}

+
+{% include 'weblinks/link.html' %} +
+{% endblock %} diff -r aa2b41c5212b -r c0d0779b266f gpp/weblinks/models.py --- a/gpp/weblinks/models.py Sun Apr 19 20:10:00 2009 +0000 +++ b/gpp/weblinks/models.py Sun Apr 19 20:41:37 2009 +0000 @@ -43,11 +43,15 @@ objects = models.Manager() public_objects = PublicLinkManager() + class Meta: + ordering = ('title', ) + def __unicode__(self): return self.title - class Meta: - ordering = ('title', ) + @models.permalink + def get_absolute_url(self): + return ('weblinks-link_detail', [str(self.id)]) class FlaggedLinkManager(models.Manager): diff -r aa2b41c5212b -r c0d0779b266f gpp/weblinks/templatetags/weblinks_tags.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/weblinks/templatetags/weblinks_tags.py Sun Apr 19 20:41:37 2009 +0000 @@ -0,0 +1,14 @@ +""" +Template tags for the weblinks application. +""" +from django import template +from weblinks.models import Link + +register = template.Library() + +@register.inclusion_tag('weblinks/latest_tag.html') +def latest_weblinks(): + links = Link.public_objects.order_by('-date_added')[:10] + return { + 'links': links, + } diff -r aa2b41c5212b -r c0d0779b266f gpp/weblinks/urls.py --- a/gpp/weblinks/urls.py Sun Apr 19 20:10:00 2009 +0000 +++ b/gpp/weblinks/urls.py Sun Apr 19 20:41:37 2009 +0000 @@ -8,6 +8,9 @@ url(r'^category/(?P\d+)/(?Ptitle|date|rating|hits)/page/(?P\d+)/$', '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'), diff -r aa2b41c5212b -r c0d0779b266f gpp/weblinks/views.py --- a/gpp/weblinks/views.py Sun Apr 19 20:10:00 2009 +0000 +++ b/gpp/weblinks/views.py Sun Apr 19 20:41:37 2009 +0000 @@ -224,3 +224,13 @@ 'search_form': SearchForm(), }, 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', { + 'link': link, + 'search_form': SearchForm(), + }, + context_instance = RequestContext(request))