diff options
Diffstat (limited to 'forum')
-rw-r--r-- | forum/models.py | 20 | ||||
-rw-r--r-- | forum/templatetags/extra_filters.py | 9 | ||||
-rw-r--r-- | forum/templatetags/extra_tags.py | 6 |
3 files changed, 22 insertions, 13 deletions
diff --git a/forum/models.py b/forum/models.py index 7de703ca..9510476a 100644 --- a/forum/models.py +++ b/forum/models.py @@ -274,6 +274,16 @@ class Question(models.Model): class Meta: db_table = u'question' +class FavoriteQuestion(models.Model): + """A favorite Question of a User.""" + question = models.ForeignKey(Question) + user = models.ForeignKey(User, related_name='user_favorite_questions') + added_at = models.DateTimeField(default=datetime.datetime.now) + class Meta: + db_table = u'favorite_question' + def __unicode__(self): + return '[%s] favorited at %s' %(self.user, self.added_at) + class QuestionRevision(models.Model): """A revision of a Question.""" question = models.ForeignKey(Question, related_name='revisions') @@ -422,16 +432,6 @@ class AnswerRevision(models.Model): flat=True)[0] + 1 super(AnswerRevision, self).save(**kwargs) -class FavoriteQuestion(models.Model): - """A favorite Question of a User.""" - question = models.ForeignKey(Question) - user = models.ForeignKey(User, related_name='user_favorite_questions') - added_at = models.DateTimeField(default=datetime.datetime.now) - class Meta: - db_table = u'favorite_question' - def __unicode__(self): - return '[%s] favorited at %s' %(self.user, self.added_at) - class Badge(models.Model): """Awarded for notable actions performed on the site by Users.""" GOLD = 1 diff --git a/forum/templatetags/extra_filters.py b/forum/templatetags/extra_filters.py index cec97920..d8b8e61f 100644 --- a/forum/templatetags/extra_filters.py +++ b/forum/templatetags/extra_filters.py @@ -1,8 +1,13 @@ -from django import template +from django import template from forum import auth register = template.Library() +@template.defaultfilters.stringfilter +@register.filter +def collapse(input): + return ' '.join(input.split()) + @register.filter def can_vote_up(user): return auth.can_vote_up(user) @@ -80,4 +85,4 @@ def cnprog_intword(number): else: return number except: - return number
\ No newline at end of file + return number diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index ac4e6ca3..06a2d27c 100644 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -14,7 +14,8 @@ register = template.Library() GRAVATAR_TEMPLATE = ('<img width="%(size)s" height="%(size)s" ' 'src="http://www.gravatar.com/avatar/%(gravatar_hash)s' - '?s=%(size)s&d=identicon&r=PG">') + '?s=%(size)s&d=identicon&r=PG" ' + 'alt="%(username)s\'s gravatar image" />') @register.simple_tag def gravatar(user, size): @@ -26,11 +27,14 @@ def gravatar(user, size): """ try: gravatar = user['gravatar'] + username = user['username'] except (TypeError, AttributeError, KeyError): gravatar = user.gravatar + username = user.username return mark_safe(GRAVATAR_TEMPLATE % { 'size': size, 'gravatar_hash': gravatar, + 'username': template.defaultfilters.urlencode(username), }) MAX_FONTSIZE = 18 |