summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-06-18 15:37:46 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2012-06-18 17:17:31 -0600
commite99720f1f6699ed3fc6afe52e93b2d9f9b33fd5c (patch)
treebe05a60a62847473991eede161e971e6066ea575
parentc33fb405eae93e66578fe2ae2b5423474dee0af1 (diff)
downloadaskbot-e99720f1f6699ed3fc6afe52e93b2d9f9b33fd5c.tar.gz
askbot-e99720f1f6699ed3fc6afe52e93b2d9f9b33fd5c.tar.bz2
askbot-e99720f1f6699ed3fc6afe52e93b2d9f9b33fd5c.zip
started migrating the score field to points, models, views and test
migrated. Added search indexes.
-rw-r--r--askbot/models/__init__.py32
-rw-r--r--askbot/models/badges.py30
-rw-r--r--askbot/models/post.py18
-rw-r--r--askbot/models/question.py26
-rw-r--r--askbot/models/repute.py16
-rw-r--r--askbot/search/haystack/__init__.py38
-rw-r--r--askbot/tests/badge_tests.py64
-rw-r--r--askbot/tests/db_api_tests.py12
-rw-r--r--askbot/tests/post_model_tests.py6
-rw-r--r--askbot/views/commands.py15
-rw-r--r--askbot/views/readers.py10
-rw-r--r--askbot/views/users.py10
-rw-r--r--askbot/views/writers.py18
13 files changed, 151 insertions, 144 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index c4c11cb4..621ae6df 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -274,7 +274,7 @@ def user_get_marked_tag_names(self, reason):
attr_name = MARKED_TAG_PROPERTY_MAP[reason]
wildcard_tags = getattr(self, attr_name).split()
tag_names.extend(wildcard_tags)
-
+
return tag_names
def user_has_affinity_to_question(self, question = None, affinity_type = None):
@@ -338,7 +338,7 @@ def user_can_have_strong_url(self):
return (self.reputation >= askbot_settings.MIN_REP_TO_HAVE_STRONG_URL)
def user_can_post_by_email(self):
- """True, if reply by email is enabled
+ """True, if reply by email is enabled
and user has sufficient reputatiton"""
return askbot_settings.REPLY_BY_EMAIL and \
self.reputation > askbot_settings.MIN_REP_TO_POST_BY_EMAIL
@@ -749,7 +749,7 @@ def user_assert_can_delete_question(self, question = None):
#if there are answers by other people,
#then deny, unless user in admin or moderator
answer_count = question.thread.all_answers()\
- .exclude(author=self).exclude(score__lte=0).count()
+ .exclude(author=self).exclude(points__lte=0).count()
if answer_count > 0:
if self.is_administrator() or self.is_moderator():
@@ -2126,7 +2126,7 @@ def user_get_groups_membership_info(self, groups):
info[group.id]['can_join'] = group.group_profile.can_accept_user(self)
return info
-
+
def user_get_karma_summary(self):
@@ -2271,12 +2271,12 @@ def _process_vote(user, post, timestamp=None, cancel=False, vote_type=None):
auth.onDownVotedCanceled(vote, post, user, timestamp)
else:
auth.onDownVoted(vote, post, user, timestamp)
-
+
post.thread.invalidate_cached_data()
if post.post_type == 'question':
#denormalize the question post score on the thread
- post.thread.score = post.score
+ post.thread.points = post.points
post.thread.save()
post.thread.update_summary_html()
@@ -2363,12 +2363,12 @@ def flag_post(user, post, timestamp=None, cancel=False, cancel_all = False, forc
content_type = post_content_type, object_id=post.id
)
for flag in all_flags:
- auth.onUnFlaggedItem(post, flag.user, timestamp=timestamp)
+ auth.onUnFlaggedItem(post, flag.user, timestamp=timestamp)
elif cancel:#todo: can't unflag?
if force == False:
user.assert_can_remove_flag_offensive(post = post)
- auth.onUnFlaggedItem(post, user, timestamp=timestamp)
+ auth.onUnFlaggedItem(post, user, timestamp=timestamp)
else:
if force == False:
@@ -2708,17 +2708,17 @@ def format_instant_notification_email(
if update_type.endswith('update'):
user_action = _('%(user)s edited a %(post_link)s.')
else:
- user_action = _('%(user)s posted a %(post_link)s')
+ user_action = _('%(user)s posted a %(post_link)s')
elif post.is_answer():
if update_type.endswith('update'):
user_action = _('%(user)s edited an %(post_link)s.')
else:
- user_action = _('%(user)s posted an %(post_link)s.')
+ user_action = _('%(user)s posted an %(post_link)s.')
elif post.is_question():
if update_type.endswith('update'):
user_action = _('%(user)s edited a %(post_link)s.')
else:
- user_action = _('%(user)s posted a %(post_link)s.')
+ user_action = _('%(user)s posted a %(post_link)s.')
else:
raise ValueError('unrecognized post type')
@@ -2746,7 +2746,7 @@ def format_instant_notification_email(
reply_separator += '</p>'
else:
reply_separator = user_action
-
+
update_data = {
'update_author_name': from_user.username,
'receiving_user_name': to_user.username,
@@ -2775,7 +2775,7 @@ def get_reply_to_addresses(user, post):
the first address - always a real email address,
the second address is not ``None`` only for "question" posts.
- When the user is notified of a new question -
+ When the user is notified of a new question -
i.e. `post` is a "quesiton", he/she
will need to choose - whether to give a question or a comment,
thus we return the second address - for the comment reply.
@@ -2857,7 +2857,7 @@ def send_instant_notifications_about_activity_in_post(
update_type = update_type,
template = get_template('instant_notification.html')
)
-
+
headers['Reply-To'] = reply_address
mail.send_mail(
subject_line = subject_line,
@@ -2878,7 +2878,7 @@ def notify_author_of_published_revision(
if revision.should_notify_author_about_publishing(was_approved):
from askbot.tasks import notify_author_of_published_revision_celery_task
notify_author_of_published_revision_celery_task.delay(revision)
-
+
#todo: move to utils
def calculate_gravatar_hash(instance, **kwargs):
@@ -3255,7 +3255,7 @@ def update_user_avatar_type_flag(instance, **kwargs):
def make_admin_if_first_user(instance, **kwargs):
"""first user automatically becomes an administrator
the function is run only once in the interpreter session
- """
+ """
import sys
#have to check sys.argv to satisfy the test runner
#which fails with the cache-based skipping
diff --git a/askbot/models/badges.py b/askbot/models/badges.py
index 61149df3..244c8e2f 100644
--- a/askbot/models/badges.py
+++ b/askbot/models/badges.py
@@ -43,13 +43,13 @@ class Badge(object):
"""
def __init__(self,
key = '',
- name = '',
+ name = '',
level = None,
description = None,
multiple = False):
#key - must be an ASCII only word
- self.key = key
+ self.key = key
self.name = name
self.level = level
self.description = description
@@ -114,11 +114,11 @@ class Badge(object):
def consider_award(self, actor = None,
context_object = None, timestamp = None):
- """Normally this method should be reimplemented
+ """Normally this method should be reimplemented
in subclass, but some badges are awarded without
checks. Those do no need to override this method
- actor - user who committed some action, context_object -
+ actor - user who committed some action, context_object -
the object related to the award situation, e.g. answer
"""
return self.award(actor, context_object, timestamp)
@@ -141,7 +141,7 @@ class Disciplined(Badge):
if context_object.author != actor:
return False
- if context_object.score >= \
+ if context_object.points>= \
askbot_settings.DISCIPLINED_BADGE_MIN_UPVOTES:
return self.award(actor, context_object, timestamp)
@@ -163,7 +163,7 @@ class PeerPressure(Badge):
if context_object.author != actor:
return False
- if context_object.score <= \
+ if context_object.points<= \
-1 * askbot_settings.PEER_PRESSURE_BADGE_MIN_DOWNVOTES:
return self.award(actor, context_object, timestamp)
return False
@@ -181,12 +181,12 @@ class Teacher(Badge):
multiple = False
)
- def consider_award(self, actor = None,
+ def consider_award(self, actor = None,
context_object = None, timestamp = None):
if context_object.post_type != 'answer':
return False
- if context_object.score >= askbot_settings.TEACHER_BADGE_MIN_UPVOTES:
+ if context_object.points>= askbot_settings.TEACHER_BADGE_MIN_UPVOTES:
return self.award(context_object.author, context_object, timestamp)
return False
@@ -268,7 +268,7 @@ class SelfLearner(Badge):
question = context_object.thread._question_post()
answer = context_object
- if question.author == answer.author and answer.score >= min_upvotes:
+ if question.author == answer.author and answer.points >= min_upvotes:
self.award(context_object.author, context_object, timestamp)
class QualityPost(Badge):
@@ -294,7 +294,7 @@ class QualityPost(Badge):
context_object = None, timestamp = None):
if context_object.post_type not in ('answer', 'question'):
return False
- if context_object.score >= self.min_votes:
+ if context_object.points >= self.min_votes:
return self.award(context_object.author, context_object, timestamp)
return False
@@ -485,7 +485,7 @@ class VotedAcceptedAnswer(Badge):
if context_object.post_type != 'answer':
return None
answer = context_object
- if answer.score >= self.min_votes and answer.accepted():
+ if answer.points >= self.min_votes and answer.accepted():
return self.award(answer.author, answer, timestamp)
class Enlightened(VotedAcceptedAnswer):
@@ -537,7 +537,7 @@ class Necromancer(Badge):
delta = datetime.timedelta(askbot_settings.NECROMANCER_BADGE_MIN_DELAY)
min_score = askbot_settings.NECROMANCER_BADGE_MIN_UPVOTES
if answer.added_at - question.added_at >= delta \
- and answer.score >= min_score:
+ and answer.points >= min_score:
return self.award(answer.author, answer, timestamp)
return False
@@ -723,7 +723,7 @@ class Enthusiast(Badge):
return False
class Commentator(Badge):
- """Commentator is a bronze badge that is
+ """Commentator is a bronze badge that is
awarded once when user posts a certain number of
comments"""
def __init__(self):
@@ -778,7 +778,7 @@ class Expert(Badge):
)
ORIGINAL_DATA = """
-
+
extra badges from stackexchange
* commentator - left n comments (single)
* enthusiast, fanatic - visited site n days in a row (s)
@@ -894,7 +894,7 @@ award_badges_signal = Signal(
#context_object - database object related to the event, e.g. question
@auto_now_timestamp
-def award_badges(event = None, actor = None,
+def award_badges(event = None, actor = None,
context_object = None, timestamp = None, **kwargs):
"""function that is called when signal `award_badges_signal` is sent
"""
diff --git a/askbot/models/post.py b/askbot/models/post.py
index c08b940b..c280acf4 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -199,7 +199,7 @@ class PostManager(BaseQuerySetManager):
comment = const.POST_STATUS['default_version'],
by_email = by_email
)
-
+
return post
#todo: instead of this, have Thread.add_answer()
@@ -308,7 +308,7 @@ class Post(models.Model):
locked_by = models.ForeignKey(User, null=True, blank=True, related_name='locked_posts')
locked_at = models.DateTimeField(null=True, blank=True)
- score = models.IntegerField(default=0)
+ points = models.IntegerField(default=0, db_column='score')
vote_up_count = models.IntegerField(default=0)
vote_down_count = models.IntegerField(default=0)
@@ -344,6 +344,14 @@ class Post(models.Model):
app_label = 'askbot'
db_table = 'askbot_post'
+ #property to support legacy themes in case there are.
+ @property
+ def score(self):
+ return int(self.points)
+ @score.setter
+ def score(self, number):
+ if number:
+ self.points = int(number)
def parse_post_text(self):
"""typically post has a field to store raw source text
@@ -670,7 +678,7 @@ class Post(models.Model):
does not talk to the actual cache system
"""
self._cached_comments = comments
-
+
def get_cached_comments(self):
try:
return self._cached_comments
@@ -1684,7 +1692,7 @@ class PostRevision(models.Model):
text = models.TextField()
approved = models.BooleanField(default=False, db_index=True)
- approved_by = models.ForeignKey(User, null = True, blank = True)
+ approved_by = models.ForeignKey(User, null = True, blank = True)
approved_at = models.DateTimeField(null = True, blank = True)
by_email = models.BooleanField(default = False)#true, if edited by email
@@ -1765,7 +1773,7 @@ class PostRevision(models.Model):
body_text = body_text,
recipient_list = [self.author.email,],
)
-
+
else:
message = _(
'Your post was placed on the moderation queue '
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 1729b531..d0e5c5b2 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -164,7 +164,7 @@ class ThreadManager(models.Manager):
# TODO: add a possibility to see deleted questions
qs = self.filter(
- posts__post_type='question',
+ posts__post_type='question',
posts__deleted=False,
) # (***) brings `askbot_post` into the SQL query, see the ordering section below
@@ -288,8 +288,8 @@ class ThreadManager(models.Manager):
'activity-asc': 'last_activity_at',
'answers-desc': '-answer_count',
'answers-asc': 'answer_count',
- 'votes-desc': '-score',
- 'votes-asc': 'score',
+ 'votes-desc': '-points',
+ 'votes-asc': 'points',
'relevance-desc': '-relevance', # special Postgresql-specific ordering, 'relevance' quaso-column is added by get_for_query()
}
@@ -318,7 +318,7 @@ class ThreadManager(models.Manager):
#threads = [thread for thread in threads if not thread.summary_html_cached()]
page_questions = Post.objects.filter(post_type='question', thread__in=[obj.id for obj in threads])\
- .only('id', 'thread', 'score', 'is_anonymous', 'summary', 'post_type', 'deleted') # pick only the used fields
+ .only('id', 'thread', 'points', 'is_anonymous', 'summary', 'post_type', 'deleted') # pick only the used fields
page_question_map = {}
for pq in page_questions:
page_question_map[pq.thread_id] = pq
@@ -402,13 +402,23 @@ class Thread(models.Model):
answer_accepted_at = models.DateTimeField(null=True, blank=True)
added_at = models.DateTimeField(default = datetime.datetime.now)
- score = models.IntegerField(default = 0)
+ #db_column will be removed later
+ points = models.IntegerField(default = 0, db_column='score')
objects = ThreadManager()
-
+
class Meta:
app_label = 'askbot'
+ #property to support legacy themes in case there are.
+ @property
+ def score(self):
+ return int(self.points)
+ @score.setter
+ def score(self, number):
+ if number:
+ self.points = int(number)
+
def _question_post(self, refresh=False):
if refresh and hasattr(self, '_question_cache'):
delattr(self, '_question_cache')
@@ -526,7 +536,7 @@ class Thread(models.Model):
return 'thread-data-%s-%s' % (self.id, sort_method)
def invalidate_cached_post_data(self):
- """needs to be called when anything notable
+ """needs to be called when anything notable
changes in the post data - on votes, adding,
deleting, editing content"""
#we can call delete_many() here if using Django > 1.2
@@ -559,7 +569,7 @@ class Thread(models.Model):
{
'latest':'-added_at',
'oldest':'added_at',
- 'votes':'-score'
+ 'votes':'-points'
}[sort_method]
)
#1) collect question, answer and comment posts and list of post id's
diff --git a/askbot/models/repute.py b/askbot/models/repute.py
index 33ec3a42..a6e9d7d1 100644
--- a/askbot/models/repute.py
+++ b/askbot/models/repute.py
@@ -75,14 +75,14 @@ class Vote(models.Model):
"""
#importing locally because of circular dependency
from askbot import auth
- score_before = self.voted_post.score
+ score_before = self.voted_post.points
if self.vote > 0:
# cancel upvote
auth.onUpVotedCanceled(self, self.voted_post, self.user)
else:
# cancel downvote
auth.onDownVotedCanceled(self, self.voted_post, self.user)
- score_after = self.voted_post.score
+ score_after = self.voted_post.points
return score_after - score_before
@@ -94,7 +94,7 @@ class BadgeData(models.Model):
awarded_to = models.ManyToManyField(User, through='Award', related_name='badges')
def _get_meta_data(self):
- """retrieves badge metadata stored
+ """retrieves badge metadata stored
in a file"""
from askbot.models import badges
return badges.get_badge(self.slug)
@@ -171,9 +171,9 @@ class ReputeManager(models.Manager):
tomorrow = today + datetime.timedelta(1)
rep_types = (1,-8)
sums = self.filter(models.Q(reputation_type__in=rep_types),
- user=user,
+ user=user,
reputed_at__range=(today, tomorrow),
- ).aggregate(models.Sum('positive'), models.Sum('negative'))
+ ).aggregate(models.Sum('positive'), models.Sum('negative'))
if sums:
pos = sums['positive__sum']
neg = sums['negative__sum']
@@ -200,7 +200,7 @@ class Repute(models.Model):
#assigned_by_moderator - so that reason can be displayed
#in that case Question field will be blank
comment = models.CharField(max_length=128, null=True)
-
+
objects = ReputeManager()
def __unicode__(self):
@@ -214,7 +214,7 @@ class Repute(models.Model):
"""returns HTML snippet with a link to related question
or a text description for a the reason of the reputation change
- in the implementation description is returned only
+ in the implementation description is returned only
for Repute.reputation_type == 10 - "assigned by the moderator"
part of the purpose of this method is to hide this idiosyncracy
@@ -242,7 +242,7 @@ class Repute(models.Model):
return '<a href="%(url)s" title="%(link_title)s">%(question_title)s</a>' \
% {
- 'url': self.question.get_absolute_url(),
+ 'url': self.question.get_absolute_url(),
'question_title': escape(self.question.thread.title),
'link_title': escape(link_title)
}
diff --git a/askbot/search/haystack/__init__.py b/askbot/search/haystack/__init__.py
index 8376a0fc..8f008a93 100644
--- a/askbot/search/haystack/__init__.py
+++ b/askbot/search/haystack/__init__.py
@@ -5,39 +5,25 @@ except ImportError:
from askbot.models import Post, Thread, Tag, User
-#class ThreadIndex(indexes.SearchIndex):
-# text = indexes.CharField(document=True, use_template=True)
-# title = indexes.CharField(model_attr='title')
-#
-# def index_queryset(self):
-# return Thread.objects.all()
-#
-# def prepare(self, obj):
-# self.prepared_data = super(ThreadIndex, self).prepare(object)
-#
-# self.prepared_data['tags'] = [tag.name for tag in objects.tags.all()]
-#
-#class PostIndex(indexes.SearchIndex):
-# text = indexes.CharField(document=True, use_template=True)
-# post_text = indexes.CharField(model_attr='text')
-# author = indexes.CharField(model_attr='user')
-#
-# def index_queryset(self):
-# return Post.objects.all()
+class ThreadIndex(indexes.SearchIndex):
+ text = indexes.CharField(document=True, use_template=True)
+ title = indexes.CharField(model_attr='title')
+
+ def index_queryset(self):
+ return Thread.objects.all()
+
+ def prepare(self, obj):
+ self.prepared_data = super(ThreadIndex, self).prepare(object)
+
+ self.prepared_data['tags'] = [tag.name for tag in objects.tags.all()]
class PostIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
post_text = indexes.CharField(model_attr='text')
- title = indexes.CharField(model_attr='thread__jtitle')
author = indexes.CharField(model_attr='user')
- def prepare(self, obj):
- self.prepared_data = super(PostIndex, self).prepare(obj)
- if obj.thread:
- self.prepared_data['tags'] = [tag.name for tag in obj.thread.tags.all()]
-
def index_queryset(self):
return Post.objects.all()
site.register(Post, PostIndex)
-#site.register(Thread, ThreadIndex)
+site.register(Thread, ThreadIndex)
diff --git a/askbot/tests/badge_tests.py b/askbot/tests/badge_tests.py
index dbb37dde..1a4cb2b5 100644
--- a/askbot/tests/badge_tests.py
+++ b/askbot/tests/badge_tests.py
@@ -24,7 +24,7 @@ class BadgeTests(AskbotTestCase):
def assert_accepted_answer_badge_works(self,
badge_key = None,
- min_score = None,
+ min_points = None,
expected_count = 1,
previous_count = 0,
trigger = None
@@ -32,7 +32,7 @@ class BadgeTests(AskbotTestCase):
assert(trigger in ('accept_best_answer', 'upvote_answer'))
question = self.post_question(user = self.u1)
answer = self.post_answer(user = self.u2, question = question)
- answer.score = min_score - 1
+ answer.points = min_points - 1
answer.save()
recipient = answer.author
@@ -47,29 +47,29 @@ class BadgeTests(AskbotTestCase):
self.u1.upvote(answer)
self.assert_have_badge(badge_key, recipient, expected_count)
- def assert_upvoted_answer_badge_works(self,
+ def assert_upvoted_answer_badge_works(self,
badge_key = None,
- min_score = None,
+ min_points = None,
multiple = False
):
"""test answer badge where answer author is the recipient
where badge award is triggered by upvotes
- * min_score - minimum # of upvotes required
+ * min_points - minimum # of upvotes required
* multiple - multiple award or not
* badge_key - key on askbot.models.badges.Badge object
"""
question = self.post_question(user = self.u1)
answer = self.post_answer(user = self.u2, question = question)
- answer.score = min_score - 1
+ answer.points = min_points - 1
answer.save()
self.u1.upvote(answer)
self.assert_have_badge(badge_key, recipient = self.u2)
self.u3.upvote(answer)
self.assert_have_badge(badge_key, recipient = self.u2, expected_count = 1)
-
+
#post another question and check that there are no new badges
answer2 = self.post_answer(user = self.u2, question = question)
- answer2.score = min_score - 1
+ answer2.points = min_points - 1
answer2.save()
self.u1.upvote(answer2)
@@ -84,28 +84,28 @@ class BadgeTests(AskbotTestCase):
expected_count = expected_count
)
- def assert_upvoted_question_badge_works(self,
+ def assert_upvoted_question_badge_works(self,
badge_key = None,
- min_score = None,
+ min_points = None,
multiple = False
):
"""test question badge where question author is the recipient
where badge award is triggered by upvotes
- * min_score - minimum # of upvotes required
+ * min_points - minimum # of upvotes required
* multiple - multiple award or not
* badge_key - key on askbot.models.badges.Badge object
"""
question = self.post_question(user = self.u1)
- question.score = min_score - 1
+ question.points = min_points - 1
question.save()
self.u2.upvote(question)
self.assert_have_badge(badge_key, recipient = self.u1)
self.u3.upvote(question)
self.assert_have_badge(badge_key, recipient = self.u1, expected_count = 1)
-
+
#post another question and check that there are no new badges
question2 = self.post_question(user = self.u1)
- question2.score = min_score - 1
+ question2.points = min_points - 1
question2.save()
self.u2.upvote(question2)
@@ -122,13 +122,13 @@ class BadgeTests(AskbotTestCase):
def test_disciplined_badge(self):
question = self.post_question(user = self.u1)
- question.score = settings.DISCIPLINED_BADGE_MIN_UPVOTES
+ question.points = settings.DISCIPLINED_BADGE_MIN_UPVOTES
question.save()
self.u1.delete_question(question)
self.assert_have_badge('disciplined', recipient = self.u1)
question2 = self.post_question(user = self.u1)
- question2.score = settings.DISCIPLINED_BADGE_MIN_UPVOTES
+ question2.points = settings.DISCIPLINED_BADGE_MIN_UPVOTES
question2.save()
self.u1.delete_question(question2)
self.assert_have_badge('disciplined', recipient = self.u1, expected_count = 2)
@@ -136,7 +136,7 @@ class BadgeTests(AskbotTestCase):
def test_peer_pressure_badge(self):
question = self.post_question(user = self.u1)
answer = self.post_answer(user = self.u1, question = question)
- answer.score = -1*settings.PEER_PRESSURE_BADGE_MIN_DOWNVOTES
+ answer.points = -1*settings.PEER_PRESSURE_BADGE_MIN_DOWNVOTES
answer.save()
self.u1.delete_answer(answer)
self.assert_have_badge('peer-pressure', recipient = self.u1)
@@ -144,21 +144,21 @@ class BadgeTests(AskbotTestCase):
def test_teacher_badge(self):
self.assert_upvoted_answer_badge_works(
badge_key = 'teacher',
- min_score = settings.TEACHER_BADGE_MIN_UPVOTES,
+ min_points = settings.TEACHER_BADGE_MIN_UPVOTES,
multiple = False
)
def test_nice_answer_badge(self):
self.assert_upvoted_answer_badge_works(
badge_key = 'nice-answer',
- min_score = settings.NICE_ANSWER_BADGE_MIN_UPVOTES,
+ min_points = settings.NICE_ANSWER_BADGE_MIN_UPVOTES,
multiple = True
)
def test_nice_question_badge(self):
self.assert_upvoted_question_badge_works(
badge_key = 'nice-question',
- min_score = settings.NICE_QUESTION_BADGE_MIN_UPVOTES,
+ min_points = settings.NICE_QUESTION_BADGE_MIN_UPVOTES,
multiple = True
)
@@ -226,7 +226,7 @@ class BadgeTests(AskbotTestCase):
question = self.post_question(user = self.u1)
answer = self.post_answer(user = self.u1, question = question)
min_votes = settings.SELF_LEARNER_BADGE_MIN_UPVOTES
- answer.score = min_votes - 1
+ answer.points = min_votes - 1
answer.save()
self.u2.upvote(answer)
self.assert_have_badge('self-learner', recipient = self.u1)
@@ -234,14 +234,14 @@ class BadgeTests(AskbotTestCase):
#copy-paste of the first question, except expect second badge
question = self.post_question(user = self.u1)
answer = self.post_answer(user = self.u1, question = question)
- answer.score = min_votes - 1
+ answer.points = min_votes - 1
answer.save()
self.u2.upvote(answer)
self.assert_have_badge('self-learner', recipient = self.u1, expected_count = 2)
question = self.post_question(user = self.u2)
answer = self.post_answer(user = self.u1, question = question)
- answer.score = min_votes - 1
+ answer.points = min_votes - 1
answer.save()
self.u2.upvote(answer)
#no badge when asker != answerer
@@ -280,13 +280,13 @@ class BadgeTests(AskbotTestCase):
def assert_enlightened_badge_works(self, trigger):
self.assert_accepted_answer_badge_works(
'enlightened',
- min_score = settings.ENLIGHTENED_BADGE_MIN_UPVOTES,
+ min_points = settings.ENLIGHTENED_BADGE_MIN_UPVOTES,
expected_count = 1,
trigger = trigger
)
self.assert_accepted_answer_badge_works(
'enlightened',
- min_score = settings.ENLIGHTENED_BADGE_MIN_UPVOTES,
+ min_points = settings.ENLIGHTENED_BADGE_MIN_UPVOTES,
expected_count = 1,
previous_count = 1,
trigger = trigger
@@ -295,13 +295,13 @@ class BadgeTests(AskbotTestCase):
def assert_guru_badge_works(self, trigger):
self.assert_accepted_answer_badge_works(
'guru',
- min_score = settings.GURU_BADGE_MIN_UPVOTES,
+ min_points = settings.GURU_BADGE_MIN_UPVOTES,
expected_count = 1,
trigger = trigger
)
self.assert_accepted_answer_badge_works(
'guru',
- min_score = settings.GURU_BADGE_MIN_UPVOTES,
+ min_points = settings.GURU_BADGE_MIN_UPVOTES,
previous_count = 1,
expected_count = 2,
trigger = trigger
@@ -328,8 +328,8 @@ class BadgeTests(AskbotTestCase):
user = self.u2,
question = question,
timestamp = future
- )
- answer.score = settings.NECROMANCER_BADGE_MIN_UPVOTES - 1
+ )
+ answer.points = settings.NECROMANCER_BADGE_MIN_UPVOTES - 1
answer.save()
self.assert_have_badge('necromancer', self.u2, expected_count = 0)
self.u1.upvote(answer)
@@ -455,7 +455,7 @@ class BadgeTests(AskbotTestCase):
self.u1.toggle_favorite_question(question)
"""no gaming"""
self.assert_have_badge('stellar-question', self.u1, 0)
-
+
def test_stellar_badge3(self):
question = self.post_question(user = self.u1)
settings.update('STELLAR_QUESTION_BADGE_MIN_STARS', 2)
@@ -478,9 +478,9 @@ class BadgeTests(AskbotTestCase):
self.post_comment(user = self.u1, parent_post = question)
self.assert_have_badge('commentator', self.u1, 0)
- self.post_comment(user = self.u1, parent_post = question)
+ self.post_comment(user = self.u1, parent_post = question)
self.assert_have_badge('commentator', self.u1, 1)
- self.post_comment(user = self.u1, parent_post = question)
+ self.post_comment(user = self.u1, parent_post = question)
self.assert_have_badge('commentator', self.u1, 1)
def test_taxonomist_badge(self):
diff --git a/askbot/tests/db_api_tests.py b/askbot/tests/db_api_tests.py
index 3a0c9582..86c97e6d 100644
--- a/askbot/tests/db_api_tests.py
+++ b/askbot/tests/db_api_tests.py
@@ -1,4 +1,4 @@
-"""Tests database api - the basic data entry
+"""Tests database api - the basic data entry
functions that happen on behalf of users
e.g. ``some_user.do_something(...)``
@@ -240,7 +240,7 @@ class UserLikeTagTests(AskbotTestCase):
self.setup_wildcard('aouaou* o* on* oeu*', 'bad')
self.assert_affinity_is('like', False)
self.assert_affinity_is('dislike', True)
-
+
self.setup_wildcard('one*', 'good')
self.assert_affinity_is('like', True)
self.assert_affinity_is('dislike', False)
@@ -288,7 +288,7 @@ class GlobalTagSubscriberGetterTests(AskbotTestCase):
self.assertEquals(actual_subscribers, expected_subscribers)
def test_nobody_likes_any_tags(self):
- """no-one had marked tags, so the set
+ """no-one had marked tags, so the set
of subscribers must be empty
"""
self.assert_subscribers_are(
@@ -387,15 +387,15 @@ class CommentTests(AskbotTestCase):
def test_other_user_can_cancel_upvote(self):
self.test_other_user_can_upvote_comment()
comment = models.Post.objects.get_comments().get(id = self.comment.id)
- self.assertEquals(comment.score, 1)
+ self.assertEquals(comment.points, 1)
self.other_user.upvote(comment, cancel = True)
comment = models.Post.objects.get_comments().get(id = self.comment.id)
- self.assertEquals(comment.score, 0)
+ self.assertEquals(comment.points, 0)
class TagAndGroupTests(AskbotTestCase):
def setUp(self):
self.u1 = self.create_user('u1')
-
+
def test_group_cannot_create_case_variant_tag(self):
self.post_question(user = self.u1, tags = 'one two three')
models.Tag.group_tags.get_or_create(user = self.u1, group_name = 'One')
diff --git a/askbot/tests/post_model_tests.py b/askbot/tests/post_model_tests.py
index 9a4d47c8..6fd2257b 100644
--- a/askbot/tests/post_model_tests.py
+++ b/askbot/tests/post_model_tests.py
@@ -613,7 +613,7 @@ class ThreadRenderCacheUpdateTests(AskbotTestCase):
def test_question_upvote_downvote(self):
question = self.post_question()
- question.score = 5
+ question.points = 5
question.vote_up_count = 7
question.vote_down_count = 2
question.save()
@@ -626,7 +626,7 @@ class ThreadRenderCacheUpdateTests(AskbotTestCase):
data = simplejson.loads(response.content)
self.assertEqual(1, data['success'])
- self.assertEqual(6, data['count']) # 6 == question.score(5) + 1
+ self.assertEqual(6, data['count']) # 6 == question.points(5) + 1
thread = Thread.objects.get(id=question.thread.id)
@@ -642,7 +642,7 @@ class ThreadRenderCacheUpdateTests(AskbotTestCase):
data = simplejson.loads(response.content)
self.assertEqual(1, data['success'])
- self.assertEqual(5, data['count']) # 6 == question.score(6) - 1
+ self.assertEqual(5, data['count']) # 6 == question.points(6) - 1
thread = Thread.objects.get(id=question.thread.id)
diff --git a/askbot/views/commands.py b/askbot/views/commands.py
index e343c85e..6fe99dfe 100644
--- a/askbot/views/commands.py
+++ b/askbot/views/commands.py
@@ -160,7 +160,7 @@ def process_vote(user = None, vote_direction = None, post = None):
if vote != None:
user.assert_can_revoke_old_vote(vote)
score_delta = vote.cancel()
- response_data['count'] = post.score + score_delta
+ response_data['count'] = post.points+ score_delta
response_data['status'] = 1 #this means "cancel"
else:
@@ -183,7 +183,7 @@ def process_vote(user = None, vote_direction = None, post = None):
else:
vote = user.downvote(post = post)
- response_data['count'] = post.score
+ response_data['count'] = post.points
response_data['status'] = 0 #this means "not cancel", normal operation
response_data['success'] = 1
@@ -326,7 +326,7 @@ def vote(request, id):
response_data['count'] = post.offensive_flag_count
response_data['success'] = 1
-
+
elif vote_type in ['7.6', '8.6']:
#flag question or answer
if vote_type == '7.6':
@@ -463,7 +463,7 @@ def get_tags_by_wildcard(request):
wildcard = request.GET.get('wildcard', None)
if wildcard is None:
raise Http404
-
+
matching_tags = models.Tag.objects.get_by_wildcards( [wildcard,] )
count = matching_tags.count()
names = matching_tags.values_list('name', flat = True)[:20]
@@ -513,7 +513,7 @@ def save_tag_wiki_text(request):
return {'html': tag_wiki.html}
else:
raise ValueError('invalid post data')
-
+
@decorators.get_only
def get_groups_list(request):
@@ -701,7 +701,8 @@ def upvote_comment(request):
)
else:
raise ValueError
- return {'score': comment.score}
+ #FIXME: rename js
+ return {'score': comment.points}
@csrf.csrf_exempt
@decorators.ajax_only
@@ -782,7 +783,7 @@ def edit_group_membership(request):
@decorators.admins_only
def save_group_logo_url(request):
"""saves urls for the group logo"""
- form = forms.GroupLogoURLForm(request.POST)
+ form = forms.GroupLogoURLForm(request.POST)
if form.is_valid():
group_id = form.cleaned_data['group_id']
image_url = form.cleaned_data['image_url']
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index c73b0c35..3689bd6f 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -413,7 +413,7 @@ def question(request, id):#refactor - long subroutine. display question body, an
return HttpResponseRedirect(reverse('index'))
elif show_answer:
- #if the url calls to view a particular answer to
+ #if the url calls to view a particular answer to
#question - we must check whether the question exists
#whether answer is actually corresponding to the current question
#and that the visitor is allowed to see it
@@ -455,7 +455,7 @@ def question(request, id):#refactor - long subroutine. display question body, an
user_post_id_list = [
id for id in post_to_author if post_to_author[id] == request.user.id
]
-
+
#resolve page number and comment number for permalinks
show_comment_position = None
if show_comment:
@@ -520,7 +520,7 @@ def question(request, id):#refactor - long subroutine. display question body, an
is_cacheable = False
elif show_comment_position > askbot_settings.MAX_COMMENTS_TO_SHOW:
is_cacheable = False
-
+
answer_form = AnswerForm(
initial = {
'wiki': question_post.wiki and askbot_settings.WIKI_ON,
@@ -608,5 +608,5 @@ def widget_questions(request):
data = {
'threads': threads[:askbot_settings.QUESTIONS_WIDGET_MAX_QUESTIONS]
}
- return render_into_skin('question_widget.html', data, request)
-
+ return render_into_skin('question_widget.html', data, request)
+
diff --git a/askbot/views/users.py b/askbot/views/users.py
index 8bc2909d..8588f132 100644
--- a/askbot/views/users.py
+++ b/askbot/views/users.py
@@ -99,7 +99,7 @@ def users(request, by_group = False, group_id = None, group_slug = None):
}
)
return HttpResponseRedirect(group_page_url)
-
+
is_paginated = True
@@ -331,7 +331,7 @@ def user_stats(request, user, context):
# Questions
#
questions = user.posts.get_questions().filter(**question_filter).\
- order_by('-score', '-thread__last_activity_at').\
+ order_by('-points', '-thread__last_activity_at').\
select_related('thread', 'thread__last_activity_by')[:100]
#added this if to avoid another query if questions is less than 100
@@ -347,7 +347,7 @@ def user_stats(request, user, context):
deleted=False,
thread__posts__deleted=False,
thread__posts__post_type='question',
- ).select_related('thread').order_by('-score', '-added_at')[:100]
+ ).select_related('thread').order_by('-points', '-added_at')[:100]
top_answer_count = len(top_answers)
@@ -381,7 +381,7 @@ def user_stats(request, user, context):
interesting_tag_names = None
ignored_tag_names = None
subscribed_tag_names = None
-
+
# tags = models.Post.objects.filter(author=user).values('id', 'thread', 'thread__tags')
# post_ids = set()
# thread_ids = set()
@@ -800,7 +800,7 @@ def user_favorites(request, user, context):
favorite_threads = user.user_favorite_questions.values_list('thread', flat=True)
questions = models.Post.objects.filter(post_type='question', thread__in=favorite_threads)\
.select_related('thread', 'thread__last_activity_by')\
- .order_by('-score', '-thread__last_activity_at')[:const.USER_VIEW_DATA_SIZE]
+ .order_by('-points', '-thread__last_activity_at')[:const.USER_VIEW_DATA_SIZE]
data = {
'active_tab':'users',
diff --git a/askbot/views/writers.py b/askbot/views/writers.py
index 232dbaea..9e03ab78 100644
--- a/askbot/views/writers.py
+++ b/askbot/views/writers.py
@@ -46,7 +46,7 @@ QUESTIONS_PAGE_SIZE = 10
ANSWERS_PAGE_SIZE = 10
@csrf.csrf_exempt
-def upload(request):#ajax upload file to a question or answer
+def upload(request):#ajax upload file to a question or answer
"""view that handles file upload via Ajax
"""
@@ -66,7 +66,7 @@ def upload(request):#ajax upload file to a question or answer
file_name_prefix = request.POST.get('file_name_prefix', '')
if file_name_prefix not in ('', 'group_logo_'):
raise exceptions.PermissionDenied('invalid upload file name prefix')
-
+
# check file type
f = request.FILES['file-upload']
#todo: extension checking should be replaced with mimetype checking
@@ -118,14 +118,14 @@ def __import_se_data(dump_file):
"""non-view function that imports the SE data
in the future may import other formats as well
- In this function stdout is temporarily
+ In this function stdout is temporarily
redirected, so that the underlying importer management
command could stream the output to the browser
todo: maybe need to add try/except clauses to restore
the redirects in the exceptional situations
"""
-
+
fake_stdout = tempfile.NamedTemporaryFile()
real_stdout = sys.stdout
sys.stdout = fake_stdout
@@ -381,7 +381,7 @@ def edit_question(request, id):
body_text = form.cleaned_data['text'],
revision_comment = form.cleaned_data['summary'],
tags = form.cleaned_data['tags'],
- wiki = is_wiki,
+ wiki = is_wiki,
edit_anonymously = is_anon_edit,
)
return HttpResponseRedirect(question.get_absolute_url())
@@ -421,7 +421,7 @@ def edit_answer(request, id):
if 'select_revision' in request.POST:
# user has changed revistion number
revision_form = forms.RevisionForm(
- answer,
+ answer,
latest_revision,
request.POST
)
@@ -550,7 +550,8 @@ def __generate_comments_json(obj, user):#non-view generates json data for the po
'user_id': comment_owner.id,
'is_deletable': is_deletable,
'is_editable': is_editable,
- 'score': comment.score,
+ 'points': comment.points,
+ 'score': comment.points, #to support js
'upvoted_by_user': getattr(comment, 'upvoted_by_user', False)
}
json_comments.append(comment_data)
@@ -615,7 +616,8 @@ def edit_comment(request):
'user_id': comment_post.author.id,
'is_deletable': is_deletable,
'is_editable': is_editable,
- 'score': comment_post.score,
+ 'score': comment_post.points, #to support unchanged js
+ 'points': comment_post.points,
'voted': comment_post.is_upvoted_by(request.user),
}