Statistics
| Branch: | Tag: | Revision:

root / db / credit_allocator.py @ 52194743

History | View | Annotate | Download (967 Bytes)

1 ce4015d4 Vassilios Karakoidas
#
2 5b32775a Vassilios Karakoidas
# Credit Allocator - Administration script
3 ce4015d4 Vassilios Karakoidas
#
4 5b32775a Vassilios Karakoidas
# Execute once to increase user credits according to their monthly rate
5 5b32775a Vassilios Karakoidas
#
6 4940f0f6 Vassilios Karakoidas
# Copyright 2010 Greek Research and Technology Network
7 ce4015d4 Vassilios Karakoidas
#
8 ce4015d4 Vassilios Karakoidas
9 45088a2d Vassilios Karakoidas
from db.models import *
10 fa672379 Vassilios Karakoidas
from django.db.models import F
11 9ee31b09 Vassilios Karakoidas
from datetime import datetime
12 9ee31b09 Vassilios Karakoidas
13 9ee31b09 Vassilios Karakoidas
import logging
14 9ee31b09 Vassilios Karakoidas
15 fa672379 Vassilios Karakoidas
16 ce4015d4 Vassilios Karakoidas
# main entry point
17 4940f0f6 Vassilios Karakoidas
def allocate_credit():
18 b90da243 Vassilios Karakoidas
    """Refund user with credits"""
19 9ee31b09 Vassilios Karakoidas
    logging.basicConfig(level=logging.DEBUG)
20 9ee31b09 Vassilios Karakoidas
    
21 9ee31b09 Vassilios Karakoidas
    logging.info('Credit Allocation administration script is running')
22 9ee31b09 Vassilios Karakoidas
    logging.info('Time: %s' % ( datetime.now().isoformat(), ))
23 fa672379 Vassilios Karakoidas
    
24 fa672379 Vassilios Karakoidas
    # Select the users that their monthly
25 90b28517 Vassilios Karakoidas
    user_list = SynnefoUser.objects.all()
26 4940f0f6 Vassilios Karakoidas
    
27 4940f0f6 Vassilios Karakoidas
    if len(user_list) == 0:
28 9ee31b09 Vassilios Karakoidas
        logging.warning('No users found')
29 9ee31b09 Vassilios Karakoidas
    else:
30 9ee31b09 Vassilios Karakoidas
        logging.info('Found %d user(s)' % ( len(user_list), ))
31 ce4015d4 Vassilios Karakoidas
32 fa672379 Vassilios Karakoidas
    for user in user_list:
33 b90da243 Vassilios Karakoidas
        user.allocate_credits()
34 9ee31b09 Vassilios Karakoidas
        logging.info("Adding %d credits to %s. Total: %d" % ( user.monthly_rate, user.name, user.credit ))
35 fa672379 Vassilios Karakoidas
        user.save()