From 02a9a126e3c0dec7e6e2a60e1463f30bd24edfc3 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 10 Jan 2011 03:47:20 -0500 Subject: some refactoring and removal of dead code --- askbot/auth.py | 96 ++--- askbot/const/__init__.py | 2 + askbot/models/__init__.py | 24 +- .../skins/default/templates/blocks/input_bar.html | 6 +- .../default/templates/user_profile/user_info.html | 2 +- askbot/templatetags/extra_filters.py | 16 - askbot/templatetags/extra_filters_jinja.py | 16 - askbot/templatetags/smart_if.py | 401 --------------------- askbot/urls.py | 1 - askbot/views/readers.py | 26 +- askbot/views/users.py | 4 +- 11 files changed, 60 insertions(+), 534 deletions(-) delete mode 100644 askbot/templatetags/smart_if.py diff --git a/askbot/auth.py b/askbot/auth.py index bfa55a22..6b12f08d 100644 --- a/askbot/auth.py +++ b/askbot/auth.py @@ -14,29 +14,9 @@ from askbot.models import Answer from askbot.models import signals from askbot.conf import settings as askbot_settings -# user preferences view permissions -def is_user_self(request_user, target_user): - return (request_user.is_authenticated() and request_user == target_user) - -def can_view_user_votes(request_user, target_user): - return (request_user.is_authenticated() and request_user == target_user) - -def can_view_user_preferences(request_user, target_user): - return (request_user.is_authenticated() and request_user == target_user) - -def can_view_user_edit(request_user, target_user): - return (request_user.is_authenticated() and request_user == target_user) - ########################################### ## actions and reputation changes event ########################################### -def calculate_reputation(origin, offset): - result = int(origin) + int(offset) - if (result > 0): - return result - else: - return 1 - @transaction.commit_on_success def onFlaggedItem(post, user, timestamp=None): if timestamp is None: @@ -45,10 +25,9 @@ def onFlaggedItem(post, user, timestamp=None): post.offensive_flag_count = post.offensive_flag_count + 1 post.save() - post.author.reputation = calculate_reputation( - post.author.reputation, - askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG - ) + post.author.receive_reputation( + askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG + ) post.author.save() question = post.get_origin_post() @@ -71,11 +50,9 @@ def onFlaggedItem(post, user, timestamp=None): #todo: These should be updated to work on same revisions. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST: - post.author.reputation = \ - calculate_reputation( - post.author.reputation, - askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION - ) + post.author.receive_reputation( + askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION + ) post.author.save() @@ -91,11 +68,9 @@ def onFlaggedItem(post, user, timestamp=None): reputation.save() elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST: - post.author.reputation = \ - calculate_reputation( - post.author.reputation, - askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION - ) + post.author.receive_reputation( + askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION + ) post.author.save() @@ -123,10 +98,9 @@ def onAnswerAccept(answer, user, timestamp=None): answer.save() answer.question.save() - answer.author.reputation = calculate_reputation( - answer.author.reputation, - askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE - ) + answer.author.receive_reputation( + askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE + ) answer.author.save() reputation = Repute(user=answer.author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, @@ -136,8 +110,7 @@ def onAnswerAccept(answer, user, timestamp=None): reputation=answer.author.reputation) reputation.save() - user.reputation = calculate_reputation(user.reputation, - askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER) + user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER) user.save() reputation = Repute(user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, @@ -157,8 +130,7 @@ def onAnswerAcceptCanceled(answer, user, timestamp=None): answer.save() answer.question.save() - answer.author.reputation = calculate_reputation( - answer.author.reputation, + answer.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE ) answer.author.save() @@ -173,8 +145,9 @@ def onAnswerAcceptCanceled(answer, user, timestamp=None): ) reputation.save() - user.reputation = calculate_reputation(user.reputation, - askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE) + user.receive_reputation( + askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE + ) user.save() reputation = Repute(user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE, @@ -198,8 +171,9 @@ def onUpVoted(vote, post, user, timestamp=None): author = post.author todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today(author) if todays_rep_gain < askbot_settings.MAX_REP_GAIN_PER_USER_PER_DAY: - author.reputation = calculate_reputation(author.reputation, - askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE) + author.receive_reputation( + askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE + ) author.save() question = post @@ -228,11 +202,9 @@ def onUpVotedCanceled(vote, post, user, timestamp=None): if not post.wiki: author = post.author - author.reputation = \ - calculate_reputation( - author.reputation, - askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION - ) + author.receive_reputation( + askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION + ) author.save() question = post @@ -261,10 +233,7 @@ def onDownVoted(vote, post, user, timestamp=None): if not post.wiki: author = post.author - author.reputation = calculate_reputation( - author.reputation, - askbot_settings.REP_LOSS_FOR_DOWNVOTING - ) + author.receive_reputation(askbot_settings.REP_LOSS_FOR_DOWNVOTING) author.save() question = post @@ -279,10 +248,9 @@ def onDownVoted(vote, post, user, timestamp=None): reputation=author.reputation) reputation.save() - user.reputation = calculate_reputation( - user.reputation, - askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE - ) + user.receive_reputation( + askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE + ) user.save() reputation = Repute(user=user, @@ -307,10 +275,9 @@ def onDownVotedCanceled(vote, post, user, timestamp=None): if not post.wiki: author = post.author - author.reputation = calculate_reputation( - author.reputation, - askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION - ) + author.receive_reputation( + askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION + ) author.save() question = post @@ -327,8 +294,7 @@ def onDownVotedCanceled(vote, post, user, timestamp=None): ) reputation.save() - user.reputation = calculate_reputation(user.reputation, - askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE) + user.receive_reputation(askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE) user.save() reputation = Repute(user=user, diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py index 693a7328..608cde43 100644 --- a/askbot/const/__init__.py +++ b/askbot/const/__init__.py @@ -249,6 +249,8 @@ BADGE_CSS_CLASSES = { } BADGE_DISPLAY_SYMBOL = '●' +MIN_REPUTATION = 1 + #an exception import * because that file has only strings from askbot.const.message_keys import * diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index f357789c..ad709509 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -53,16 +53,20 @@ User.add_to_class( User.add_to_class('email_isvalid', models.BooleanField(default=False)) User.add_to_class('email_key', models.CharField(max_length=32, null=True)) #hardcoded initial reputaion of 1, no setting for this one -User.add_to_class('reputation', models.PositiveIntegerField(default=1)) +User.add_to_class('reputation', + models.PositiveIntegerField(default=const.MIN_REPUTATION) +) User.add_to_class('gravatar', models.CharField(max_length=32)) User.add_to_class('gold', models.SmallIntegerField(default=0)) User.add_to_class('silver', models.SmallIntegerField(default=0)) User.add_to_class('bronze', models.SmallIntegerField(default=0)) -User.add_to_class('questions_per_page', - models.SmallIntegerField( - choices=const.QUESTIONS_PER_PAGE_USER_CHOICES, - default=10) - ) +User.add_to_class( + 'questions_per_page', + models.SmallIntegerField( + choices=const.QUESTIONS_PER_PAGE_USER_CHOICES, + default=10 + ) +) User.add_to_class('last_seen', models.DateTimeField(default=datetime.datetime.now)) User.add_to_class('real_name', models.CharField(max_length=100, blank=True)) @@ -1528,6 +1532,13 @@ def user_clean_response_counts(user): 'seen response count wanted to go below zero form %s' % user.username ) +def user_receive_reputation(self, num_points): + new_points = self.reputation + num_points + if new_points > 0: + self.reputation = new_points + else: + self.reputation = const.MIN_REPUTATION + User.add_to_class('is_username_taken',classmethod(user_is_username_taken)) User.add_to_class( 'get_q_sel_email_feed_frequency', @@ -1546,6 +1557,7 @@ User.add_to_class('visit_question', user_visit_question) User.add_to_class('upvote', upvote) User.add_to_class('downvote', downvote) User.add_to_class('flag_post', flag_post) +User.add_to_class('receive_reputation', user_receive_reputation) User.add_to_class('get_flags', user_get_flags) User.add_to_class('get_flag_count_posted_today', user_get_flag_count_posted_today) User.add_to_class('get_flags_for_post', user_get_flags_for_post) diff --git a/askbot/skins/default/templates/blocks/input_bar.html b/askbot/skins/default/templates/blocks/input_bar.html index a7be193e..bed97eb4 100644 --- a/askbot/skins/default/templates/blocks/input_bar.html +++ b/askbot/skins/default/templates/blocks/input_bar.html @@ -3,8 +3,10 @@