Revision 9ee31b09 db/credit_allocator.py
b/db/credit_allocator.py | ||
---|---|---|
7 | 7 |
# |
8 | 8 |
|
9 | 9 |
from db.models import * |
10 |
|
|
11 | 10 |
from django.db.models import F |
11 |
from datetime import datetime |
|
12 |
|
|
13 |
import logging |
|
14 |
|
|
12 | 15 |
|
13 | 16 |
# main entry point |
14 | 17 |
def allocate_credit(): |
15 | 18 |
"""Refund user with credits""" |
19 |
logging.basicConfig(level=logging.DEBUG) |
|
20 |
|
|
21 |
logging.info('Credit Allocation administration script is running') |
|
22 |
logging.info('Time: %s' % ( datetime.now().isoformat(), )) |
|
16 | 23 |
|
17 | 24 |
# Select the users that their monthly |
18 | 25 |
user_list = OceanUser.objects.filter(credit__lt=F('quota')) |
19 | 26 |
|
20 | 27 |
if len(user_list) == 0: |
21 |
print "No users found" |
|
22 |
return |
|
28 |
logging.warning('No users found') |
|
29 |
else: |
|
30 |
logging.info('Found %d user(s)' % ( len(user_list), )) |
|
23 | 31 |
|
24 | 32 |
for user in user_list: |
25 | 33 |
user.allocate_credits() |
26 |
print "Add %d credits to %s. Total: %d" % ( user.monthly_rate, user.name, user.credit )
|
|
34 |
logging.info("Adding %d credits to %s. Total: %d" % ( user.monthly_rate, user.name, user.credit ))
|
|
27 | 35 |
user.save() |
Also available in: Unified diff