summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Chen <chagel@gmail.com>2009-08-02 16:39:47 +0800
committerMike Chen <chagel@gmail.com>2009-08-02 16:39:47 +0800
commitf202c999814eb0c817477529f092a22654e91792 (patch)
tree16c7079bb976470e4c4961736175e80da39eba34
parent47bbdb87d331bd770278784699d942f59d058362 (diff)
downloadaskbot-f202c999814eb0c817477529f092a22654e91792.tar.gz
askbot-f202c999814eb0c817477529f092a22654e91792.tar.bz2
askbot-f202c999814eb0c817477529f092a22654e91792.zip
fix command error for awarding badges
-rw-r--r--forum/management/commands/once_award_badges.py50
1 files changed, 24 insertions, 26 deletions
diff --git a/forum/management/commands/once_award_badges.py b/forum/management/commands/once_award_badges.py
index c26251d7..7074e3db 100644
--- a/forum/management/commands/once_award_badges.py
+++ b/forum/management/commands/once_award_badges.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python
#encoding:utf-8
#-------------------------------------------------------------------------------
# Name: Award badges command
@@ -12,7 +12,6 @@
# 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
@@ -157,8 +156,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 = 0 AND activity_type IN (%s) ORDER BY user_id, activity_type" % activity_types
cursor = connection.cursor()
try:
@@ -206,9 +204,9 @@ class Command(BaseCommand):
(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 "+
+ 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:
@@ -236,9 +234,9 @@ class Command(BaseCommand):
(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 "+
+ 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:
@@ -264,10 +262,10 @@ class Command(BaseCommand):
"""
(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 "+
+ 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:
@@ -292,10 +290,10 @@ class Command(BaseCommand):
"""
(26, '优秀市民', 2, '优秀市民', '投票300次以上', 0, 0)
"""
- query = "SELECT count(*) 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) "+
+ query = "SELECT count(*) 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 vote_count >= 300" % (TYPE_ACTIVITY_VOTE_UP, TYPE_ACTIVITY_VOTE_DOWN, 26)
self.__award_for_count_num(query, 26)
@@ -304,10 +302,10 @@ class Command(BaseCommand):
"""
(27, '编辑主任', 2, '编辑主任', '编辑了100个帖子', 0, 0)
"""
- query = "SELECT count(*) 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) "+
+ query = "SELECT count(*) 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 vote_count >= 100" % (TYPE_ACTIVITY_UPDATE_QUESTION, TYPE_ACTIVITY_UPDATE_ANSWER, 27)
self.__award_for_count_num(query, 27)
@@ -316,10 +314,10 @@ class Command(BaseCommand):
"""
(5, '评论家', 3, '评论家', '评论10次以上', 0, 0),
"""
- query = "SELECT count(*) 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) "+
+ query = "SELECT count(*) 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 vote_count >= 10" % (TYPE_ACTIVITY_COMMENT_QUESTION, TYPE_ACTIVITY_COMMENT_ANSWER, 5)
self.__award_for_count_num(query, 5)