Project

General

Profile

Download (959 Bytes) Statistics
| Branch: | Tag: | Revision:

calebasse / scripts / maj_valide.py @ 0d4bf0b4

1
import sys
2
import calebasse.settings
3
import django.core.management
4
from datetime import datetime
5

    
6
django.core.management.setup_environ(calebasse.settings)
7

    
8
from django.db import transaction
9
from calebasse.actes.models import Act
10

    
11
@transaction.commit_manually
12
def main():
13
    print datetime.now()
14
    total = Act.objects.all().count()
15
    i = 0
16
    for a in Act.objects.all():
17
        i += 1
18
        try:
19
            state = a.actvalidationstate_set.latest('created')
20
            if state.state_name == 'VALIDE':
21
                a.valide = True
22
                a.save()
23
        except:
24
            pass
25
        if not i % 100:
26
            percent  = int(round((float(i) / float(total)) * 100))
27
            out = '\r %20s [%s%s] %3d %%' % ("Actes traites : ", '=' * percent, ' ' * (100 - percent), percent)
28
            sys.stdout.write(out)
29
            sys.stdout.flush()
30
    transaction.commit()
31
    print datetime.now()
32

    
33
if __name__ == "__main__":
34
    main()
(41-41/47)