# HG changeset patch # User Brian Neal # Date 1240082057 0 # Node ID 7b6540b185d90bbd2a69397947b7967cea25f313 # Parent 777451a98f9d4b068f5e8bc6017bbb35b8caee22 Added get_absolute_url() for my comments. Had to add a get_absolute_url() function for downloads in the process. diff -r 777451a98f9d -r 7b6540b185d9 gpp/comments/models.py --- a/gpp/comments/models.py Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/comments/models.py Sat Apr 18 19:14:17 2009 +0000 @@ -7,6 +7,7 @@ from django.contrib.contenttypes import generic from django.contrib.auth.models import User from django.template.loader import render_to_string +from django.core import urlresolvers COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000) @@ -43,17 +44,29 @@ # Attach manager objects = CommentManager() + class Meta: + ordering = ('creation_date', ) + def __unicode__(self): return u'%s: %s...' % (self.user.username, self.comment[:50]) - class Meta: - ordering = ('creation_date', ) - def save(self, force_insert=False, force_update=False): html = render_to_string('comments/markdown.html', {'data': self.comment}) self.html = html.strip() super(Comment, self).save(force_insert, force_update) + def get_absolute_url(self): + return self.get_content_object_url() + ('#c%s' % self.id) + + def get_content_object_url(self): + """ + Get a URL suitable for redirecting to the content object. + """ + return urlresolvers.reverse( + "comments-url-redirect", + args=(self.content_type_id, self.object_id) + ) + class CommentFlag(models.Model): """This model represents a user flagging a comment as inappropriate.""" diff -r 777451a98f9d -r 7b6540b185d9 gpp/comments/urls.py --- a/gpp/comments/urls.py Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/comments/urls.py Sat Apr 18 19:14:17 2009 +0000 @@ -8,3 +8,9 @@ url(r'^markdown/$', 'markdown_preview', name='comments-markdown_preview'), url(r'^post/$', 'post_comment', name='comments-post'), ) + +urlpatterns += patterns('', + url(r'^cr/(\d+)/(\d+)/$', + 'django.contrib.contenttypes.views.shortcut', + name='comments-url-redirect'), +) diff -r 777451a98f9d -r 7b6540b185d9 gpp/downloads/models.py --- a/gpp/downloads/models.py Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/downloads/models.py Sat Apr 18 19:14:17 2009 +0000 @@ -67,6 +67,10 @@ def __unicode__(self): return self.title + @models.permalink + def get_absolute_url(self): + return ('downloads-download', [str(self.id)]) + def save(self, force_insert=False, force_update=False): html = render_to_string('downloads/markdown.html', {'data': self.description}) self.html = html.strip() diff -r 777451a98f9d -r 7b6540b185d9 gpp/potd/models.py --- a/gpp/potd/models.py Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/potd/models.py Sat Apr 18 19:14:17 2009 +0000 @@ -34,11 +34,15 @@ date_added = models.DateField(auto_now_add=True) potd_count = models.IntegerField(default=0) + class Meta: + ordering = ('-date_added', '-caption') + def __unicode__(self): return u'%s (%s)' % (self.caption, self.pk) - class Meta: - ordering = ('-date_added', '-caption') + @models.permalink + def get_absolute_url(self): + return ('potd-archive', [str(self.id)]) def save(self, force_insert=False, force_update=False): diff -r 777451a98f9d -r 7b6540b185d9 gpp/potd/urls.py --- a/gpp/potd/urls.py Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/potd/urls.py Sat Apr 18 19:14:17 2009 +0000 @@ -5,4 +5,5 @@ urlpatterns = patterns('potd.views', url(r'^$', 'view', name='potd-view'), + url(r'^archive/(\d+)/$', 'archive', name='potd-archive'), ) diff -r 777451a98f9d -r 7b6540b185d9 gpp/potd/views.py --- a/gpp/potd/views.py Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/potd/views.py Sat Apr 18 19:14:17 2009 +0000 @@ -3,14 +3,25 @@ """ from django.shortcuts import render_to_response +from django.shortcuts import get_object_or_404 from django.template import RequestContext from potd.models import Current +from potd.models import Photo def view(request): potd = Current.objects.get_current_photo() return render_to_response('potd/view.html', { 'potd': potd, + 'is_current': True, }, context_instance = RequestContext(request)) + +def archive(request, id): + photo = get_object_or_404(Photo, pk=id) + return render_to_response('potd/view.html', { + 'potd': photo, + 'is_current': False, + }, + context_instance = RequestContext(request)) diff -r 777451a98f9d -r 7b6540b185d9 gpp/templates/comments/comment.html --- a/gpp/templates/comments/comment.html Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/templates/comments/comment.html Sat Apr 18 19:14:17 2009 +0000 @@ -2,12 +2,12 @@ {% load markup %} {% load smiley_tags %}
  • -
    +
    {% if comment.is_removed %} -

    This comment has been removed.

    +

    This comment has been removed.

    {% else %}
    {{ comment.html|safe }}
    {% endif %} diff -r 777451a98f9d -r 7b6540b185d9 gpp/templates/potd/view.html --- a/gpp/templates/potd/view.html Thu Apr 16 02:00:17 2009 +0000 +++ b/gpp/templates/potd/view.html Sat Apr 18 19:14:17 2009 +0000 @@ -11,8 +11,12 @@ {% endblock %} {% block content %} +{% if is_current %}

    Photo Of The Day

    {% now "l, F d, Y" %}

    +{% else %} +

    Photo Of The Day Archives

    +{% endif %}
    {% if potd %} {{ potd.caption }}