diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-19 19:16:13 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-19 19:16:13 -0500 |
commit | e117a1949b957a53516b642a880894d2286a72dd (patch) | |
tree | 3aaffef6ab7d332e83b77f7a38c4697d199b8305 | |
parent | 14de03b345b493cc3e558178b6bc5a07a3b66bd7 (diff) | |
download | askbot-e117a1949b957a53516b642a880894d2286a72dd.tar.gz askbot-e117a1949b957a53516b642a880894d2286a72dd.tar.bz2 askbot-e117a1949b957a53516b642a880894d2286a72dd.zip |
made so that some badges award in postgres and mysql
-rw-r--r-- | askbot/__init__.py | 2 | ||||
-rw-r--r-- | askbot/management/commands/base_command.py | 2 | ||||
-rw-r--r-- | askbot/management/commands/multi_award_badges.py | 18 | ||||
-rw-r--r-- | askbot/management/commands/once_award_badges.py | 6 |
4 files changed, 16 insertions, 12 deletions
diff --git a/askbot/__init__.py b/askbot/__init__.py index fb6dfad9..fcedc653 100644 --- a/askbot/__init__.py +++ b/askbot/__init__.py @@ -22,7 +22,7 @@ def get_version(): """returns version of the askbot app this version is meaningful for pypi only """ - return '0.6.31' + return '0.6.33' #todo: maybe send_mail functions belong to models #or the future API diff --git a/askbot/management/commands/base_command.py b/askbot/management/commands/base_command.py index 46a2d7a7..820956d0 100644 --- a/askbot/management/commands/base_command.py +++ b/askbot/management/commands/base_command.py @@ -20,6 +20,6 @@ class BaseCommand(NoArgsCommand): def update_activities_auditted(self, cursor, activity_ids): # update processed rows to auditted if len(activity_ids): - query = "UPDATE activity SET is_auditted = 1 WHERE id in (%s)"\ + query = "UPDATE activity SET is_auditted = True WHERE id in (%s)"\ % ','.join('%s' % item for item in activity_ids) cursor.execute(query) diff --git a/askbot/management/commands/multi_award_badges.py b/askbot/management/commands/multi_award_badges.py index c3ed947d..9cb870c9 100644 --- a/askbot/management/commands/multi_award_badges.py +++ b/askbot/management/commands/multi_award_badges.py @@ -15,7 +15,7 @@ #!/usr/bin/env python import logging -from django.db import connection +from django.db import connection, transaction from django.shortcuts import get_object_or_404 from django.contrib.contenttypes.models import ContentType @@ -24,6 +24,7 @@ from askbot import const from askbot.management.commands.base_command import BaseCommand class Command(BaseCommand): + @transaction.commit_manually def handle_noargs(self, **options): badge_calls = ( self.delete_question_be_voted_up_3, @@ -50,6 +51,7 @@ class Command(BaseCommand): for badge_call in badge_calls: try: badge_call() + transaction.commit() except Exception, e: logging.critical('badge award error ' + unicode(e) + 'in ' + badge_call.__name__) finally: @@ -62,7 +64,7 @@ class Command(BaseCommand): 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 \ - act.is_auditted = 0" % (const.TYPE_ACTIVITY_DELETE_QUESTION) + act.is_auditted = False" % (const.TYPE_ACTIVITY_DELETE_QUESTION) self.__process_activities_badge(query, 1, Question) def delete_answer_be_voted_up_3(self): @@ -72,7 +74,7 @@ class Command(BaseCommand): 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 \ - act.is_auditted = 0" % (const.TYPE_ACTIVITY_DELETE_ANSWER) + act.is_auditted = False" % (const.TYPE_ACTIVITY_DELETE_ANSWER) self.__process_activities_badge(query, 1, Answer) def delete_question_be_vote_down_3(self): @@ -82,7 +84,7 @@ class Command(BaseCommand): 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 \ - act.is_auditted = 0" % (const.TYPE_ACTIVITY_DELETE_QUESTION) + act.is_auditted = False" % (const.TYPE_ACTIVITY_DELETE_QUESTION) content_type = ContentType.objects.get_for_model(Question) self.__process_activities_badge(query, 2, Question) @@ -93,7 +95,7 @@ class Command(BaseCommand): 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 \ - act.is_auditted = 0" % (const.TYPE_ACTIVITY_DELETE_ANSWER) + act.is_auditted = False" % (const.TYPE_ACTIVITY_DELETE_ANSWER) self.__process_activities_badge(query, 2, Answer) def answer_be_voted_up_10(self): @@ -104,7 +106,7 @@ class Command(BaseCommand): activity act, answer a WHERE act.object_id = a.id AND\ act.activity_type = %s AND \ a.vote_up_count >= 10 AND\ - act.is_auditted = 0" % (const.TYPE_ACTIVITY_ANSWER) + act.is_auditted = False" % (const.TYPE_ACTIVITY_ANSWER) self.__process_activities_badge(query, 3, Answer) def question_be_voted_up_10(self): @@ -115,7 +117,7 @@ class Command(BaseCommand): activity act, question q WHERE act.object_id = q.id AND\ act.activity_type = %s AND \ q.vote_up_count >= 10 AND\ - act.is_auditted = 0" % (const.TYPE_ACTIVITY_ASK_QUESTION) + act.is_auditted = False" % (const.TYPE_ACTIVITY_ASK_QUESTION) self.__process_activities_badge(query, 4, Question) def question_view_1000(self): @@ -222,7 +224,7 @@ class Command(BaseCommand): (34, '导师', 2, '导师', '被指定为最佳答案并且赞成票40以上', 1, 0), """ query = "SELECT a.id, a.author_id FROM answer a WHERE a.vote_up_count >= 40 AND\ - a.accepted = 1 AND\ + a.accepted = True AND\ a.id NOT IN \ (SELECT object_id FROM award WHERE award.badge_id = %s)" % (34) diff --git a/askbot/management/commands/once_award_badges.py b/askbot/management/commands/once_award_badges.py index ad4132af..42be67f5 100644 --- a/askbot/management/commands/once_award_badges.py +++ b/askbot/management/commands/once_award_badges.py @@ -14,7 +14,7 @@ import logging from datetime import datetime, date -from django.db import connection +from django.db import connection, transaction from django.shortcuts import get_object_or_404 from django.contrib.contenttypes.models import ContentType @@ -93,6 +93,7 @@ BADGE_AWARD_TYPE_FIRST = { } class Command(BaseCommand): + @transaction.commit_manually def handle_noargs(self, **options): badge_calls = ( self.alpha_user, @@ -109,6 +110,7 @@ class Command(BaseCommand): for badge_call in badge_calls: try: badge_call() + transaction.commit() except Exception, e: logging.critical('badge award error ' + unicode(e) + 'in ' + badge_call.__name__) finally: @@ -152,7 +154,7 @@ class Command(BaseCommand): 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 is_auditted = 0 AND activity_type IN (%s) ORDER BY user_id, activity_type" % activity_types + query = "SELECT id, user_id, activity_type, content_type_id, object_id FROM activity WHERE is_auditted = False AND activity_type IN (%s) ORDER BY user_id, activity_type" % activity_types cursor = connection.cursor() try: cursor.execute(query) |