diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-29 23:21:32 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-29 23:21:32 -0500 |
commit | d516f06f680184fd8165cd324a221e04e3f79342 (patch) | |
tree | 234e211bf4a3294b08da84e92cd0a3a94afac2f8 | |
parent | e970c390a50e30ce04045046729d70b0e25518a4 (diff) | |
download | askbot-d516f06f680184fd8165cd324a221e04e3f79342.tar.gz askbot-d516f06f680184fd8165cd324a221e04e3f79342.tar.bz2 askbot-d516f06f680184fd8165cd324a221e04e3f79342.zip |
removed some unused code
-rw-r--r-- | askbot/admin.py | 13 | ||||
-rw-r--r-- | askbot/management/commands/clean_award_badges.py | 59 | ||||
-rw-r--r-- | askbot/management/commands/pg_clean_award_badges.py | 59 | ||||
-rw-r--r-- | askbot/management/commands/pg_multi_award_badges.py | 348 | ||||
-rw-r--r-- | askbot/management/commands/pg_once_award_badges.py | 350 | ||||
-rw-r--r-- | askbot/models/repute.py | 2 | ||||
-rw-r--r-- | askbot/templatetags/extra_tags.py | 370 | ||||
-rw-r--r-- | askbot/views/writers.py | 2 |
8 files changed, 14 insertions, 1189 deletions
diff --git a/askbot/admin.py b/askbot/admin.py index 309c4294..af62ed84 100644 --- a/askbot/admin.py +++ b/askbot/admin.py @@ -40,24 +40,12 @@ class AnswerRevisionAdmin(admin.ModelAdmin): class AwardAdmin(admin.ModelAdmin): """ admin class""" -class BadgeAdmin(admin.ModelAdmin): - """ admin class""" - class ReputeAdmin(admin.ModelAdmin): """ admin class""" class ActivityAdmin(admin.ModelAdmin): """ admin class""" -#class BookAdmin(admin.ModelAdmin): -# """ admin class""" - -#class BookAuthorInfoAdmin(admin.ModelAdmin): -# """ admin class""" - -#class BookAuthorRssAdmin(admin.ModelAdmin): -# """ admin class""" - admin.site.register(models.Question, QuestionAdmin) admin.site.register(models.Tag, TagAdmin) admin.site.register(models.Answer, AnswerAdmin) @@ -66,7 +54,6 @@ admin.site.register(models.Vote, VoteAdmin) admin.site.register(models.FavoriteQuestion, FavoriteQuestionAdmin) admin.site.register(models.QuestionRevision, QuestionRevisionAdmin) admin.site.register(models.AnswerRevision, AnswerRevisionAdmin) -admin.site.register(models.Badge, BadgeAdmin) admin.site.register(models.Award, AwardAdmin) admin.site.register(models.Repute, ReputeAdmin) admin.site.register(models.Activity, ActivityAdmin) diff --git a/askbot/management/commands/clean_award_badges.py b/askbot/management/commands/clean_award_badges.py deleted file mode 100644 index 49e79fca..00000000 --- a/askbot/management/commands/clean_award_badges.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -#------------------------------------------------------------------------------- -# Name: Award badges command -# Purpose: This is a command file croning in background process regularly to -# query database and award badges for user's special acitivities. -# -# Author: Mike -# -# Created: 18/01/2009 -# Copyright: (c) Mike 2009 -# Licence: GPL V2 -#------------------------------------------------------------------------------- -""" -#!/usr/bin/env python -#encoding:utf-8 -from django.core.management.base import NoArgsCommand -from django.db import connection -from django.contrib.contenttypes.models import ContentType -from askbot import models - -class Command(NoArgsCommand): - def handle_noargs(self, **options): - try: - try: - self.clean_awards() - except Exception, e: - print e - finally: - connection.close() - - def clean_awards(self): - models.Award.objects.all().delete() - - award_type =ContentType.objects.get_for_model(models.Award) - models.Activity.objects.filter(content_type=award_type).delete() - - for user in models.User.objects.all(): - user.gold = 0 - user.silver = 0 - user.bronze = 0 - user.save() - - for badge in models.Badge.objects.all(): - badge.awarded_count = 0 - badge.save() - - query = "UPDATE activity SET is_auditted = 0" - cursor = connection.cursor() - try: - cursor.execute(query) - finally: - cursor.close() - connection.close() - -def main(): - pass - -if __name__ == '__main__': - main() diff --git a/askbot/management/commands/pg_clean_award_badges.py b/askbot/management/commands/pg_clean_award_badges.py deleted file mode 100644 index 934d1f1d..00000000 --- a/askbot/management/commands/pg_clean_award_badges.py +++ /dev/null @@ -1,59 +0,0 @@ -#------------------------------------------------------------------------------- -# Name: Award badges command -# Purpose: This is a command file croning in background process regularly to -# query database and award badges for user's special acitivities. -# -# Author: Mike -# -# Created: 18/01/2009 -# Copyright: (c) Mike 2009 -# Licence: GPL V2 -#------------------------------------------------------------------------------- -#!/usr/bin/env python -#encoding:utf-8 -from django.core.management.base import NoArgsCommand -from django.db import connection -from django.shortcuts import get_object_or_404 -from django.contrib.contenttypes.models import ContentType - -from askbot.models import * - -class Command(NoArgsCommand): - def handle_noargs(self, **options): - try: - try: - self.clean_awards() - except Exception, e: - print e - finally: - connection.close() - - def clean_awards(self): - Award.objects.all().delete() - - award_type =ContentType.objects.get_for_model(Award) - Activity.objects.filter(content_type=award_type).delete() - - for user in User.objects.all(): - user.gold = 0 - user.silver = 0 - user.bronze = 0 - user.save() - - for badge in Badge.objects.all(): - badge.awarded_count = 0 - badge.save() - - query = "UPDATE activity SET is_auditted = FALSE" - cursor = connection.cursor() - try: - cursor.execute(query) - finally: - cursor.close() - connection.close() - -def main(): - pass - -if __name__ == '__main__': - main()
\ No newline at end of file diff --git a/askbot/management/commands/pg_multi_award_badges.py b/askbot/management/commands/pg_multi_award_badges.py deleted file mode 100644 index 6a4ef2f6..00000000 --- a/askbot/management/commands/pg_multi_award_badges.py +++ /dev/null @@ -1,348 +0,0 @@ -#!/usr/bin/env python -#encoding:utf-8 -#------------------------------------------------------------------------------- -# Name: Award badges command -# Purpose: This is a command file croning in background process regularly to -# query database and award badges for user's special acitivities. -# -# Author: Mike, Sailing -# -# Created: 22/01/2009 -# Copyright: (c) Mike 2009 -# Licence: GPL V2 -#------------------------------------------------------------------------------- - -from datetime import datetime, date -from django.core.management.base import NoArgsCommand -from django.db import connection -from django.shortcuts import get_object_or_404 -from django.contrib.contenttypes.models import ContentType - -from askbot.models import * -from askbot.const import * -from pg_base_command import BaseCommand -""" -(1, '????', 3, '????', '?????3?????????', 1, 0), -(2, '????', 3, '????', '?????3?????????', 1, 0), -(3, '????', 3, '????', '????10???', 1, 0), -(4, '????', 3, '????', '????10???', 1, 0), -(5, '???', 3, '???', '??10???', 0, 0), -(6, '????', 3, '????', '????????1000??', 1, 0), -(7, '???', 3, '???', '?????????', 0, 0), -(8, '???', 3, '???', '???????', 0, 0), -(9, '???', 3, '???', '??????', 0, 0), -(10, '??', 3, '??', '???????', 0, 0), -(11, '??', 3, '??', '???????', 0, 0), -(12, '??', 3, '??', '???????', 0, 0), -(13, '??', 3, '??', '???????????????', 0, 0), -(14, '???', 3, '???', '??????', 0, 0), -(15, '??', 3, '??', '??????????????????', 0, 0), -(16, '????', 3, '????', '????????????', 0, 0), -(17, '????', 3, '????', '??????????3??????', 1, 0), -(18, '??????', 1, '??????', '????100????', 1, 0), -(19, '??????', 1, '??????', '????100????', 1, 0), -(20, '???', 1, '???', '???100?????', 1, 0), -(21, '????', 1, '????', '????????10000??', 1, 0), -(22, 'alpha??', 2, 'alpha??', '?????????', 0, 0), -(23, '????', 2, '????', '????25????', 1, 0), -(24, '????', 2, '????', '????25????', 1, 0), -(25, '?????', 2, '?????', '???25?????', 1, 0), -(26, '????', 2, '????', '??300???', 0, 0), -(27, '????', 2, '????', '???100???', 0, 0), -(28, '??', 2, '??', '?????????', 0, 0), -(29, '??', 2, '??', '???????????', 0, 0), -(30, '??', 2, '??', '?????????', 0, 0), -(31, '??????', 2, '??????', '????????2500??', 1, 0), -(32, '???', 2, '???', '??????????10???', 0, 0), -(33, 'beta??', 2, 'beta??', 'beta??????', 0, 0), -(34, '??', 2, '??', '?????????????40??', 1, 0), -(35, '??', 2, '??', '???60??????????5???', 1, 0), -(36, '????', 2, '????', '??????50???????', 1, 0); - - -TYPE_ACTIVITY_ASK_QUESTION=1 -TYPE_ACTIVITY_ANSWER=2 -TYPE_ACTIVITY_COMMENT_QUESTION=3 -TYPE_ACTIVITY_COMMENT_ANSWER=4 -TYPE_ACTIVITY_UPDATE_QUESTION=5 -TYPE_ACTIVITY_UPDATE_ANSWER=6 -TYPE_ACTIVITY_PRIZE=7 -TYPE_ACTIVITY_MARK_ANSWER=8 -TYPE_ACTIVITY_VOTE_UP=9 -TYPE_ACTIVITY_VOTE_DOWN=10 -TYPE_ACTIVITY_CANCEL_VOTE=11 -TYPE_ACTIVITY_DELETE_QUESTION=12 -TYPE_ACTIVITY_DELETE_ANSWER=13 -TYPE_ACTIVITY_MARK_OFFENSIVE=14 -TYPE_ACTIVITY_UPDATE_TAGS=15 -TYPE_ACTIVITY_FAVORITE=16 -TYPE_ACTIVITY_USER_FULL_UPDATED = 17 -""" - -class Command(BaseCommand): - def handle_noargs(self, **options): - try: - try: - self.delete_question_be_voted_up_3() - self.delete_answer_be_voted_up_3() - self.delete_question_be_vote_down_3() - self.delete_answer_be_voted_down_3() - self.answer_be_voted_up_10() - self.question_be_voted_up_10() - self.question_view_1000() - self.answer_self_question_be_voted_up_3() - self.answer_be_voted_up_100() - self.question_be_voted_up_100() - self.question_be_favorited_100() - self.question_view_10000() - self.answer_be_voted_up_25() - self.question_be_voted_up_25() - self.question_be_favorited_25() - self.question_view_2500() - self.answer_be_accepted_and_voted_up_40() - self.question_be_answered_after_60_days_and_be_voted_up_5() - self.created_tag_be_used_in_question_50() - except Exception, e: - print e - finally: - connection.close() - - def delete_question_be_voted_up_3(self): - """ - (1, '????', 3, '????', '?????3?????????', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM activity act, question q WHERE act.object_id = q.id AND\ - act.activity_type = %s AND\ - q.vote_up_count >=3 AND \ - not act.is_auditted" % (TYPE_ACTIVITY_DELETE_QUESTION) - self.__process_activities_badge(query, 1, Question) - - def delete_answer_be_voted_up_3(self): - """ - (1, '????', 3, '????', '?????3?????????', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM activity act, answer an WHERE act.object_id = an.id AND\ - act.activity_type = %s AND\ - an.vote_up_count >=3 AND \ - not act.is_auditted" % (TYPE_ACTIVITY_DELETE_ANSWER) - self.__process_activities_badge(query, 1, Answer) - - def delete_question_be_vote_down_3(self): - """ - (2, '????', 3, '????', '?????3?????????', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM activity act, question q WHERE act.object_id = q.id AND\ - act.activity_type = %s AND\ - q.vote_down_count >=3 AND \ - not act.is_auditted" % (TYPE_ACTIVITY_DELETE_QUESTION) - content_type = ContentType.objects.get_for_model(Question) - self.__process_activities_badge(query, 2, Question) - - def delete_answer_be_voted_down_3(self): - """ - (2, '????', 3, '????', '?????3?????????', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM activity act, answer an WHERE act.object_id = an.id AND\ - act.activity_type = %s AND\ - an.vote_down_count >=3 AND \ - not act.is_auditted" % (TYPE_ACTIVITY_DELETE_ANSWER) - self.__process_activities_badge(query, 2, Answer) - - def answer_be_voted_up_10(self): - """ - (3, '????', 3, '????', '????10???', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM \ - activity act, answer a WHERE act.object_id = a.id AND\ - act.activity_type = %s AND \ - a.vote_up_count >= 10 AND\ - not act.is_auditted" % (TYPE_ACTIVITY_ANSWER) - self.__process_activities_badge(query, 3, Answer) - - def question_be_voted_up_10(self): - """ - (4, '????', 3, '????', '????10???', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM \ - activity act, question q WHERE act.object_id = q.id AND\ - act.activity_type = %s AND \ - q.vote_up_count >= 10 AND\ - not act.is_auditted" % (TYPE_ACTIVITY_ASK_QUESTION) - self.__process_activities_badge(query, 4, Question) - - def question_view_1000(self): - """ - (6, '????', 3, '????', '????????1000??', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM \ - activity act, question q WHERE act.activity_type = %s AND\ - act.object_id = q.id AND \ - q.view_count >= 1000 AND\ - act.object_id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (TYPE_ACTIVITY_ASK_QUESTION, 6) - self.__process_activities_badge(query, 6, Question, False) - - def answer_self_question_be_voted_up_3(self): - """ - (17, '????', 3, '????', '??????????3??????', 1, 0), - """ - query = "SELECT act.id, act.user_id, act.object_id FROM \ - activity act, answer an WHERE act.activity_type = %s AND\ - act.object_id = an.id AND\ - an.vote_up_count >= 3 AND\ - act.user_id = (SELECT user_id FROM question q WHERE q.id = an.question_id) AND\ - act.object_id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (TYPE_ACTIVITY_ANSWER, 17) - self.__process_activities_badge(query, 17, Question, False) - - def answer_be_voted_up_100(self): - """ - (18, '??????', 1, '??????', '????100????', 1, 0), - """ - query = "SELECT an.id, an.author_id FROM answer an WHERE an.vote_up_count >= 100 AND an.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (18) - - self.__process_badge(query, 18, Answer) - - def question_be_voted_up_100(self): - """ - (19, '??????', 1, '??????', '????100????', 1, 0), - """ - query = "SELECT q.id, q.author_id FROM question q WHERE q.vote_up_count >= 100 AND q.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (19) - - self.__process_badge(query, 19, Question) - - def question_be_favorited_100(self): - """ - (20, '???', 1, '???', '???100?????', 1, 0), - """ - query = "SELECT q.id, q.author_id FROM question q WHERE q.favourite_count >= 100 AND q.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (20) - - self.__process_badge(query, 20, Question) - - def question_view_10000(self): - """ - (21, '????', 1, '????', '????????10000??', 1, 0), - """ - query = "SELECT q.id, q.author_id FROM question q WHERE q.view_count >= 10000 AND q.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (21) - - self.__process_badge(query, 21, Question) - - def answer_be_voted_up_25(self): - """ - (23, '????', 2, '????', '????25????', 1, 0), - """ - query = "SELECT a.id, a.author_id FROM answer a WHERE a.vote_up_count >= 25 AND a.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (23) - - self.__process_badge(query, 23, Answer) - - def question_be_voted_up_25(self): - """ - (24, '????', 2, '????', '????25????', 1, 0), - """ - query = "SELECT q.id, q.author_id FROM question q WHERE q.vote_up_count >= 25 AND q.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (24) - - self.__process_badge(query, 24, Question) - - def question_be_favorited_25(self): - """ - (25, '?????', 2, '?????', '???25?????', 1, 0), - """ - query = "SELECT q.id, q.author_id FROM question q WHERE q.favourite_count >= 25 AND q.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (25) - - self.__process_badge(query, 25, Question) - - def question_view_2500(self): - """ - (31, '??????', 2, '??????', '????????2500??', 1, 0), - """ - query = "SELECT q.id, q.author_id FROM question q WHERE q.view_count >= 2500 AND q.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (31) - - self.__process_badge(query, 31, Question) - - def answer_be_accepted_and_voted_up_40(self): - """ - (34, '??', 2, '??', '?????????????40??', 1, 0), - """ - query = "SELECT a.id, a.author_id FROM answer a WHERE a.vote_up_count >= 40 AND\ - a.accepted AND\ - a.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (34) - - self.__process_badge(query, 34, Answer) - - def question_be_answered_after_60_days_and_be_voted_up_5(self): - """ - (35, '??', 2, '??', '???60??????????5???', 1, 0), - """ - query = "SELECT a.id, a.author_id FROM question q, answer a WHERE q.id = a.question_id AND\ - (a.added_at + '60 day'::INTERVAL) >= q.added_at AND\ - a.vote_up_count >= 5 AND \ - a.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (35) - - self.__process_badge(query, 35, Answer) - - def created_tag_be_used_in_question_50(self): - """ - (36, '????', 2, '????', '??????50???????', 1, 0); - """ - query = "SELECT t.id, t.created_by_id FROM tag t, auth_user u WHERE t.created_by_id = u.id AND \ - t. used_count >= 50 AND \ - t.id NOT IN \ - (SELECT object_id FROM award WHERE award.badge_id = %s)" % (36) - - self.__process_badge(query, 36, Tag) - - def __process_activities_badge(self, query, badge, content_object, update_auditted=True): - content_type = ContentType.objects.get_for_model(content_object) - - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - - if update_auditted: - activity_ids = [] - badge = get_object_or_404(Badge, id=badge) - for row in rows: - activity_id = row[0] - user_id = row[1] - object_id = row[2] - - user = get_object_or_404(User, id=user_id) - award = Award(user=user, badge=badge, content_type=content_type, object_id=object_id) - award.save() - - if update_auditted: - activity_ids.append(activity_id) - - if update_auditted: - self.update_activities_auditted(cursor, activity_ids) - finally: - cursor.close() - - def __process_badge(self, query, badge, content_object): - content_type = ContentType.objects.get_for_model(Answer) - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - - badge = get_object_or_404(Badge, id=badge) - for row in rows: - object_id = row[0] - user_id = row[1] - - user = get_object_or_404(User, id=user_id) - award = Award(user=user, badge=badge, content_type=content_type, object_id=object_id) - award.save() - finally: - cursor.close() diff --git a/askbot/management/commands/pg_once_award_badges.py b/askbot/management/commands/pg_once_award_badges.py deleted file mode 100644 index 7decbc2d..00000000 --- a/askbot/management/commands/pg_once_award_badges.py +++ /dev/null @@ -1,350 +0,0 @@ -#!/usr/bin/env python -#encoding:utf-8 -#------------------------------------------------------------------------------- -# Name: Award badges command -# Purpose: This is a command file croning in background process regularly to -# query database and award badges for user's special acitivities. -# -# Author: Mike, Sailing -# -# Created: 18/01/2009 -# Copyright: (c) Mike 2009 -# Licence: GPL V2 -#------------------------------------------------------------------------------- - -from datetime import datetime, date -from django.db import connection -from django.shortcuts import get_object_or_404 -from django.contrib.contenttypes.models import ContentType - -from askbot.models import * -from askbot.const import * -from pg_base_command import BaseCommand -""" -(1, '????', 3, '????', '?????3?????????', 1, 0), -(2, '????', 3, '????', '?????3?????????', 1, 0), -(3, '????', 3, '????', '????10???', 1, 0), -(4, '????', 3, '????', '????10???', 1, 0), -(5, '???', 3, '???', '??10???', 0, 0), -(6, '????', 3, '????', '????????1000??', 1, 0), -(7, '???', 3, '???', '?????????', 0, 0), -(8, '???', 3, '???', '???????', 0, 0), -(9, '???', 3, '???', '??????', 0, 0), -(10, '??', 3, '??', '???????', 0, 0), -(11, '??', 3, '??', '???????', 0, 0), -(12, '??', 3, '??', '???????', 0, 0), -(13, '??', 3, '??', '???????????????', 0, 0), -(14, '???', 3, '???', '??????', 0, 0), -(15, '??', 3, '??', '??????????????????', 0, 0), -(16, '????', 3, '????', '????????????', 0, 0), -(17, '????', 3, '????', '??????????3??????', 1, 0), -(18, '??????', 1, '??????', '????100????', 1, 0), -(19, '??????', 1, '??????', '????100????', 1, 0), -(20, '???', 1, '???', '???100?????', 1, 0), -(21, '????', 1, '????', '????????10000??', 1, 0), -(22, 'alpha??', 2, 'alpha??', '?????????', 0, 0), -(23, '????', 2, '????', '????25????', 1, 0), -(24, '????', 2, '????', '????25????', 1, 0), -(25, '?????', 2, '?????', '???25?????', 1, 0), -(26, '????', 2, '????', '??300???', 0, 0), -(27, '????', 2, '????', '???100???', 0, 0), -(28, '??', 2, '??', '?????????', 0, 0), -(29, '??', 2, '??', '???????????', 0, 0), -(30, '??', 2, '??', '?????????', 0, 0), -(31, '??????', 2, '??????', '????????2500??', 1, 0), -(32, '???', 2, '???', '??????????10???', 0, 0), -(33, 'beta??', 2, 'beta??', 'beta??????', 0, 0), -(34, '??', 2, '??', '?????????????40??', 1, 0), -(35, '??', 2, '??', '???60??????????5???', 1, 0), -(36, '????', 2, '????', '??????50???????', 1, 0); - - -TYPE_ACTIVITY_ASK_QUESTION=1 -TYPE_ACTIVITY_ANSWER=2 -TYPE_ACTIVITY_COMMENT_QUESTION=3 -TYPE_ACTIVITY_COMMENT_ANSWER=4 -TYPE_ACTIVITY_UPDATE_QUESTION=5 -TYPE_ACTIVITY_UPDATE_ANSWER=6 -TYPE_ACTIVITY_PRIZE=7 -TYPE_ACTIVITY_MARK_ANSWER=8 -TYPE_ACTIVITY_VOTE_UP=9 -TYPE_ACTIVITY_VOTE_DOWN=10 -TYPE_ACTIVITY_CANCEL_VOTE=11 -TYPE_ACTIVITY_DELETE_QUESTION=12 -TYPE_ACTIVITY_DELETE_ANSWER=13 -TYPE_ACTIVITY_MARK_OFFENSIVE=14 -TYPE_ACTIVITY_UPDATE_TAGS=15 -TYPE_ACTIVITY_FAVORITE=16 -TYPE_ACTIVITY_USER_FULL_UPDATED = 17 -""" - -BADGE_AWARD_TYPE_FIRST = { - TYPE_ACTIVITY_MARK_OFFENSIVE : 7, - TYPE_ACTIVITY_CANCEL_VOTE: 8, - TYPE_ACTIVITY_VOTE_DOWN : 9, - TYPE_ACTIVITY_UPDATE_QUESTION : 10, - TYPE_ACTIVITY_UPDATE_ANSWER : 10, - TYPE_ACTIVITY_UPDATE_TAGS : 11, - TYPE_ACTIVITY_MARK_ANSWER : 12, - TYPE_ACTIVITY_VOTE_UP : 14, - TYPE_ACTIVITY_USER_FULL_UPDATED: 16 - -} - -class Command(BaseCommand): - def handle_noargs(self, **options): - try: - try: - self.alpha_user() - self.beta_user() - self.first_type_award() - self.first_ask_be_voted() - self.first_answer_be_voted() - self.first_answer_be_voted_10() - self.vote_count_300() - self.edit_count_100() - self.comment_count_10() - except Exception, e: - print e - finally: - connection.close() - - def alpha_user(self): - """ - Before Jan 25, 2009(Chinese New Year Eve and enter into Beta for CNProg), every registered user - will be awarded the "Alpha" badge if he has any activities. - """ - alpha_end_date = date(2009, 1, 25) - if date.today() < alpha_end_date: - badge = get_object_or_404(Badge, id=22) - for user in User.objects.all(): - award = Award.objects.filter(user=user, badge=badge) - if award and not badge.multiple: - continue - activities = Activity.objects.filter(user=user) - if len(activities) > 0: - new_award = Award(user=user, badge=badge) - new_award.save() - - def beta_user(self): - """ - Before Feb 25, 2009, every registered user - will be awarded the "Beta" badge if he has any activities. - """ - beta_end_date = date(2009, 2, 25) - if date.today() < beta_end_date: - badge = get_object_or_404(Badge, id=33) - for user in User.objects.all(): - award = Award.objects.filter(user=user, badge=badge) - if award and not badge.multiple: - continue - activities = Activity.objects.filter(user=user) - if len(activities) > 0: - new_award = Award(user=user, badge=badge) - new_award.save() - - def first_type_award(self): - """ - This will award below badges for users first behaviors: - - (7, '???', 3, '???', '?????????', 0, 0), - (8, '???', 3, '???', '???????', 0, 0), - (9, '???', 3, '???', '??????', 0, 0), - (10, '??', 3, '??', '???????', 0, 0), - (11, '??', 3, '??', '???????', 0, 0), - (12, '??', 3, '??', '???????', 0, 0), - (14, '???', 3, '???', '??????', 0, 0), - (16, '????', 3, '????', '????????????', 0, 0), - """ - activity_types = ','.join('%s' % item for item in BADGE_AWARD_TYPE_FIRST.keys()) - # ORDER BY user_id, activity_type - query = "SELECT id, user_id, activity_type, content_type_id, object_id FROM activity WHERE not is_auditted AND activity_type IN (%s) ORDER BY user_id, activity_type" % activity_types - - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - # collect activity_id in current process - activity_ids = [] - last_user_id = 0 - last_activity_type = 0 - for row in rows: - activity_ids.append(row[0]) - user_id = row[1] - activity_type = row[2] - content_type_id = row[3] - object_id = row[4] - - # if the user and activity are same as the last, continue - if user_id == last_user_id and activity_type == last_activity_type: - continue; - - user = get_object_or_404(User, id=user_id) - badge = get_object_or_404(Badge, id=BADGE_AWARD_TYPE_FIRST[activity_type]) - content_type = get_object_or_404(ContentType, id=content_type_id) - - count = Award.objects.filter(user=user, badge=badge).count() - if count and not badge.multiple: - continue - else: - # new award - award = Award(user=user, badge=badge, content_type=content_type, object_id=object_id) - award.save() - - # set the current user_id and activity_type to last - last_user_id = user_id - last_activity_type = activity_type - - # update processed rows to auditted - self.update_activities_auditted(cursor, activity_ids) - finally: - cursor.close() - - def first_ask_be_voted(self): - """ - For user asked question and got first upvote, we award him following badge: - - (13, '??', 3, '??', '???????????????', 0, 0), - """ - query = "SELECT act.user_id, q.vote_up_count, act.object_id FROM " \ - "activity act, question q WHERE act.activity_type = %s AND " \ - "act.object_id = q.id AND " \ - "act.user_id NOT IN (SELECT distinct user_id FROM award WHERE badge_id = %s)" % (TYPE_ACTIVITY_ASK_QUESTION, 13) - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - - badge = get_object_or_404(Badge, id=13) - content_type = ContentType.objects.get_for_model(Question) - awarded_users = [] - for row in rows: - user_id = row[0] - vote_up_count = row[1] - object_id = row[2] - if vote_up_count > 0 and user_id not in awarded_users: - user = get_object_or_404(User, id=user_id) - award = Award(user=user, badge=badge, content_type=content_type, object_id=object_id) - award.save() - awarded_users.append(user_id) - finally: - cursor.close() - - def first_answer_be_voted(self): - """ - When user answerd questions and got first upvote, we award him following badge: - - (15, '??', 3, '??', '??????????????????', 0, 0), - """ - query = "SELECT act.user_id, a.vote_up_count, act.object_id FROM " \ - "activity act, answer a WHERE act.activity_type = %s AND " \ - "act.object_id = a.id AND " \ - "act.user_id NOT IN (SELECT distinct user_id FROM award WHERE badge_id = %s)" % (TYPE_ACTIVITY_ANSWER, 15) - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - - awarded_users = [] - badge = get_object_or_404(Badge, id=15) - content_type = ContentType.objects.get_for_model(Answer) - for row in rows: - user_id = row[0] - vote_up_count = row[1] - object_id = row[2] - if vote_up_count > 0 and user_id not in awarded_users: - user = get_object_or_404(User, id=user_id) - award = Award(user=user, badge=badge, content_type=content_type, object_id=object_id) - award.save() - awarded_users.append(user_id) - finally: - cursor.close() - - def first_answer_be_voted_10(self): - """ - (32, '???', 2, '???', '??????????10???', 0, 0) - """ - query = "SELECT act.user_id, act.object_id FROM " \ - "activity act, answer a WHERE act.object_id = a.id AND " \ - "act.activity_type = %s AND " \ - "a.vote_up_count >= 10 AND " \ - "act.user_id NOT IN (SELECT user_id FROM award WHERE badge_id = %s)" % (TYPE_ACTIVITY_ANSWER, 32) - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - - awarded_users = [] - badge = get_object_or_404(Badge, id=32) - content_type = ContentType.objects.get_for_model(Answer) - for row in rows: - user_id = row[0] - if user_id not in awarded_users: - user = get_object_or_404(User, id=user_id) - object_id = row[1] - award = Award(user=user, badge=badge, content_type=content_type, object_id=object_id) - award.save() - awarded_users.append(user_id) - finally: - cursor.close() - - def vote_count_300(self): - """ - (26, '????', 2, '????', '??300???', 0, 0) - """ - query = "SELECT count(*) as vote_count, user_id FROM activity WHERE " \ - "activity_type = %s OR " \ - "activity_type = %s AND " \ - "user_id NOT IN (SELECT user_id FROM award WHERE badge_id = %s) " \ - "GROUP BY user_id HAVING count(*) >= 300" % (TYPE_ACTIVITY_VOTE_UP, TYPE_ACTIVITY_VOTE_DOWN, 26) - - self.__award_for_count_num(query, 26) - - def edit_count_100(self): - """ - (27, '????', 2, '????', '???100???', 0, 0) - """ - query = "SELECT count(*) as vote_count, user_id FROM activity WHERE " \ - "activity_type = %s OR " \ - "activity_type = %s AND " \ - "user_id NOT IN (SELECT user_id FROM award WHERE badge_id = %s) " \ - "GROUP BY user_id HAVING count(*) >= 100" % (TYPE_ACTIVITY_UPDATE_QUESTION, TYPE_ACTIVITY_UPDATE_ANSWER, 27) - - self.__award_for_count_num(query, 27) - - def comment_count_10(self): - """ - (5, '???', 3, '???', '??10???', 0, 0), - """ - query = "SELECT count(*) as vote_count, user_id FROM activity WHERE " \ - "activity_type = %s OR " \ - "activity_type = %s AND " \ - "user_id NOT IN (SELECT user_id FROM award WHERE badge_id = %s) " \ - "GROUP BY user_id HAVING count(*) >= 10" % (TYPE_ACTIVITY_COMMENT_QUESTION, TYPE_ACTIVITY_COMMENT_ANSWER, 5) - self.__award_for_count_num(query, 5) - - def __award_for_count_num(self, query, badge): - cursor = connection.cursor() - try: - cursor.execute(query) - rows = cursor.fetchall() - - awarded_users = [] - badge = get_object_or_404(Badge, id=badge) - for row in rows: - vote_count = row[0] - user_id = row[1] - - if user_id not in awarded_users: - user = get_object_or_404(User, id=user_id) - award = Award(user=user, badge=badge) - award.save() - awarded_users.append(user_id) - finally: - cursor.close() - -def main(): - pass - -if __name__ == '__main__': - main() diff --git a/askbot/models/repute.py b/askbot/models/repute.py index eef85b58..d8712636 100644 --- a/askbot/models/repute.py +++ b/askbot/models/repute.py @@ -72,7 +72,7 @@ class Award(models.Model): object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') awarded_at = models.DateTimeField(default=datetime.datetime.now) - notified = models.BooleanField(default=False) + notified = models.BooleanField(default=False)#not used objects = AwardManager() diff --git a/askbot/templatetags/extra_tags.py b/askbot/templatetags/extra_tags.py index 80ccf251..1a637bd2 100644 --- a/askbot/templatetags/extra_tags.py +++ b/askbot/templatetags/extra_tags.py @@ -1,26 +1,11 @@ -import time -import os -import datetime import math -import re -import logging from django import template -from django.utils.encoding import smart_unicode from django.utils.safestring import mark_safe -from askbot.const import * -from askbot.models import Question, Answer, QuestionRevision, AnswerRevision -from askbot.models import Badge +#from askbot.const import * from django.utils.translation import ugettext as _ -from django.utils.translation import ungettext -from django.conf import settings -from askbot.conf import settings as askbot_settings -from django.template.defaulttags import url as default_url from django.core.urlresolvers import reverse -from askbot.skins import utils as skin_utils -from askbot.utils import colors from askbot.utils import functions from askbot.utils.slug import slugify -from askbot.templatetags import extra_filters from askbot.skins.loaders import ENV register = template.Library() @@ -43,16 +28,19 @@ def gravatar(user, size): appropriate values. """ #todo: rewrite using get_from_dict_or_object - gravatar = functions.get_from_dict_or_object(user, 'gravatar') + gravatar_hash = functions.get_from_dict_or_object(user, 'gravatar') username = functions.get_from_dict_or_object(user, 'username') user_id = functions.get_from_dict_or_object(user, 'id') slug = slugify(username) - user_profile_url = reverse('user_profile', kwargs={'id':user_id,'slug':slug}) + user_profile_url = reverse( + 'user_profile', + kwargs={'id':user_id, 'slug':slug} + ) #safe_username = template.defaultfilters.urlencode(username) return mark_safe(GRAVATAR_TEMPLATE % { 'user_profile_url': user_profile_url, 'size': size, - 'gravatar_hash': gravatar, + 'gravatar_hash': gravatar_hash, 'alt_text': _('%(username)s gravatar image') % {'username': username}, 'username': username, }) @@ -63,14 +51,16 @@ MIN_FONTSIZE = 12 def tag_font_size(max_size, min_size, current_size): """ do a logarithmic mapping calcuation for a proper size for tagging cloud - Algorithm from http://blogs.dekoh.com/dev/2007/10/29/choosing-a-good-font-size-variation-algorithm-for-your-tag-cloud/ + Algorithm from http://blogs.dekoh.com/dev/2007/10/29/choosing-a-good- + font-size-variation-algorithm-for-your-tag-cloud/ """ #avoid invalid calculation if current_size == 0: current_size = 1 try: - weight = (math.log10(current_size) - math.log10(min_size)) / (math.log10(max_size) - math.log10(min_size)) - except: + weight = (math.log10(current_size) - math.log10(min_size)) / \ + (math.log10(max_size) - math.log10(min_size)) + except Exception: weight = 0 return MIN_FONTSIZE + round((MAX_FONTSIZE - MIN_FONTSIZE) * weight) @@ -125,250 +115,6 @@ def cnprog_paginator(context): "extend_url" : extend_url } -@register.inclusion_tag("post_contributor_info.html") -def post_contributor_info(post,contributor_type='original_author'): - """contributor_type: original_author|last_updater - """ - if isinstance(post,Question): - post_type = 'question' - elif isinstance(post,Answer): - post_type = 'answer' - elif isinstance(post,AnswerRevision) or isinstance(post,QuestionRevision): - post_type = 'revision' - return { - 'post':post, - 'post_type':post_type, - 'wiki_on':askbot_settings.WIKI_ON, - 'contributor_type':contributor_type - } - - -BADGE_TEMPLATE = '<span title="%(pluralized_badge_count)s">' \ - + '<span class="%(badge_css_class)s">%(badge_symbol)s</span>' \ - + '<span class="badgecount">%(badge_count)s</span>' \ - + '</span>' -BADGE_LEVELS = dict(Badge.TYPE_CHOICES) - -def render_badge_counter(badge_level = None, badge_count = None): - - pluralized_badge_count = ungettext( - '%(badge_count)d %(badge_level)s badge', - '%(badge_count)d %(badge_level)s badges', - badge_count - ) % { - 'badge_count': badge_count, - 'badge_level': BADGE_LEVELS[badge_level] - } - - output = BADGE_TEMPLATE % \ - { - 'pluralized_badge_count': pluralized_badge_count, - 'badge_css_class': Badge.CSS_CLASSES[badge_level], - 'badge_symbol': Badge.DISPLAY_SYMBOL, - 'badge_count': badge_count, - } - return output - - -REP_TEMPLATE = '<span class="reputation-score" ' \ - + 'title="%(reputation)s %(repword)s">%(reputation)s</span>' -@register.simple_tag -def render_reputation_counter(rep): - return REP_TEMPLATE % { - 'repword': _('reputation points'), - 'reputation': rep - } - - -@register.simple_tag -def render_badge_counters(gold_count, silver_count, bronze_count): - output = '' - if gold_count > 0 : - output += render_badge_counter( - badge_level = Badge.GOLD, - badge_count = gold_count - ) - if silver_count > 0: - output += render_badge_counter( - badge_level = Badge.SILVER, - badge_count = silver_count - ) - if bronze_count > 0: - output += render_badge_counter( - badge_level = Badge.BRONZE, - badge_count = bronze_count - ) - return output - - -@register.simple_tag -def get_score_badge_by_details(rep, gold_count, silver_count, bronze_count): - output = render_reputation_counter(rep) - output += render_badge_counters(gold_count, silver_count, bronze_count) - return output - - -#this one is used for the header next to user profile and logout links -REP_TEMPLATE2 = '<a class="ab-nav-karma" href="%(karma_graph_url)s" ' \ - + ' title="%(karma_phrase)s">' \ - + '%(rep_word)s: %(reputation)s</a>' -BADGE_TEMPLATE2 = ' <a class="ab-nav-badges" href="%(user_badges_url)s">' \ - + '%(badge_counters)s</a>' -@register.simple_tag -def get_long_score_and_badge_report(user): - profile_url = user.get_absolute_url() - karma_graph_url = profile_url + '?sort=reputation' - karma_phrase = _('your karma is %(reputation)s') \ - % { 'reputation': user.reputation } - - output = REP_TEMPLATE2 % { - 'repword': _('reputation points'), - 'karma_graph_url': karma_graph_url, - 'reputation': user.reputation, - 'karma_phrase': karma_phrase, - 'rep_word': _('reputation points'), - } - - badge_counters = render_badge_counters(user.gold, user.silver, user.bronze) - - if badge_counters != '': - output += ' ' + BADGE_TEMPLATE2 % { - 'user_badges_url': profile_url + '#badges', - 'badge_counters': _('badges: ') + badge_counters - } - return output - - -@register.simple_tag -def get_score_badge(user): - return get_score_badge_by_details( - user.reputation, - user.gold, - user.silver, - user.bronze - ) - - -@register.simple_tag -def get_user_vote_image(dic, key, arrow): - if dic.has_key(key): - if int(dic[key]) == int(arrow): - return '-on' - return '' - -@register.simple_tag -def get_total_count(up_count, down_count): - return up_count + down_count - -@register.simple_tag -def format_number(value): - strValue = str(value) - if len(strValue) <= 3: - return strValue - result = '' - first = '' - pattern = re.compile('(-?\d+)(\d{3})') - m = re.match(pattern, strValue) - while m != None: - first = m.group(1) - second = m.group(2) - result = ',' + second + result - strValue = first + ',' + second - m = re.match(pattern, strValue) - return first + result - -diff_date = register.simple_tag(functions.diff_date) - -@register.simple_tag -def get_latest_changed_timestamp(): - try: - from time import localtime, strftime - from os import path - root = settings.SITE_SRC_ROOT - dir = ( - root, - '%s/askbot' % root, - '%s/templates' % root, - ) - stamp = (path.getmtime(d) for d in dir) - latest = max(stamp) - timestr = strftime("%H:%M %b-%d-%Y %Z", localtime(latest)) - except: - timestr = '' - return timestr - -@register.simple_tag -def media(url): - url = skin_utils.get_media_url(url) - if url: - return url - else: - return '' #todo: raise exception here? - -class ItemSeparatorNode(template.Node): - def __init__(self,separator): - sep = separator.strip() - if sep[0] == sep[-1] and sep[0] in ('\'','"'): - sep = sep[1:-1] - else: - raise template.TemplateSyntaxError('separator in joinitems tag must be quoted') - self.content = sep - def render(self,context): - return self.content - -class JoinItemListNode(template.Node): - def __init__(self,separator=ItemSeparatorNode("''"), last_separator=None, items=()): - self.separator = separator - if last_separator: - self.last_separator = last_separator - else: - self.last_separator = separator - self.items = items - def render(self,context): - out = [] - empty_re = re.compile(r'^\s*$') - for item in self.items: - bit = item.render(context) - if not empty_re.search(bit): - out.append(bit) - if len(out) == 1: - return out[0] - if len(out) > 1: - last = out.pop() - all_but_last = self.separator.render(context).join(out) - return self.last_separator.render(context).join((all_but_last,last)) - else: - assert(len(out)==0) - return '' - -@register.tag(name="joinitems") -def joinitems(parser,token): - try: - tagname, junk, sep_token = token.split_contents() - last_sep_token = None - except: - try: - tagname, junk, sep_token, last_sep_token = token.split_contents() - except: - raise template.TemplateSyntaxError('incorrect usage of joinitems tag first param ' - 'must be \'using\' second - separator and ' - 'optional third - last item separator') - if junk == 'using': - sep_node = ItemSeparatorNode(sep_token) - if last_sep_token: - last_sep_node = ItemSeparatorNode(last_sep_token) - else: - last_sep_node = None - else: - raise template.TemplateSyntaxError("joinitems tag requires 'using \"separator html\"' parameters") - nodelist = [] - while True: - nodelist.append(parser.parse(('separator','endjoinitems'))) - next = parser.next_token() - if next.contents == 'endjoinitems': - break - - return JoinItemListNode(separator=sep_node,last_separator=last_sep_node,items=nodelist) class IncludeJinja(template.Node): """http://www.mellowmorning.com/2010/08/24/""" @@ -396,95 +142,3 @@ def include_jinja(parser, token): raise template.TemplateSyntaxError('file name must be quoted') return IncludeJinja(filename) - -class BlockMediaUrlNode(template.Node): - def __init__(self,nodelist): - self.items = nodelist - def render(self,context): - url = '' - if self.items: - url += '/' - for item in self.items: - url += item.render(context) - - url = skin_utils.get_media_url(url) - return url.replace(' ','') - -@register.tag(name='blockmedia') -def blockmedia(parser,token): - try: - tagname = token.split_contents() - except ValueError: - raise template.TemplateSyntaxError("blockmedia tag does not use arguments") - nodelist = [] - while True: - nodelist.append(parser.parse(('endblockmedia'))) - next = parser.next_token() - if next.contents == 'endblockmedia': - break - return BlockMediaUrlNode(nodelist) - -class FullUrlNode(template.Node): - def __init__(self, default_node): - self.default_node = default_node - - def render(self, context): - domain = askbot_settings.APP_URL - #protocol = getattr(settings, "PROTOCOL", "http") - path = self.default_node.render(context) - return "%s%s" % (domain, path) - -@register.tag(name='fullurl') -def fullurl(parser, token): - default_node = default_url(parser, token) - return FullUrlNode(default_node) - -@register.simple_tag -def fullmedia(url): - domain = askbot_settings.APP_URL - #protocol = getattr(settings, "PROTOCOL", "http") - path = media(url) - return "%s%s" % (domain, path) - -class IsManyNode(template.Node): - def __init__(self, test_items, true_nodelist, false_nodelist): - self.true_nodelist = true_nodelist - self.false_nodelist = false_nodelist - self.test_items = test_items - def render(self, context): - maybe = False - for item in self.test_items: - is_good = item.resolve(context) - if maybe == True and is_good: - return self.true_nodelist.render(context) - if is_good: - maybe = True - return self.false_nodelist.render(context) - -@register.tag(name='ifmany') -def ifmany(parser,token): - """usage {% ifmany item1 item2 item3 ... itemN %} stuff {% endifmany %} - returns content included into the tag if more than one - item evaluates to Tru'ish value - that's the idea - {% else %} is not supported yet - """ - - bits = list(token.split_contents()) - start_tag = bits.pop(0) - - test_items = [] - for bit in bits: - item = parser.compile_filter(bit) - test_items.append(item) - - end_tag = 'end' + start_tag - else_tag = 'else' - true_nodelist = parser.parse((end_tag,else_tag,)) - token = parser.next_token() - if token.contents == else_tag: - false_nodelist = parser.parse((end_tag,)) - token = parser.next_token() - else: - false_nodelist = template.NodeList() - - return IsManyNode(test_items, true_nodelist, false_nodelist) diff --git a/askbot/views/writers.py b/askbot/views/writers.py index e431d5fd..0e294b4a 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -27,7 +27,7 @@ from askbot import forms from askbot import models from askbot.skins.loaders import ENV from askbot.utils.decorators import ajax_only -from askbot.templatetags.extra_tags import diff_date +from askbot.utils.functions import diff_date from askbot.templatetags import extra_filters_jinja as template_filters # used in index page |