]> git.openstreetmap.org Git - osqa.git/blob - forum/management/commands/clean_award_badges.py
deleting the test file
[osqa.git] / forum / management / commands / clean_award_badges.py
1 #-------------------------------------------------------------------------------
2 # Name:        Award badges command
3 # Purpose:     This is a command file croning in background process regularly to
4 #              query database and award badges for user's special acitivities.
5 #
6 # Author:      Mike
7 #
8 # Created:     18/01/2009
9 # Copyright:   (c) Mike 2009
10 # Licence:     GPL V2
11 #-------------------------------------------------------------------------------
12 #!/usr/bin/env python
13 #encoding:utf-8
14 from django.core.management.base import NoArgsCommand
15 from django.db import connection
16 from django.shortcuts import get_object_or_404
17 from django.contrib.contenttypes.models import ContentType
18
19 from forum.models import *
20
21 class Command(NoArgsCommand):
22     def handle_noargs(self, **options):
23         try:
24             try:
25                 self.clean_awards()
26             except Exception, e:
27                 print e
28         finally:
29             connection.close()
30
31     def clean_awards(self):
32         Award.objects.all().delete()
33
34         award_type =ContentType.objects.get_for_model(Award)
35         Activity.objects.filter(content_type=award_type).delete()
36
37         for user in User.objects.all():
38             user.gold = 0
39             user.silver = 0
40             user.bronze = 0
41             user.save()
42
43         for badge in Badge.objects.all():
44             badge.awarded_count = 0
45             badge.save()
46             
47         query = "UPDATE activity SET is_auditted = 0"
48         cursor = connection.cursor()
49         try:
50             cursor.execute(query)
51         finally:
52             cursor.close()
53             connection.close()
54
55 def main():
56     pass
57
58 if __name__ == '__main__':
59     main()