summaryrefslogtreecommitdiffstats
path: root/forum/management/commands/clean_award_badges.py
blob: 117e3a5f8eeda1613919284a05d00eae3421ce31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 = 0"
        cursor = connection.cursor()
        try:
            cursor.execute(query)
        finally:
            cursor.close()
            connection.close()

def main():
    pass

if __name__ == '__main__':
    main()