Mercurial > public > sg101
changeset 20:c0d0779b266f
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.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 19 Apr 2009 20:41:37 +0000 |
parents | aa2b41c5212b |
children | 884839ddbfde |
files | gpp/templates/home.html gpp/templates/weblinks/latest_tag.html gpp/templates/weblinks/link_detail.html gpp/weblinks/models.py gpp/weblinks/templatetags/__init__.py gpp/weblinks/templatetags/weblinks_tags.py gpp/weblinks/urls.py gpp/weblinks/views.py |
diffstat | 7 files changed, 53 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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 %} <h2>Welcome to SurfGuitar101!</h2> @@ -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.</p> <div class="span-9"> - Some stuff. + {% latest_weblinks %} </div> <div class="span-10 last"> Some more stuff.
--- /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 @@ +<h3>New Links</h3> +{% if links %} +<ol> + {% for link in links %} + <li><a href="{{ link.get_absolute_url }}">{{ link.title }}</a></li> + {% endfor %} +</ol> +{% else %} +<p>No links at this time.</p> +{% endif %}
--- /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 %} +<h3>Link Details: {{ link.title }}</h3> +<dl> +{% include 'weblinks/link.html' %} +</dl> +{% endblock %}
--- 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):
--- /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, + }
--- 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<category>\d+)/(?P<sort>title|date|rating|hits)/page/(?P<page>\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'),
--- 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))