diff options
-rwxr-xr-x | forum/badges/__init__.py | 18 | ||||
-rwxr-xr-x | forum/badges/base.py | 20 | ||||
-rwxr-xr-x | forum/management/commands/pg_base_command.py | 70 | ||||
-rwxr-xr-x | forum/management/commands/pg_clean_award_badges.py | 116 | ||||
-rwxr-xr-x | forum/management/commands/pg_multi_award_badges.py | 696 | ||||
-rwxr-xr-x | forum/management/commands/pg_once_award_badges.py | 700 | ||||
-rwxr-xr-x | forum/management/commands/sximport.py | 218 | ||||
-rwxr-xr-x | forum/settings.py | 100 | ||||
-rwxr-xr-x | forum/utils/email.py | 42 | ||||
-rwxr-xr-x | forum/utils/time.py | 8 | ||||
-rwxr-xr-x | forum_modules/robotstxt/templates/robots.txt | 2 | ||||
-rwxr-xr-x | forum_modules/robotstxt/urls.py | 12 |
12 files changed, 1001 insertions, 1001 deletions
diff --git a/forum/badges/__init__.py b/forum/badges/__init__.py index 5ed245af..8d7cd097 100755 --- a/forum/badges/__init__.py +++ b/forum/badges/__init__.py @@ -1,10 +1,10 @@ -import re
-
-from forum.badges.base import BadgeImplementation
-from forum.modules import get_modules_script_classes
-
-ALL_BADGES = dict([
- (re.sub('BadgeImpl', '', name).lower(), cls) for name, cls
- in get_modules_script_classes('badges', BadgeImplementation).items()
- if not re.search('AbstractBadgeImpl$', name)
+import re + +from forum.badges.base import BadgeImplementation +from forum.modules import get_modules_script_classes + +ALL_BADGES = dict([ + (re.sub('BadgeImpl', '', name).lower(), cls) for name, cls + in get_modules_script_classes('badges', BadgeImplementation).items() + if not re.search('AbstractBadgeImpl$', name) ])
\ No newline at end of file diff --git a/forum/badges/base.py b/forum/badges/base.py index 154d4dfd..03ef3565 100755 --- a/forum/badges/base.py +++ b/forum/badges/base.py @@ -1,11 +1,11 @@ -
-
-class BadgeImplementation(object):
- name = ""
- description = ""
-
- def install(self):
- pass
-
- def process_job(self):
+ + +class BadgeImplementation(object): + name = "" + description = "" + + def install(self): + pass + + def process_job(self): raise NotImplementedError
\ No newline at end of file diff --git a/forum/management/commands/pg_base_command.py b/forum/management/commands/pg_base_command.py index a314c9eb..b3167dcf 100755 --- a/forum/management/commands/pg_base_command.py +++ b/forum/management/commands/pg_base_command.py @@ -1,35 +1,35 @@ -#!/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 forum.models import *
-from forum.const import *
-
-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 = TRUE WHERE id in (%s)"\
- % ','.join('%s' % item for item in activity_ids)
- cursor.execute(query)
-
-
-
-
-
+#!/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 forum.models import * +from forum.const import * + +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 = TRUE WHERE id in (%s)"\ + % ','.join('%s' % item for item in activity_ids) + cursor.execute(query) + + + + + diff --git a/forum/management/commands/pg_clean_award_badges.py b/forum/management/commands/pg_clean_award_badges.py index aa93e76b..b3925a68 100755 --- a/forum/management/commands/pg_clean_award_badges.py +++ b/forum/management/commands/pg_clean_award_badges.py @@ -1,59 +1,59 @@ -#-------------------------------------------------------------------------------
-# 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 forum.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__':
+#------------------------------------------------------------------------------- +# 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 forum.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/forum/management/commands/pg_multi_award_badges.py b/forum/management/commands/pg_multi_award_badges.py index 88bea762..75f84bfe 100755 --- a/forum/management/commands/pg_multi_award_badges.py +++ b/forum/management/commands/pg_multi_award_badges.py @@ -1,348 +1,348 @@ -#!/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 forum.models import *
-from forum.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()
+#!/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 forum.models import * +from forum.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/forum/management/commands/pg_once_award_badges.py b/forum/management/commands/pg_once_award_badges.py index 3dd6646c..b2f79363 100755 --- a/forum/management/commands/pg_once_award_badges.py +++ b/forum/management/commands/pg_once_award_badges.py @@ -1,350 +1,350 @@ -#!/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 forum.models import *
-from forum.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()
+#!/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 forum.models import * +from forum.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/forum/management/commands/sximport.py b/forum/management/commands/sximport.py index 5a0bb96a..f6af4e90 100755 --- a/forum/management/commands/sximport.py +++ b/forum/management/commands/sximport.py @@ -1,109 +1,109 @@ -from django.core.management.base import LabelCommand
-from zipfile import ZipFile
-from xml.dom import minidom as dom
-import datetime
-
-from forum.models import User
-
-class Command(LabelCommand):
- def handle_label(self, label, **options):
- zip = ZipFile(label)
-
- map = {}
-
- map['users'] = self.import_users(zip.open("Users.xml"))
- map['questions'], map['answers'] = self.import_posts(zip.open("Posts.xml"))
-
-
- def row_to_dic(self, row):
- return dict([
- (child.localName.lower(),
- " ".join([t.nodeValue for t in child.childNodes if t.nodeType == t.TEXT_NODE]))
- for child in row.childNodes
- if child.nodeType == child.ELEMENT_NODE
- ])
-
- def from_sx_time(self, timestring):
- if timestring is None:
- return timestring
-
- try:
- return datetime.datetime.strptime(timestring, '%Y-%m-%dT%H:%M:%S')
- except:
- return datetime.datetime.strptime(timestring, '%Y-%m-%dT%H:%M:%S.%f')
-
-
- def import_users(self, users):
- pkey_map = {}
- doc = dom.parse(users)
-
- rows = doc.getElementsByTagName('row')
- unknown_count = 0
-
- added_names = []
-
- for row in rows:
- values = self.row_to_dic(row)
-
- username = values.get('displayname',
- values.get('realname',
- values.get('email', None)))
-
- if username is None:
- unknown_count += 1
- username = 'Unknown User %d' % unknown_count
-
- if username in added_names:
- cnt = 1
- new_username = "%s %d" % (username, cnt)
- while new_username in added_names:
- cnt += 1
- new_username = "%s %d" % (username, cnt)
-
- username = new_username
-
- added_names.append(username)
-
- user = User(username=username, email=values.get('email', ''))
-
- user.reputation = values['reputation']
- user.last_seen = self.from_sx_time(values['lastaccessdate'])
-
- user.real_name = values.get('realname', '')
- user.about = values.get('aboutme', '')
- user.website = values.get('websiteurl', '')
- user.date_of_birth = self.from_sx_time(values.get('birthday', None))
- user.location = values.get('location', '')
-
- user.is_active = True
- user.email_isvalid = True
-
-
- if int(values['usertypeid']) == 5:
- user.is_superuser = True
-
- if int(values['usertypeid']) == 5:
- user.is_staff = True
-
- user.save()
-
- pkey_map[values['id']] = user
-
- return users
-
- def import_posts(self, posts, map):
- pkey_map = {}
- doc = dom.parse(posts)
-
- rows = doc.getElementsByTagName('row')
-
- for row in rows:
- map = {
- 'title': row['']
- }
-
- pass
- pass
-
-
-
+from django.core.management.base import LabelCommand +from zipfile import ZipFile +from xml.dom import minidom as dom +import datetime + +from forum.models import User + +class Command(LabelCommand): + def handle_label(self, label, **options): + zip = ZipFile(label) + + map = {} + + map['users'] = self.import_users(zip.open("Users.xml")) + map['questions'], map['answers'] = self.import_posts(zip.open("Posts.xml")) + + + def row_to_dic(self, row): + return dict([ + (child.localName.lower(), + " ".join([t.nodeValue for t in child.childNodes if t.nodeType == t.TEXT_NODE])) + for child in row.childNodes + if child.nodeType == child.ELEMENT_NODE + ]) + + def from_sx_time(self, timestring): + if timestring is None: + return timestring + + try: + return datetime.datetime.strptime(timestring, '%Y-%m-%dT%H:%M:%S') + except: + return datetime.datetime.strptime(timestring, '%Y-%m-%dT%H:%M:%S.%f') + + + def import_users(self, users): + pkey_map = {} + doc = dom.parse(users) + + rows = doc.getElementsByTagName('row') + unknown_count = 0 + + added_names = [] + + for row in rows: + values = self.row_to_dic(row) + + username = values.get('displayname', + values.get('realname', + values.get('email', None))) + + if username is None: + unknown_count += 1 + username = 'Unknown User %d' % unknown_count + + if username in added_names: + cnt = 1 + new_username = "%s %d" % (username, cnt) + while new_username in added_names: + cnt += 1 + new_username = "%s %d" % (username, cnt) + + username = new_username + + added_names.append(username) + + user = User(username=username, email=values.get('email', '')) + + user.reputation = values['reputation'] + user.last_seen = self.from_sx_time(values['lastaccessdate']) + + user.real_name = values.get('realname', '') + user.about = values.get('aboutme', '') + user.website = values.get('websiteurl', '') + user.date_of_birth = self.from_sx_time(values.get('birthday', None)) + user.location = values.get('location', '') + + user.is_active = True + user.email_isvalid = True + + + if int(values['usertypeid']) == 5: + user.is_superuser = True + + if int(values['usertypeid']) == 5: + user.is_staff = True + + user.save() + + pkey_map[values['id']] = user + + return users + + def import_posts(self, posts, map): + pkey_map = {} + doc = dom.parse(posts) + + rows = doc.getElementsByTagName('row') + + for row in rows: + map = { + 'title': row[''] + } + + pass + pass + + + diff --git a/forum/settings.py b/forum/settings.py index f3a665b2..04a7c399 100755 --- a/forum/settings.py +++ b/forum/settings.py @@ -1,51 +1,51 @@ -import os
-
-
-INSTALLED_APPS = ['forum']
-
-MIDDLEWARE_CLASSES = [
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.common.CommonMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'forum.middleware.anon_user.ConnectToSessionMessagesMiddleware',
- 'forum.middleware.pagesize.QuestionsPageSizeMiddleware',
- 'forum.middleware.cancel.CancelActionMiddleware',
- 'django.middleware.transaction.TransactionMiddleware',
-]
-
-TEMPLATE_LOADERS = [
- 'django.template.loaders.filesystem.load_template_source',
- 'django.template.loaders.app_directories.load_template_source',
- 'forum.modules.module_templates_loader',
- 'forum.skins.load_template_source',
-]
-
-TEMPLATE_CONTEXT_PROCESSORS = [
- 'django.core.context_processors.request',
- 'forum.context.application_settings',
- 'forum.user_messages.context_processors.user_messages',
- 'django.core.context_processors.auth',
-]
-
-TEMPLATE_DIRS = [
- os.path.join(os.path.dirname(__file__),'skins').replace('\\','/'),
-]
-
-def setup_settings(settings):
-
- if (hasattr(settings, 'DEBUG') and getattr(settings, 'DEBUG')):
- try:
- import debug_toolbar
- INSTALLED_APPS.append('debug_toolbar')
- MIDDLEWARE_CLASSES.append('debug_toolbar.middleware.DebugToolbarMiddleware')
- except:
- pass
-
-
- settings.INSTALLED_APPS = set(settings.INSTALLED_APPS) | set(INSTALLED_APPS)
- settings.MIDDLEWARE_CLASSES = set(settings.MIDDLEWARE_CLASSES) | set(MIDDLEWARE_CLASSES)
- settings.TEMPLATE_LOADERS = set(settings.TEMPLATE_LOADERS) | set(TEMPLATE_LOADERS)
- settings.TEMPLATE_CONTEXT_PROCESSORS = set(settings.TEMPLATE_CONTEXT_PROCESSORS) | set(TEMPLATE_CONTEXT_PROCESSORS)
- settings.TEMPLATE_DIRS = set(settings.TEMPLATE_DIRS) | set(TEMPLATE_DIRS)
-
+import os + + +INSTALLED_APPS = ['forum'] + +MIDDLEWARE_CLASSES = [ + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'forum.middleware.anon_user.ConnectToSessionMessagesMiddleware', + 'forum.middleware.pagesize.QuestionsPageSizeMiddleware', + 'forum.middleware.cancel.CancelActionMiddleware', + 'django.middleware.transaction.TransactionMiddleware', +] + +TEMPLATE_LOADERS = [ + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', + 'forum.modules.module_templates_loader', + 'forum.skins.load_template_source', +] + +TEMPLATE_CONTEXT_PROCESSORS = [ + 'django.core.context_processors.request', + 'forum.context.application_settings', + 'forum.user_messages.context_processors.user_messages', + 'django.core.context_processors.auth', +] + +TEMPLATE_DIRS = [ + os.path.join(os.path.dirname(__file__),'skins').replace('\\','/'), +] + +def setup_settings(settings): + + if (hasattr(settings, 'DEBUG') and getattr(settings, 'DEBUG')): + try: + import debug_toolbar + INSTALLED_APPS.append('debug_toolbar') + MIDDLEWARE_CLASSES.append('debug_toolbar.middleware.DebugToolbarMiddleware') + except: + pass + + + settings.INSTALLED_APPS = set(settings.INSTALLED_APPS) | set(INSTALLED_APPS) + settings.MIDDLEWARE_CLASSES = set(settings.MIDDLEWARE_CLASSES) | set(MIDDLEWARE_CLASSES) + settings.TEMPLATE_LOADERS = set(settings.TEMPLATE_LOADERS) | set(TEMPLATE_LOADERS) + settings.TEMPLATE_CONTEXT_PROCESSORS = set(settings.TEMPLATE_CONTEXT_PROCESSORS) | set(TEMPLATE_CONTEXT_PROCESSORS) + settings.TEMPLATE_DIRS = set(settings.TEMPLATE_DIRS) | set(TEMPLATE_DIRS) +
\ No newline at end of file diff --git a/forum/utils/email.py b/forum/utils/email.py index a6ea1087..dc712572 100755 --- a/forum/utils/email.py +++ b/forum/utils/email.py @@ -1,21 +1,21 @@ -from django.core.mail import send_mail, EmailMultiAlternatives
-from django.conf import settings
-from django.template import loader, Context
-from django.utils.html import strip_tags
-from threading import Thread
-
-def send_email(subject, recipients, template, context={}, sender=settings.DEFAULT_FROM_EMAIL, txt_template=None):
- context['settings'] = settings
- html_body = loader.get_template(template).render(Context(context))
-
- if txt_template is None:
- txt_body = strip_tags(html_body)
- else:
- txt_body = loader.get_template(txt_template).render(Context(context))
-
- msg = EmailMultiAlternatives(subject, txt_body, sender, recipients)
- msg.attach_alternative(html_body, "text/html")
-
- thread = Thread(target=EmailMultiAlternatives.send, args=[msg])
- thread.setDaemon(True)
- thread.start()
+from django.core.mail import send_mail, EmailMultiAlternatives +from django.conf import settings +from django.template import loader, Context +from django.utils.html import strip_tags +from threading import Thread + +def send_email(subject, recipients, template, context={}, sender=settings.DEFAULT_FROM_EMAIL, txt_template=None): + context['settings'] = settings + html_body = loader.get_template(template).render(Context(context)) + + if txt_template is None: + txt_body = strip_tags(html_body) + else: + txt_body = loader.get_template(txt_template).render(Context(context)) + + msg = EmailMultiAlternatives(subject, txt_body, sender, recipients) + msg.attach_alternative(html_body, "text/html") + + thread = Thread(target=EmailMultiAlternatives.send, args=[msg]) + thread.setDaemon(True) + thread.start() diff --git a/forum/utils/time.py b/forum/utils/time.py index 5fd15e24..39e01d0f 100755 --- a/forum/utils/time.py +++ b/forum/utils/time.py @@ -1,4 +1,4 @@ -import datetime
-
-def one_day_from_now():
- return datetime.datetime.now() + datetime.timedelta(days=1)
+import datetime + +def one_day_from_now(): + return datetime.datetime.now() + datetime.timedelta(days=1) diff --git a/forum_modules/robotstxt/templates/robots.txt b/forum_modules/robotstxt/templates/robots.txt index 97d769f1..574fc315 100755 --- a/forum_modules/robotstxt/templates/robots.txt +++ b/forum_modules/robotstxt/templates/robots.txt @@ -1,2 +1,2 @@ -User-agent: *
+User-agent: * Disallow: /
\ No newline at end of file diff --git a/forum_modules/robotstxt/urls.py b/forum_modules/robotstxt/urls.py index 83915456..79a6d84c 100755 --- a/forum_modules/robotstxt/urls.py +++ b/forum_modules/robotstxt/urls.py @@ -1,6 +1,6 @@ -from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
-
-urlpatterns = patterns('',
- (r'^robots.txt$', direct_to_template, {'template': 'modules/robotsdennyall/robots.txt'}),
-)
+from django.conf.urls.defaults import * +from django.views.generic.simple import direct_to_template + +urlpatterns = patterns('', + (r'^robots.txt$', direct_to_template, {'template': 'modules/robotsdennyall/robots.txt'}), +) |