summaryrefslogtreecommitdiffstats
path: root/forum
diff options
context:
space:
mode:
authorBruno Sarlo <bruno@bruno-laptop.(none)>2009-08-11 02:07:44 -0300
committerBruno Sarlo <bruno@bruno-laptop.(none)>2009-08-11 02:07:44 -0300
commit3ba8dcf1da127053636b5e4c78eb6e4e523e5aba (patch)
treeb8d7deb8f9e245f8b5f8330860f867803a0e74dd /forum
parent306b82e6ef376fd3362dde41e3853dcf5688106d (diff)
parent1eacc7a42618e84766477fbcc2c32a1da3547115 (diff)
downloadaskbot-3ba8dcf1da127053636b5e4c78eb6e4e523e5aba.tar.gz
askbot-3ba8dcf1da127053636b5e4c78eb6e4e523e5aba.tar.bz2
askbot-3ba8dcf1da127053636b5e4c78eb6e4e523e5aba.zip
Merge branch 'master' of git://github.com/evgenyfadeev/CNPROG
Conflicts: forum/views.py locale/es/LC_MESSAGES/django.mo settings_local.py templates/answer_edit_tips.html templates/book.html templates/header.html templates/index.html templates/question_edit_tips.html templates/user_stats.html templates/user_tabs.html templates/users_questions.html
Diffstat (limited to 'forum')
-rw-r--r--forum/auth.py5
-rw-r--r--forum/models.py28
-rw-r--r--forum/templatetags/extra_filters.py9
-rw-r--r--forum/templatetags/extra_tags.py6
-rw-r--r--forum/views.py12
5 files changed, 42 insertions, 18 deletions
diff --git a/forum/auth.py b/forum/auth.py
index 36ca54d3..776746e8 100644
--- a/forum/auth.py
+++ b/forum/auth.py
@@ -167,7 +167,10 @@ def can_upload_files(request_user):
###########################################
def calculate_reputation(origin, offset):
result = int(origin) + int(offset)
- return result if result > 0 else 1
+ if (result > 0):
+ return result
+ else:
+ return 1
@transaction.commit_on_success
def onFlaggedItem(item, post, user):
diff --git a/forum/models.py b/forum/models.py
index 255eb21f..9510476a 100644
--- a/forum/models.py
+++ b/forum/models.py
@@ -179,6 +179,9 @@ class Question(models.Model):
"""Creates a list of Tag names from the ``tagnames`` attribute."""
return [name for name in self.tagnames.split(u' ')]
+ def tagname_meta_generator(self):
+ return ','.join([str(tag) for tag in self.tagname_list()])
+
def get_absolute_url(self):
return '%s%s' % (reverse('question', args=[self.id]), self.title.replace(' ', '-'))
@@ -271,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')
@@ -419,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
@@ -652,7 +655,10 @@ def record_comment_event(instance, created, **kwargs):
from django.contrib.contenttypes.models import ContentType
question_type = ContentType.objects.get_for_model(Question)
question_type_id = question_type.id
- type = TYPE_ACTIVITY_COMMENT_QUESTION if instance.content_type_id == question_type_id else TYPE_ACTIVITY_COMMENT_ANSWER
+ if (instance.content_type_id == question_type_id):
+ type = TYPE_ACTIVITY_COMMENT_QUESTION
+ else:
+ type = TYPE_ACTIVITY_COMMENT_ANSWER
activity = Activity(user=instance.user, active_at=instance.added_at, content_object=instance, activity_type=type)
activity.save()
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&amp;d=identicon&amp;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
diff --git a/forum/views.py b/forum/views.py
index a118cc57..626c93a3 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -332,7 +332,10 @@ def question(request, id):
answers = answers.select_related(depth=1)
favorited = question.has_favorite_by_user(request.user)
- question_vote = question.votes.select_related().filter(user=request.user)
+ if not request.user.is_anonymous():
+ question_vote = question.votes.select_related().filter(user=request.user)
+ else:
+ question_vote = None #is this correct?
if question_vote is not None and question_vote.count() > 0:
question_vote = question_vote[0]
@@ -1167,8 +1170,11 @@ def user_recent(request, user_id, user_view):
self.type_id = type
self.title = title
self.summary = summary
- self.title_link = u'/%s%s/%s#%s' %(_('questions/'),question_id, title, answer_id)\
- if int(answer_id) > 0 else u'/%s%s/%s' %(_('questions/'), question_id, title)
+ if int(answer_id) > 0:
+ self.title_link = u'/questions/%s/%s#%s' %(question_id, title, answer_id)
+ else:
+ self.title_link = u'/questions/%s/%s' %(question_id, title)
+
class AwardEvent:
def __init__(self, time, type, id):
self.time = time