Statistics
| Branch: | Tag: | Revision:

root / db / credit_allocator.py @ d08a5f6f

History | View | Annotate | Download (991 Bytes)

1
#
2
# Credit Allocator - Administration script
3
#
4
# Execute once to increase user credits according to their monthly rate
5
#
6
# Copyright 2010 Greek Research and Technology Network
7
#
8

    
9
from db.models import *
10
from django.db.models import F
11
from datetime import datetime
12

    
13
import logging
14

    
15

    
16
# main entry point
17
def allocate_credit():
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(), ))
23
    
24
    # Select the users that their monthly
25
    user_list = SynnefoUser.objects.filter(credit__lt=F('quota'))
26
    
27
    if len(user_list) == 0:
28
        logging.warning('No users found')
29
    else:
30
        logging.info('Found %d user(s)' % ( len(user_list), ))
31

    
32
    for user in user_list:
33
        user.allocate_credits()
34
        logging.info("Adding %d credits to %s. Total: %d" % ( user.monthly_rate, user.name, user.credit ))
35
        user.save()